Skip to content

Commit

Permalink
explicit errors if gasless owner update fails (#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
efstajas authored Oct 15, 2024
1 parent 321a9d6 commit 4a3bd19
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/lib/flows/claim-project-flow/claim-project-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface State {
maintainerSplits: ListEditorConfig;
dependencySplits: ListEditorConfig;
dependenciesAutoImported: boolean;
gaslessOwnerUpdateTaskId: string | undefined;
avatar:
| {
type: 'emoji';
Expand Down Expand Up @@ -84,6 +85,7 @@ export const state = () =>
weights: {},
},
dependenciesAutoImported: false,
gaslessOwnerUpdateTaskId: undefined,
avatar: {
type: 'emoji',
emoji: '💧',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
$context.linkedToRepo = false;
});
const GASLESS_CALL_ERROR_MESSAGE =
'Something went wrong while trying to update the repo owner on-chain. Please try again in ten minutes or reach out on Discord if the error persists.';
function verify() {
dispatch('await', {
promise: async () => {
Expand Down Expand Up @@ -70,7 +73,7 @@
try {
// Kick off repo owner update using gasless TX
await fetch('/api/gasless/call/repo-owner-update', {
const gaslessCall = await fetch('/api/gasless/call/repo-owner-update', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -81,10 +84,19 @@
chainId: $walletStore.network.chainId,
}),
});
if (!gaslessCall.ok) {
throw new Error(GASLESS_CALL_ERROR_MESSAGE);
}
const { taskId } = await gaslessCall.json();
assert(typeof taskId === 'string', 'Invalid task ID');
$context.gaslessOwnerUpdateTaskId = taskId;
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
throw new Error('Failed to gasless-call repo-owner-update');
throw new Error(GASLESS_CALL_ERROR_MESSAGE);
}
},
message: 'Verifying...',
Expand Down
33 changes: 33 additions & 0 deletions src/lib/flows/claim-project-flow/steps/poll-api/poll-api.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
} from './__generated__/gql.generated';
import filterCurrentChainData from '$lib/utils/filter-current-chain-data';
import network from '$lib/stores/wallet/network';
import assert from '$lib/utils/assert';
const dispatch = createEventDispatcher<StepComponentEvents>();
Expand Down Expand Up @@ -46,6 +47,38 @@
}
`;
assert($context.gaslessOwnerUpdateTaskId, 'Gasless owner update task ID is missing');
// First, wait for Gelato Relay to resolve the update task.
await expect(
async () => {
const res = await fetch(`/api/gasless/track/${$context.gaslessOwnerUpdateTaskId}`);
if (!res.ok) throw new Error('Failed to track gasless owner update task');
const { task } = await res.json();
assert(typeof task === 'object', 'Invalid task');
const { taskState } = task;
assert(typeof taskState === 'string', 'Invalid task state');
return taskState;
},
(taskState) => {
switch (taskState) {
case 'ExecSuccess':
return true;
case 'Cancelled':
throw new Error(
'Failed to gaslessly update the repository owner on-chain. Please reach out to us on Discord.',
);
default:
return false;
}
},
300000,
2000,
);
// Next, wait for the new owner to be indexed by our infra.
await expect(
() =>
query<CheckProjectVerificationStatusQuery, CheckProjectVerificationStatusQueryVariables>(
Expand Down

0 comments on commit 4a3bd19

Please sign in to comment.