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

explicit errors if gasless owner update fails #1262

Merged
merged 1 commit into from
Oct 15, 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: 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');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does assert eventually produce some sort of global error display for the user?

Copy link
Contributor Author

@efstajas efstajas Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, any error thrown within the context of a Stepper will be caught by the stepper component and trigger an Error step that just stringifies the error and shows it to the user. Doesn't matter if that error came from assert or elsewhere.


// First, wait for Gelato Relay to resolve the update task.
await expect(
efstajas marked this conversation as resolved.
Show resolved Hide resolved
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
Loading