-
+
{stepInfo.icon}
+ {error && (
+
+ )}
-
-
- {stepInfo.title}
+
+
+
+ {stepInfo.title}
+
+ {error &&
{error}
}
- {showRetry && i === currentStep && (
+ {error && (
)}
- {i !== steps.length - 1 &&
}
+ {i !== steps.length - 1 &&
}
);
})}
diff --git a/src/views/dialogs/DepositDialog2/utils.ts b/src/views/dialogs/DepositDialog2/utils.ts
index dfafb21d6..0a1a12270 100644
--- a/src/views/dialogs/DepositDialog2/utils.ts
+++ b/src/views/dialogs/DepositDialog2/utils.ts
@@ -1,7 +1,13 @@
import { OfflineSigner } from '@cosmjs/proto-signing';
import { ERC20Approval, RouteResponse, SkipClient, UserAddress } from '@skip-go/client';
import { useQuery } from '@tanstack/react-query';
-import { Address, maxUint256, WalletClient } from 'viem';
+import {
+ Address,
+ ChainMismatchError,
+ maxUint256,
+ UserRejectedRequestError,
+ WalletClient,
+} from 'viem';
import { useChainId } from 'wagmi';
import ERC20ABI from '@/abi/erc20.json';
@@ -65,10 +71,14 @@ export function getUserAddressesForRoute(
});
}
+type StepResult =
+ | { success: true; errorMessage: undefined }
+ | { success: false; errorMessage: string };
+
export type DepositStep =
| {
type: 'network' | 'approve';
- executeStep: (signer: WalletClient) => Promise
;
+ executeStep: (signer: WalletClient) => Promise;
}
| {
type: 'deposit';
@@ -76,7 +86,7 @@ export type DepositStep =
executeStep: (
signer: WalletClient | OfflineSigner,
skipClient: SkipClient
- ) => Promise;
+ ) => Promise;
};
// Prepares all the steps the user needs to take in their wallet to complete their deposit
@@ -111,9 +121,12 @@ export function useDepositSteps({
executeStep: async (signer: WalletClient) => {
try {
await signer.switchChain({ id: Number(depositToken.chainId) });
- return true;
+ return { success: true };
} catch (e) {
- return false;
+ return {
+ success: false,
+ errorMessage: parseError(e, 'There was an error changing wallet networks.'),
+ };
}
},
});
@@ -171,9 +184,19 @@ export function useDepositSteps({
});
const receipt = await viemClient.waitForTransactionReceipt({ hash: txHash });
// TODO future improvement: also check to see if approval amount is sufficient here
- return receipt.status === 'success';
+ // TODO(deposit2.0): localization
+ const isOnChainSuccess = receipt.status === 'success';
+ return {
+ success: isOnChainSuccess,
+ errorMessage: isOnChainSuccess
+ ? undefined
+ : 'Your approval has failed. Please try again.',
+ } as StepResult;
} catch (e) {
- return false;
+ return {
+ success: false,
+ errorMessage: parseError(e, 'There was an error with your approval.'),
+ };
}
},
});
@@ -196,9 +219,12 @@ export function useDepositSteps({
onDeposit({ txHash, chainId: chainID });
},
});
- return true;
+ return { success: true };
} catch (e) {
- return false;
+ return {
+ success: false,
+ errorMessage: parseError(e, 'Your deposit has failed. Please try again.'),
+ };
}
},
});
@@ -213,6 +239,7 @@ export function useDepositSteps({
depositRoute?.amountIn,
depositRoute?.sourceAssetChainID,
depositRoute?.sourceAssetDenom,
+ walletChainId,
],
queryFn: getStepsQuery,
});
@@ -236,3 +263,17 @@ function userAddressHelper(route: RouteResponse, userAddresses: UserAddress[]) {
}
return addressList;
}
+
+// TODO(deposit2.0): localization
+// TODO(deposit2.0): Add final copy for each error message
+function parseError(e: Error, fallbackMessage: string) {
+ if ('code' in e && e.code === UserRejectedRequestError.code) {
+ return 'User rejected request.';
+ }
+
+ if ('name' in e && e.name === ChainMismatchError.name) {
+ return 'Please change your wallet network and try again.';
+ }
+
+ return fallbackMessage;
+}
diff --git a/tailwind.config.js b/tailwind.config.js
index 634ea722c..e66449c8b 100644
--- a/tailwind.config.js
+++ b/tailwind.config.js
@@ -124,7 +124,27 @@ export default {
borderRadius: ({ theme }) => ({
...theme('spacing'),
}),
- extend: {},
+ extend: {
+ animation:{
+ 'shake': 'shake 0.82s cubic-bezier(.36,.07,.19,.97) both',
+ },
+ keyframes: {
+ 'shake' : {
+ '10%, 90%': {
+ transform: 'translate3d(-1px, 0, 0)'
+ },
+ '20%, 80%': {
+ transform: 'translate3d(2px, 0, 0)'
+ },
+ '30%, 50%, 70%': {
+ transform: 'translate3d(-4px, 0, 0)'
+ },
+ '40%, 60%': {
+ transform: 'translate3d(4px, 0, 0)'
+ }
+ }
+ }
+ },
},
plugins: [
plugin(function ({ addUtilities, addComponents }) {