From 3345117900ba292682cc3c9239e8bdc816bdf908 Mon Sep 17 00:00:00 2001 From: "Ioannis T." Date: Thu, 5 Dec 2024 17:52:07 +0100 Subject: [PATCH] refactor: integrate new last processed ipfs hash field when awaiting on account metadata update --- .../create-stream-flow/input-details.svelte | 2 +- .../flows/delete-stream-flow/confirm.svelte | 2 +- .../shared/steps/edit-drip-list.svelte | 2 +- .../steps/set-new-metadata.svelte | 2 +- .../edit-project-splits/steps/review.svelte | 2 +- .../edit-stream-flow/enter-new-details.svelte | 2 +- src/lib/utils/ipfs.ts | 85 +++++++++++++++---- 7 files changed, 75 insertions(+), 22 deletions(-) diff --git a/src/lib/flows/create-stream-flow/input-details.svelte b/src/lib/flows/create-stream-flow/input-details.svelte index 88d557d6e..6d0c036b6 100644 --- a/src/lib/flows/create-stream-flow/input-details.svelte +++ b/src/lib/flows/create-stream-flow/input-details.svelte @@ -239,7 +239,7 @@ const { dripsAccountId } = $wallet; assert(dripsAccountId); - await waitForAccountMetadata(dripsAccountId, newHash); + await waitForAccountMetadata(dripsAccountId, newHash, 'address'); await invalidateAll(); }, diff --git a/src/lib/flows/delete-stream-flow/confirm.svelte b/src/lib/flows/delete-stream-flow/confirm.svelte index de4d3d826..31c82137b 100644 --- a/src/lib/flows/delete-stream-flow/confirm.svelte +++ b/src/lib/flows/delete-stream-flow/confirm.svelte @@ -63,7 +63,7 @@ const { dripsAccountId } = $walletStore; assert(dripsAccountId); - await waitForAccountMetadata(dripsAccountId, newHash); + await waitForAccountMetadata(dripsAccountId, newHash, 'address'); await goto('/funds'); }, diff --git a/src/lib/flows/edit-drip-list/shared/steps/edit-drip-list.svelte b/src/lib/flows/edit-drip-list/shared/steps/edit-drip-list.svelte index 4cdbb6511..157fa31a4 100644 --- a/src/lib/flows/edit-drip-list/shared/steps/edit-drip-list.svelte +++ b/src/lib/flows/edit-drip-list/shared/steps/edit-drip-list.svelte @@ -168,7 +168,7 @@ ], after: async (_, { accountId, ipfsHash }) => { - await waitForAccountMetadata(accountId, ipfsHash); + await waitForAccountMetadata(accountId, ipfsHash, 'dripList'); await invalidateAccountCache(accountId); await invalidateAll(); }, diff --git a/src/lib/flows/edit-project-metadata/steps/set-new-metadata.svelte b/src/lib/flows/edit-project-metadata/steps/set-new-metadata.svelte index a6b92c070..b75cb4c80 100644 --- a/src/lib/flows/edit-project-metadata/steps/set-new-metadata.svelte +++ b/src/lib/flows/edit-project-metadata/steps/set-new-metadata.svelte @@ -114,7 +114,7 @@ ], after: async (_, { accountId, ipfsHash }) => { - await waitForAccountMetadata(accountId, ipfsHash); + await waitForAccountMetadata(accountId, ipfsHash, 'project'); await invalidateAccountCache(accountId); await invalidateAll(); }, diff --git a/src/lib/flows/edit-project-splits/steps/review.svelte b/src/lib/flows/edit-project-splits/steps/review.svelte index 6a86a19f5..1f1b64bc7 100644 --- a/src/lib/flows/edit-project-splits/steps/review.svelte +++ b/src/lib/flows/edit-project-splits/steps/review.svelte @@ -70,7 +70,7 @@ ], after: async (_, { newMetadataHash }) => { - await waitForAccountMetadata($context.projectAccountId, newMetadataHash); + await waitForAccountMetadata($context.projectAccountId, newMetadataHash, 'project'); await invalidateAccountCache($context.projectAccountId); await invalidateAll(); }, diff --git a/src/lib/flows/edit-stream-flow/enter-new-details.svelte b/src/lib/flows/edit-stream-flow/enter-new-details.svelte index d8295859d..4b4d746e1 100644 --- a/src/lib/flows/edit-stream-flow/enter-new-details.svelte +++ b/src/lib/flows/edit-stream-flow/enter-new-details.svelte @@ -129,7 +129,7 @@ const { dripsAccountId } = $walletStore; assert(dripsAccountId); - await waitForAccountMetadata(dripsAccountId, newHash); + await waitForAccountMetadata(dripsAccountId, newHash, 'address'); await invalidateAll(); }, diff --git a/src/lib/utils/ipfs.ts b/src/lib/utils/ipfs.ts index cb1dcedcd..28dbf6875 100644 --- a/src/lib/utils/ipfs.ts +++ b/src/lib/utils/ipfs.ts @@ -4,11 +4,15 @@ import { gql } from 'graphql-request'; import expect from './expect'; import filterCurrentChainData from './filter-current-chain-data'; import unreachable from './unreachable'; +import network from '$lib/stores/wallet/network'; import type { + DripListLastProcessedIpfsHashQuery, + DripListLastProcessedIpfsHashQueryVariables, + ProjectLastProcessedIpfsHashQuery, + ProjectLastProcessedIpfsHashQueryVariables, LatestAccountMetadataHashQuery, LatestAccountMetadataHashQueryVariables, } from './__generated__/gql.generated'; -import network from '$lib/stores/wallet/network'; /** * Fetch the given hash from IPFS. @@ -57,32 +61,81 @@ export async function pin(data: Record, f = fetch) { export async function waitForAccountMetadata( accountId: string, expectedIpfsHash: string, + entityType: 'project' | 'dripList' | 'address', f = fetch, ) { await expect( async () => { - const res = await query< - LatestAccountMetadataHashQuery, - LatestAccountMetadataHashQueryVariables - >( - gql` - query LatestAccountMetadataHash($accountId: ID!, $chains: [SupportedChain!]) { - userById(accountId: $accountId, chains: $chains) { + if (entityType === 'project') { + const projectLastProcessedIpfsHashQuery = gql` + query ProjectLastProcessedIpfsHash($projectId: ID!, $chains: [SupportedChain!]) { + projectById(id: $projectId, chains: $chains) { chainData { - chain - latestMetadataIpfsHash + ... on ClaimedProjectData { + chain + lastProcessedIpfsHash + } + ... on UnClaimedProjectData { + chain + } } } } - `, - { accountId, chains: [network.gqlName] }, - f, - ); + `; + + const res = await query< + ProjectLastProcessedIpfsHashQuery, + ProjectLastProcessedIpfsHashQueryVariables + >( + projectLastProcessedIpfsHashQuery, + { projectId: accountId, chains: [network.gqlName] }, + f, + ); + + const chainData = filterCurrentChainData(res.projectById?.chainData || unreachable()); + + return 'lastProcessedIpfsHash' in chainData ? chainData.lastProcessedIpfsHash : null; + } else if (entityType === 'dripList') { + const dripListLastProcessedIpfsHashQuery = gql` + query DripListLastProcessedIpfsHash($dripListId: ID!, $chain: SupportedChain!) { + dripList(id: $dripListId, chain: $chain) { + chain + lastProcessedIpfsHash + } + } + `; + + const res = await query< + DripListLastProcessedIpfsHashQuery, + DripListLastProcessedIpfsHashQueryVariables + >(dripListLastProcessedIpfsHashQuery, { dripListId: accountId, chain: network.gqlName }, f); + + return res.dripList?.lastProcessedIpfsHash; + } else { + const res = await query< + LatestAccountMetadataHashQuery, + LatestAccountMetadataHashQueryVariables + >( + gql` + query LatestAccountMetadataHash($accountId: ID!, $chains: [SupportedChain!]) { + userById(accountId: $accountId, chains: $chains) { + chainData { + chain + latestMetadataIpfsHash + } + } + } + `, + { accountId, chains: [network.gqlName] }, + f, + ); - const chainData = filterCurrentChainData(res.userById?.chainData || unreachable()); + const chainData = filterCurrentChainData(res.userById?.chainData || unreachable()); - return chainData.latestMetadataIpfsHash; + return chainData.latestMetadataIpfsHash; + } }, + (result) => expectedIpfsHash === result, ); }