Skip to content

Commit

Permalink
Account for user rejected error
Browse files Browse the repository at this point in the history
  • Loading branch information
sdankel committed Apr 16, 2024
1 parent 4000fd6 commit 1cd0621
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions app/src/features/toolbar/hooks/useDeployContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ export function useDeployContract(
retry: walletIsLoading && !wallet ? 1 : 0,
onSuccess,
onError: (error) => {
console.error(`Deployment failed: ${error.message}`);
track('Deploy Error', toMetricProperties(error, metricMetadata));
// This is a hack to handle the case where the deployment failed because the user rejected the transaction.
if ((error as any)['code'] === 0) {
track('Deploy Error', { ...metricMetadata, source: 'user-rejected' });
} else {
console.error(`Deployment failed: `, error);
track('Deploy Error', toMetricProperties(error, metricMetadata));
}
onError(error);
},
mutationFn: async () => {
Expand Down Expand Up @@ -71,11 +76,8 @@ export function useDeployContract(
networkUrl: contract.provider.url,
});
} catch (error) {
reject(
new Error(`SDK Error: ${JSON.stringify(error)}`, {
cause: { source: 'sdk' },
})
);
(error as Error).cause = { source: 'sdk' };
reject(error);
}
}
);
Expand Down

0 comments on commit 1cd0621

Please sign in to comment.