Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate new last processed ipfs hash field when awaiting on account metadata update #1384

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
);
}
Loading