From 20bf869d3cc900c18c9e9064c8b76e5d768e4fc5 Mon Sep 17 00:00:00 2001 From: Jason Efstathiou Date: Mon, 14 Oct 2024 16:36:50 +0200 Subject: [PATCH] explicit errors if gasless owner update fails --- .../claim-project-flow/claim-project-flow.ts | 2 ++ .../add-ethereum-address.svelte | 16 +++++++-- .../steps/poll-api/poll-api.svelte | 33 +++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/lib/flows/claim-project-flow/claim-project-flow.ts b/src/lib/flows/claim-project-flow/claim-project-flow.ts index 631cc481c..1428439e4 100644 --- a/src/lib/flows/claim-project-flow/claim-project-flow.ts +++ b/src/lib/flows/claim-project-flow/claim-project-flow.ts @@ -55,6 +55,7 @@ export interface State { maintainerSplits: ListEditorConfig; dependencySplits: ListEditorConfig; dependenciesAutoImported: boolean; + gaslessOwnerUpdateTaskId: string | undefined; avatar: | { type: 'emoji'; @@ -84,6 +85,7 @@ export const state = () => weights: {}, }, dependenciesAutoImported: false, + gaslessOwnerUpdateTaskId: undefined, avatar: { type: 'emoji', emoji: '💧', diff --git a/src/lib/flows/claim-project-flow/steps/add-ethereum-address/add-ethereum-address.svelte b/src/lib/flows/claim-project-flow/steps/add-ethereum-address/add-ethereum-address.svelte index 391bed4d1..60ee3c5dc 100644 --- a/src/lib/flows/claim-project-flow/steps/add-ethereum-address/add-ethereum-address.svelte +++ b/src/lib/flows/claim-project-flow/steps/add-ethereum-address/add-ethereum-address.svelte @@ -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 () => { @@ -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', @@ -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...', diff --git a/src/lib/flows/claim-project-flow/steps/poll-api/poll-api.svelte b/src/lib/flows/claim-project-flow/steps/poll-api/poll-api.svelte index 73ed7eec7..56229ae15 100644 --- a/src/lib/flows/claim-project-flow/steps/poll-api/poll-api.svelte +++ b/src/lib/flows/claim-project-flow/steps/poll-api/poll-api.svelte @@ -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(); @@ -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(