Skip to content

Commit

Permalink
refactor: integrate new last processed ipfs hash field when awaiting …
Browse files Browse the repository at this point in the history
…on account metadata update
  • Loading branch information
jtourkos committed Dec 5, 2024
1 parent fd04f7b commit 3345117
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/lib/flows/create-stream-flow/input-details.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
const { dripsAccountId } = $wallet;
assert(dripsAccountId);
await waitForAccountMetadata(dripsAccountId, newHash);
await waitForAccountMetadata(dripsAccountId, newHash, 'address');
await invalidateAll();
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/flows/delete-stream-flow/confirm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
const { dripsAccountId } = $walletStore;
assert(dripsAccountId);
await waitForAccountMetadata(dripsAccountId, newHash);
await waitForAccountMetadata(dripsAccountId, newHash, 'address');
await goto('/funds');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
],
after: async (_, { accountId, ipfsHash }) => {
await waitForAccountMetadata(accountId, ipfsHash);
await waitForAccountMetadata(accountId, ipfsHash, 'dripList');
await invalidateAccountCache(accountId);
await invalidateAll();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
],
after: async (_, { accountId, ipfsHash }) => {
await waitForAccountMetadata(accountId, ipfsHash);
await waitForAccountMetadata(accountId, ipfsHash, 'project');
await invalidateAccountCache(accountId);
await invalidateAll();
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/flows/edit-project-splits/steps/review.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
],
after: async (_, { newMetadataHash }) => {
await waitForAccountMetadata($context.projectAccountId, newMetadataHash);
await waitForAccountMetadata($context.projectAccountId, newMetadataHash, 'project');
await invalidateAccountCache($context.projectAccountId);
await invalidateAll();
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/flows/edit-stream-flow/enter-new-details.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
const { dripsAccountId } = $walletStore;
assert(dripsAccountId);
await waitForAccountMetadata(dripsAccountId, newHash);
await waitForAccountMetadata(dripsAccountId, newHash, 'address');
await invalidateAll();
},
Expand Down
85 changes: 69 additions & 16 deletions src/lib/utils/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -57,32 +61,81 @@ export async function pin(data: Record<string, unknown>, 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,
);
}

0 comments on commit 3345117

Please sign in to comment.