Skip to content

Commit 721400c

Browse files
committed
Merge branch 'master' into sns-321-missing-subdomains-sns-manager
2 parents c2e0de9 + d9cbc82 commit 721400c

25 files changed

+390
-290
lines changed

package-lock.json

+25-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"@solana/wallet-adapter-react": "0.15.35",
5454
"@solana/wallet-adapter-react-ui": "0.9.34",
5555
"@solana/web3.js": "1.87.6",
56+
"@tanstack/react-query": "^5.18.1",
5657
"axios": "1.6.7",
5758
"buffer": "6.0.3",
5859
"expo": "49.0.18",
@@ -65,7 +66,6 @@
6566
"expo-status-bar": "~1.6.0",
6667
"lodash": "4.17.21",
6768
"react": "18.2.0",
68-
"react-async-hook": "4.0.0",
6969
"react-dom": "18.2.0",
7070
"react-error-overlay": "6.0.11",
7171
"react-native": "0.72.6",

src/App.tsx

+17-13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import { CreateSubdomainModal } from "./components/CreateSubdomainModal";
3737
import { SuccessSubdomainModal } from "./components/SuccessSubdomainModal";
3838
import { t } from "@lingui/macro";
3939
import { i18n } from "@lingui/core";
40+
import { QueryClientProvider } from "@tanstack/react-query";
41+
import { queryClient } from "./lib";
4042
import {
4143
LanguageProvider,
4244
useLanguageContext,
@@ -201,19 +203,21 @@ function App() {
201203
https://github.com/gorhom/react-native-bottom-sheet/issues/1389
202204
*/}
203205
<GestureHandlerRootView style={{ flex: 1 }}>
204-
<SolanaProvider>
205-
<RecoilRoot>
206-
<NavigationContainer>
207-
<LanguageProvider i18n={i18n}>
208-
<StatusModalProvider>
209-
<ModalProvider stack={stackModal}>
210-
<TabNavigator />
211-
</ModalProvider>
212-
</StatusModalProvider>
213-
</LanguageProvider>
214-
</NavigationContainer>
215-
</RecoilRoot>
216-
</SolanaProvider>
206+
<QueryClientProvider client={queryClient}>
207+
<SolanaProvider>
208+
<RecoilRoot>
209+
<NavigationContainer>
210+
<LanguageProvider i18n={i18n}>
211+
<StatusModalProvider>
212+
<ModalProvider stack={stackModal}>
213+
<TabNavigator />
214+
</ModalProvider>
215+
</StatusModalProvider>
216+
</LanguageProvider>
217+
</NavigationContainer>
218+
</RecoilRoot>
219+
</SolanaProvider>
220+
</QueryClientProvider>
217221
</GestureHandlerRootView>
218222
</ErrorBoundary>
219223
);

src/components/ProfileBlock.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import tw from "@src/utils/tailwind";
1010
import { abbreviate } from "@src/utils/abbreviate";
1111
import { useWallet } from "@src/hooks/useWallet";
1212
import { useFavoriteDomain } from "@src/hooks/useFavoriteDomain";
13-
import { useProfilePic } from "@bonfida/sns-react";
1413

