Skip to content

Commit

Permalink
Staging Release
Browse files Browse the repository at this point in the history
Staging Release
  • Loading branch information
tcheee authored Nov 12, 2024
2 parents bed5d7c + cf24adf commit 01aab72
Show file tree
Hide file tree
Showing 6 changed files with 888 additions and 106 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"@emotion/styled": "^11.13.0",
"@fingerprintjs/fingerprintjs": "^3.4.2",
"@headlessui/react": "^2.2.0",
"@lifi/explorer": "^0.0.2",
"@lifi/explorer": "^0.0.3",
"@lifi/sdk": "^3.4.1",
"@lifi/wallet-management": "^3.4.3",
"@lifi/widget": "^3.12.0",
"@lifi/wallet-management": "^3.4.4",
"@lifi/widget": "^3.12.1",
"@metaplex-foundation/mpl-core": "^1.1.1",
"@metaplex-foundation/umi": "^0.9.2",
"@metaplex-foundation/umi-bundle-defaults": "^0.9.2",
Expand Down Expand Up @@ -42,7 +42,7 @@
"fontaine": "^0.5.0",
"graphql": "^16.9.0",
"graphql-request": "^7.1.2",
"i18next": "^23.16.4",
"i18next": "^23.16.5",
"i18next-resources-for-ts": "^1.5.0",
"i18next-resources-to-backend": "^1.2.1",
"next": "^14.2.17",
Expand Down
2 changes: 0 additions & 2 deletions src/app/api/update-data/route.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { base58 } from '@metaplex-foundation/umi/serializers';
import 'server-only';

type TRequest = {
Expand All @@ -15,7 +14,6 @@ export async function POST(request: Request): Promise<Response> {
headers: {
'Content-Type': 'application/json',
'x-api-key': process.env.WASH_HANDSHAKE as string,
Authorization: `Bearer ${base58.serialize(res.publicKey ?? '')}`,
},
},
);
Expand Down
4 changes: 1 addition & 3 deletions src/wash/hooks/useGetCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useUmi } from '../contexts/useUmi';
import { colorDict, WASH_ENDPOINT_ROOT_URI } from '../utils/constants';
import { ChainType } from '@lifi/sdk';
import { useAccount } from '@lifi/wallet-management';
import { base58 } from '@metaplex-foundation/umi/serializers';
import { useQuery } from '@tanstack/react-query';

import type { TColor } from '../utils/theme';
Expand Down Expand Up @@ -36,13 +35,12 @@ export function useGetCollection(): TGetCollection {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${base58.serialize(account.address ?? '')}`, //TODO: CHECK IF NO base58 REQUIRED
},
},
);
const result = await response.json();
return result.data;
}, [account.address, umi?.identity.publicKey]);
}, [umi?.identity.publicKey]);

const {
isPending,
Expand Down
40 changes: 24 additions & 16 deletions src/wash/hooks/useGetNFT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useUmi } from '../contexts/useUmi';
import { colorDict, WASH_ENDPOINT_ROOT_URI } from '../utils/constants';
import { ChainType } from '@lifi/sdk';
import { useAccount } from '@lifi/wallet-management';
import { base58 } from '@metaplex-foundation/umi/serializers';
import { useQuery } from '@tanstack/react-query';

import type { TColor } from '../utils/theme';
Expand All @@ -30,6 +29,9 @@ export type TGetNFT = {
};

export function useGetNFT(refetchUser?: VoidFunction): TGetNFT {
const [isRefreshingDataFor, set_isRefreshingDataFor] = useState<
string | undefined
>(undefined);
const [dataRefreshedFor, set_dataRefreshedFor] = useState<string | undefined>(
undefined,
);
Expand Down Expand Up @@ -65,7 +67,6 @@ export function useGetNFT(refetchUser?: VoidFunction): TGetNFT {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${base58.serialize(account.address ?? '')}`,
},
},
);
Expand Down Expand Up @@ -93,19 +94,24 @@ export function useGetNFT(refetchUser?: VoidFunction): TGetNFT {
* @returns The updated NFT data from the server.
*********************************************************************************************/
const fetchUpdatedNFT = useCallback(async (): Promise<void> => {
await fetch(`/api/update-data`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${base58.serialize(account.address ?? '')}`,
},
body: JSON.stringify({
publicKey: umi?.identity.publicKey,
}),
});
set_dataRefreshedFor(umi?.identity.publicKey);
await Promise.all([cachedQuery.refetch(), refetchUser?.()]);
}, [umi?.identity.publicKey, account.address, cachedQuery, refetchUser]);
try {
set_isRefreshingDataFor(umi?.identity.publicKey);
await fetch(`/api/update-data`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
publicKey: umi?.identity.publicKey,
}),
});
set_dataRefreshedFor(umi?.identity.publicKey);
set_isRefreshingDataFor(undefined);
await Promise.all([cachedQuery.refetch(), refetchUser?.()]);
} catch (error) {
console.warn('error', error);
}
}, [umi?.identity.publicKey, cachedQuery, refetchUser]);

/**************************************************************************************************
* useEffect Hook for Fetching Updated NFT Data
Expand All @@ -126,7 +132,8 @@ export function useGetNFT(refetchUser?: VoidFunction): TGetNFT {
account.isConnected &&
account.address &&
umi?.identity.publicKey &&
dataRefreshedFor !== umi?.identity.publicKey
dataRefreshedFor !== umi?.identity.publicKey &&
(!isRefreshingDataFor || isRefreshingDataFor !== umi?.identity.publicKey)
) {
fetchUpdatedNFT();
}
Expand All @@ -137,6 +144,7 @@ export function useGetNFT(refetchUser?: VoidFunction): TGetNFT {
account.address,
umi?.identity.publicKey,
dataRefreshedFor,
isRefreshingDataFor,
]);

/**************************************************************************************************
Expand Down
3 changes: 1 addition & 2 deletions src/wash/hooks/useGetUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ export function useGetUser(): TGetUser {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${account.address ?? ''}`,
},
},
);
const result = await response.json();
return { items: result.items, quests: result.userQuests };
}, [umi?.identity.publicKey, account.address]);
}, [umi?.identity.publicKey]);

const { isLoading, error, data, refetch } = useQuery({
queryKey: ['user'],
Expand Down
Loading

0 comments on commit 01aab72

Please sign in to comment.