1514
interface ProfileBlockProps {
1615
children?: ReactNode;
@@ -66,7 +65,7 @@ export const ProfileBlock = ({
6665
openModal("EditPicture", {
6766
currentPic: picRecord,
6867
domain: domain,
69-
setAsFav: !favorite.result?.reverse,
68+
setAsFav: !favorite.data?.reverse,
7069
refresh: onNewPicUploaded,
7170
})
7271
}

src/hooks/useDomainInfo.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { isTokenized } from "@bonfida/name-tokenizer";
2-
import { useSolanaConnection } from "../hooks/xnft-hooks";
2+
import { useQuery } from "@tanstack/react-query";
33
import { NameRegistryState, getDomainKeySync } from "@bonfida/spl-name-service";
4-
import { useAsync } from "react-async-hook";
4+
import { QueryKeys } from "@src/lib";
5+
import { useSolanaConnection } from "../hooks/xnft-hooks";
56

67
export const useDomainInfo = (domain: string) => {
78
const connection = useSolanaConnection();
8-
const fn = async () => {
9+
10+
const queryFn = async () => {
911
if (!connection) return;
1012
const { pubkey } = getDomainKeySync(domain);
1113
const { registry, nftOwner } = await NameRegistryState.retrieve(
@@ -20,5 +22,10 @@ export const useDomainInfo = (domain: string) => {
2022
isTokenized: _isTokenized,
2123
};
2224
};
23-
return useAsync(fn, [!!connection, domain]);
25+
26+
return useQuery({
27+
queryKey: [QueryKeys.domainInfo, domain],
28+
queryFn,
29+
staleTime: 1000 * 30,
30+
});
2431
};

src/hooks/useDomains.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { useAsync } from "react-async-hook";
1+
import { useQuery } from "@tanstack/react-query";
22
import axios from "axios";
3+
import { QueryKeys } from "@src/lib";
34

45
export interface Result {
56
key: string;
@@ -12,15 +13,20 @@ export interface Response {
1213
}
1314

1415
const get = async (key: string | undefined | null) => {
15-
if (!key) return;
16+
if (!key) return [];
1617
const { data }: { data: Response } = await axios.get(
1718
`https://sns-sdk-proxy.bonfida.workers.dev/domains/${key}`,
1819
);
19-
if (data.s !== "ok") return;
20+
if (data.s !== "ok") return [];
2021
data.result.sort((a, b) => a.domain.localeCompare(b.domain));
2122
return data.result;
2223
};
2324

2425
export const useDomains = (owner: string | null | undefined) => {
25-
return useAsync(get, [owner]);
26+
return useQuery({
27+
queryKey: [QueryKeys.domainsList, owner],
28+
queryFn: () => get(owner),
29+
enabled: !!owner,
30+
staleTime: 1000 * 30,
31+
});
2632
};

src/hooks/useFavoriteDomain.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import { getFavoriteDomain } from "@bonfida/spl-name-service";
22
import { PublicKey } from "@solana/web3.js";
33
import { useSolanaConnection } from "./xnft-hooks";
4-
import { useAsync } from "react-async-hook";
54
import { useWallet } from "./useWallet";
5+
import { QueryKeys } from "@src/lib";
6+
import { useQuery } from "@tanstack/react-query";
67

78
export const useFavoriteDomain = (owner: string | undefined) => {
89
const connection = useSolanaConnection();
910
const { publicKey } = useWallet();
1011
owner = owner || publicKey?.toBase58();
1112

12-
const fn = async () => {
13+
const queryFn = async () => {
1314
if (!connection || !owner) return;
1415
const fav = await getFavoriteDomain(connection, new PublicKey(owner));
1516
return fav;
1617
};
1718

18-
return useAsync(fn, [owner, !!connection]);
19+
return useQuery({
20+
queryKey: [QueryKeys.favoriteDomain, owner],
21+
queryFn,
22+
staleTime: 1000 * 30,
23+
});
1924
};

src/hooks/usePyth.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PublicKey } from "@solana/web3.js";
33
import { Connection } from "@solana/web3.js";
44
import { tokenList } from "../utils/tokens/popular-tokens";
55
import { useSolanaConnection } from "./xnft-hooks";
6-
import { useAsync } from "react-async-hook";
6+
import { useQuery } from "@tanstack/react-query";
77

88
export interface Pyth {
99
price: number;
@@ -39,7 +39,8 @@ const getPrice = async (connection: Connection, feed: PublicKey) => {
3939

4040
export const usePyth = () => {
4141
const connection = useSolanaConnection();
42-
const fn = async () => {
42+
43+
const queryFn = async () => {
4344
if (!connection) return;
4445
const results = new Map<string, Pyth>();
4546
for (let x of FEEDS.keys()) {
@@ -52,5 +53,10 @@ export const usePyth = () => {
5253

5354
return results;
5455
};
55-
return useAsync(fn, [!!connection]);
56+
57+
return useQuery({
58+
queryKey: [],
59+
queryFn,
60+
staleTime: 1000 * 5,
61+
});
5662
};

src/hooks/useRecords.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
ETH_ROA_RECORDS,
44
GUARDIANS,
55
Record,
6-
RecordResult,
76
SELF_SIGNED,
87
} from "@bonfida/spl-name-service";
98
import { useRecordsV2 } from "@bonfida/sns-react";
@@ -76,7 +75,7 @@ export const useRecords = (domain: string | undefined, records: Record[]) => {
7675

7776
const execute: ExecuteFunction<void> = useCallback(async () => {
7877
try {
79-
await domainInfo.execute();
78+
await domainInfo.refetch();
8079
await res.execute();
8180
} catch (error) {
8281
console.error(error);
@@ -90,11 +89,11 @@ export const useRecords = (domain: string | undefined, records: Record[]) => {
9089
});
9190

9291
useEffect(() => {
93-
if (!res || !res.result || !domainInfo || !domainInfo.result) {
92+
if (!res || !res.result || !domainInfo || !domainInfo.data) {
9493
return setData({
9594
execute,
9695
result: [],
97-
loading: res.loading || domainInfo.loading,
96+
loading: res.loading || domainInfo.isLoading,
9897
});
9998
}
10099

@@ -108,7 +107,7 @@ export const useRecords = (domain: string | undefined, records: Record[]) => {
108107
const header = r?.retrievedRecord.header;
109108
const stalenessId = r?.retrievedRecord.getStalenessId();
110109
const roaId = r?.retrievedRecord.getRoAId();
111-
const owner = new PublicKey(domainInfo.result.owner);
110+
const owner = new PublicKey(domainInfo.data.owner);
112111

113112
// Check staleness
114113
if (
@@ -144,16 +143,16 @@ export const useRecords = (domain: string | undefined, records: Record[]) => {
144143
setData({
145144
result: _data,
146145
execute,
147-
loading: domainInfo.loading || res.loading,
146+
loading: domainInfo.isLoading || res.loading,
148147
});
149148
}, [
150149
res.loading,
151150
JSON.stringify(res.result?.map((e) => e?.deserializedContent)),
152-
domainInfo.result?.owner,
153-
domainInfo.result?.isTokenized,
151+
domainInfo.data?.owner,
152+
domainInfo.data?.isTokenized,
154153
domain,
155154
...records,
156-
domainInfo.loading,
155+
domainInfo.isLoading,
157156
]);
158157

159158
return data;

src/hooks/useRent.tsx

-14
This file was deleted.

src/hooks/useSubdomains.tsx

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useAsync } from "react-async-hook";
21
import {
32
NAME_PROGRAM_ID,
43
findSubdomains,
@@ -11,6 +10,8 @@ import {
1110
} from "@bonfida/spl-name-service";
1211
import { useSolanaConnection } from "./xnft-hooks";
1312
import { AccountInfo, PublicKey } from "@solana/web3.js";
13+
import { useQuery } from "@tanstack/react-query";
14+
import { QueryKeys } from "@src/lib";
1415

1516
export interface SubdomainResult {
1617
key: string;
@@ -20,7 +21,7 @@ export interface SubdomainResult {
2021
export const useSubdomains = (domain: string) => {
2122
const connection = useSolanaConnection();
2223

23-
const fn = async () => {
24+
const queryFn = async () => {
2425
if (!connection) return;
2526
const { pubkey: key } = getDomainKeySync(domain);
2627

@@ -30,7 +31,11 @@ export const useSubdomains = (domain: string) => {
3031
return subdomains;
3132
};
3233

33-
return useAsync(fn, [!!connection, domain]);
34+
return useQuery({
35+
queryKey: [QueryKeys.subdomainsFromUser, domain],
36+
queryFn,
37+
staleTime: 1000 * 30,
38+
});
3439
};
3540

3641
const deserializeReverseSub = (
@@ -44,7 +49,7 @@ const deserializeReverseSub = (
4449
export const useSubdomainsFromUser = (owner: string) => {
4550
const connection = useSolanaConnection();
4651

47-
const fn = async () => {
52+
const queryFn = async () => {
4853
if (!connection) return;
4954
const accounts = await connection.getProgramAccounts(NAME_PROGRAM_ID, {
5055
filters: [{ memcmp: { offset: 32, bytes: owner } }],
@@ -111,5 +116,9 @@ export const useSubdomainsFromUser = (owner: string) => {
111116
return result;
112117
};
113118

114-
return useAsync(fn, [!!connection, owner]);
119+
return useQuery({
120+
queryKey: [QueryKeys.subdomainsFromUser, owner],
121+
queryFn,
122+
staleTime: 1000 * 30,
123+
});
115124
};

0 commit comments

Comments
 (0)