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

Disable the offramping button after flow start #108

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
11 changes: 9 additions & 2 deletions src/components/buttons/SwapSubmitButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import { FC } from 'preact/compat';
interface SwapSubmitButtonProps {
text: string;
disabled: boolean;
pending: boolean;
}
export const SwapSubmitButton: FC<SwapSubmitButtonProps> = ({ text, disabled }) => (
export const SwapSubmitButton: FC<SwapSubmitButtonProps> = ({ text, disabled, pending }) => (
<ConnectButton.Custom>
{({ account, chain, openConnectModal, authenticationStatus, mounted }) => {
const ready = mounted && authenticationStatus !== 'loading';
const connected =
ready && account && chain && (!authenticationStatus || authenticationStatus === 'authenticated');

const showInDisabledState = disabled || pending;

return (
<div>
{(() => {
Expand All @@ -28,7 +31,11 @@ export const SwapSubmitButton: FC<SwapSubmitButtonProps> = ({ text, disabled })
}

return (
<button className="w-full mt-5 text-white bg-blue-700 btn rounded-xl" disabled={disabled}>
<button
className="w-full mt-5 text-white bg-blue-700 btn rounded-xl disabled:text-neutral-400 disabled:bg-neutral-100"
disabled={showInDisabledState}
>
{pending && <span className="loading loading-spinner loading-sm"></span>}
{text}
</button>
);
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useMainProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { EventStatus, GenericEvent } from '../components/GenericEvent';
import Big from 'big.js';
import { createTransactionEvent, useEventsContext } from '../contexts/events';
import { set } from 'react-hook-form';

export type SigningPhase = 'started' | 'approved' | 'signed' | 'finished';

Expand Down Expand Up @@ -149,6 +150,8 @@ export const useMainProcess = () => {
})();
}, [offrampingPhase, wagmiConfig]);

const resetSep24Url = () => setSep24Url(undefined);

return {
setOfframpingPhase,
handleOnSubmit,
Expand All @@ -157,6 +160,7 @@ export const useMainProcess = () => {
offrampingStarted,
sep24Id,
finishOfframping,
resetSep24Url,
signingPhase,
};
};
12 changes: 5 additions & 7 deletions src/pages/swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const SwapPage = () => {
sep24Id,
offrampingPhase,
setOfframpingPhase,
resetSep24Url,
signingPhase,
} = useMainProcess();

Expand Down Expand Up @@ -238,18 +239,15 @@ export const SwapPage = () => {
target="_blank"
rel="noreferrer"
className="w-full mt-5 text-white bg-blue-700 btn rounded-xl"
onClick={resetSep24Url}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a handler to remove the sep 24 url. It can only be used once anyway (if clicking this button a second time, then only an error message would be shown on the anchor flow).

By removing the url, the disabled spinner button "Offramping in Progress" will be shown again, which makes sense.

>
Start Offramping
</a>
) : (
<SwapSubmitButton
text="Confirm"
disabled={
offrampingPhase !== undefined ||
offrampingStarted ||
Boolean(getCurrentErrorMessage()) ||
!inputAmountIsStable
}
text={offrampingStarted ? 'Offramping in Progress' : 'Confirm'}
disabled={Boolean(getCurrentErrorMessage()) || !inputAmountIsStable}
pending={offrampingStarted || offrampingPhase !== undefined}
/>
)}
</form>
Expand Down
174 changes: 87 additions & 87 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13239,93 +13239,6 @@ __metadata:
languageName: node
linkType: hard

"pendulum-pay@workspace:.":
version: 0.0.0-use.local
resolution: "pendulum-pay@workspace:."
dependencies:
"@babel/core": "npm:^7.20.12"
"@babel/plugin-proposal-class-properties": "npm:^7.18.6"
"@babel/preset-env": "npm:^7.20.2"
"@babel/preset-typescript": "npm:^7.18.6"
"@emotion/react": "npm:^11.11.1"
"@emotion/styled": "npm:^11.11.0"
"@fontsource/roboto": "npm:^5.0.8"
"@heroicons/react": "npm:^2.1.3"
"@hookform/resolvers": "npm:^3.4.2"
"@material-ui/core": "npm:^4.12.4"
"@mui/icons-material": "npm:^5.14.19"
"@mui/material": "npm:^5.14.20"
"@pendulum-chain/api": "npm:^0.3.1"
"@pendulum-chain/api-solang": "npm:^0.6.0"
"@pendulum-chain/types": "npm:^0.2.3"
"@polkadot/api": "npm:^9.9.1"
"@polkadot/api-base": "npm:^9.9.1"
"@polkadot/api-contract": "npm:^9.9.1"
"@polkadot/api-derive": "npm:^9.9.1"
"@polkadot/extension-dapp": "npm:^0.47.1"
"@polkadot/keyring": "npm:^10.1.9"
"@polkadot/rpc-augment": "npm:^9.9.1"
"@polkadot/rpc-core": "npm:^9.9.1"
"@polkadot/rpc-provider": "npm:^9.9.1"
"@polkadot/types": "npm:^9.9.1"
"@polkadot/types-augment": "npm:^9.9.1"
"@polkadot/types-codec": "npm:^9.9.1"
"@polkadot/types-create": "npm:^9.9.1"
"@polkadot/types-known": "npm:^9.9.1"
"@polkadot/util": "npm:^10.1.9"
"@polkadot/util-crypto": "npm:^12.6.2"
"@preact/preset-vite": "npm:^2.5.0"
"@rainbow-me/rainbowkit": "npm:^2.1.2"
"@talismn/connect-components": "npm:^1.1.8"
"@talismn/connect-wallets": "npm:^1.2.5"
"@tanstack/react-query": "npm:^5.45.1"
"@testing-library/jest-dom": "npm:^6.4.8"
"@testing-library/preact": "npm:^3.2.3"
"@testing-library/preact-hooks": "npm:^1.1.0"
"@testing-library/user-event": "npm:^14.5.2"
"@types/big.js": "npm:^6"
"@types/bn.js": "npm:^5"
"@types/node": "npm:^18.14.1"
"@typescript-eslint/eslint-plugin": "npm:^5.53.0"
"@typescript-eslint/parser": "npm:^5.53.0"
"@walletconnect/modal": "npm:^2.6.2"
"@walletconnect/universal-provider": "npm:^2.12.2"
autoprefixer: "npm:^10.4.19"
babel-preset-vite: "npm:^1.1.3"
big.js: "npm:^6.2.1"
bn.js: "npm:^5.2.1"
buffer: "npm:^6.0.3"
daisyui: "npm:^4.11.1"
eslint: "npm:^8.34.0"
eslint-plugin-react: "npm:^7.32.2"
eslint-plugin-react-hooks: "npm:^4.6.0"
framer-motion: "npm:^11.2.14"
happy-dom: "npm:^14.12.3"
husky: "npm:>=6"
lint-staged: "npm:>=10"
postcss: "npm:^8.4.38"
preact: "npm:^10.12.1"
prettier: "npm:^2.8.4"
react-daisyui: "npm:^5.0.0"
react-hook-form: "npm:^7.51.5"
react-native-compat: "npm:^1.0.0"
react-router-dom: "npm:^6.8.1"
stellar-base: "npm:^11.0.1"
stellar-sdk: "npm:^11.3.0"
tailwind: "npm:^4.0.0"
tailwindcss: "npm:^3.4.3"
ts-node: "npm:^10.9.1"
typescript: "npm:^5.3.3"
viem: "npm:2.x"
vite: "npm:^5.3.5"
vite-plugin-node-polyfills: "npm:^0.22.0"
vitest: "npm:^2.0.5"
wagmi: "npm:^2.10.3"
web3: "npm:^4.10.0"
yup: "npm:^1.4.0"
languageName: unknown
linkType: soft

"picocolors@npm:^1, picocolors@npm:^1.0.1":
version: 1.0.1
resolution: "picocolors@npm:1.0.1"
Expand Down Expand Up @@ -17013,6 +16926,93 @@ __metadata:
languageName: node
linkType: hard

"vortex@workspace:.":
version: 0.0.0-use.local
resolution: "vortex@workspace:."
dependencies:
"@babel/core": "npm:^7.20.12"
"@babel/plugin-proposal-class-properties": "npm:^7.18.6"
"@babel/preset-env": "npm:^7.20.2"
"@babel/preset-typescript": "npm:^7.18.6"
"@emotion/react": "npm:^11.11.1"
"@emotion/styled": "npm:^11.11.0"
"@fontsource/roboto": "npm:^5.0.8"
"@heroicons/react": "npm:^2.1.3"
"@hookform/resolvers": "npm:^3.4.2"
"@material-ui/core": "npm:^4.12.4"
"@mui/icons-material": "npm:^5.14.19"
"@mui/material": "npm:^5.14.20"
"@pendulum-chain/api": "npm:^0.3.1"
"@pendulum-chain/api-solang": "npm:^0.6.0"
"@pendulum-chain/types": "npm:^0.2.3"
"@polkadot/api": "npm:^9.9.1"
"@polkadot/api-base": "npm:^9.9.1"
"@polkadot/api-contract": "npm:^9.9.1"
"@polkadot/api-derive": "npm:^9.9.1"
"@polkadot/extension-dapp": "npm:^0.47.1"
"@polkadot/keyring": "npm:^10.1.9"
"@polkadot/rpc-augment": "npm:^9.9.1"
"@polkadot/rpc-core": "npm:^9.9.1"
"@polkadot/rpc-provider": "npm:^9.9.1"
"@polkadot/types": "npm:^9.9.1"
"@polkadot/types-augment": "npm:^9.9.1"
"@polkadot/types-codec": "npm:^9.9.1"
"@polkadot/types-create": "npm:^9.9.1"
"@polkadot/types-known": "npm:^9.9.1"
"@polkadot/util": "npm:^10.1.9"
"@polkadot/util-crypto": "npm:^12.6.2"
"@preact/preset-vite": "npm:^2.5.0"
"@rainbow-me/rainbowkit": "npm:^2.1.2"
"@talismn/connect-components": "npm:^1.1.8"
"@talismn/connect-wallets": "npm:^1.2.5"
"@tanstack/react-query": "npm:^5.45.1"
"@testing-library/jest-dom": "npm:^6.4.8"
"@testing-library/preact": "npm:^3.2.3"
"@testing-library/preact-hooks": "npm:^1.1.0"
"@testing-library/user-event": "npm:^14.5.2"
"@types/big.js": "npm:^6"
"@types/bn.js": "npm:^5"
"@types/node": "npm:^18.14.1"
"@typescript-eslint/eslint-plugin": "npm:^5.53.0"
"@typescript-eslint/parser": "npm:^5.53.0"
"@walletconnect/modal": "npm:^2.6.2"
"@walletconnect/universal-provider": "npm:^2.12.2"
autoprefixer: "npm:^10.4.19"
babel-preset-vite: "npm:^1.1.3"
big.js: "npm:^6.2.1"
bn.js: "npm:^5.2.1"
buffer: "npm:^6.0.3"
daisyui: "npm:^4.11.1"
eslint: "npm:^8.34.0"
eslint-plugin-react: "npm:^7.32.2"
eslint-plugin-react-hooks: "npm:^4.6.0"
framer-motion: "npm:^11.2.14"
happy-dom: "npm:^14.12.3"
husky: "npm:>=6"
lint-staged: "npm:>=10"
postcss: "npm:^8.4.38"
preact: "npm:^10.12.1"
prettier: "npm:^2.8.4"
react-daisyui: "npm:^5.0.0"
react-hook-form: "npm:^7.51.5"
react-native-compat: "npm:^1.0.0"
react-router-dom: "npm:^6.8.1"
stellar-base: "npm:^11.0.1"
stellar-sdk: "npm:^11.3.0"
tailwind: "npm:^4.0.0"
tailwindcss: "npm:^3.4.3"
ts-node: "npm:^10.9.1"
typescript: "npm:^5.3.3"
viem: "npm:2.x"
vite: "npm:^5.3.5"
vite-plugin-node-polyfills: "npm:^0.22.0"
vitest: "npm:^2.0.5"
wagmi: "npm:^2.10.3"
web3: "npm:^4.10.0"
yup: "npm:^1.4.0"
languageName: unknown
linkType: soft

"wagmi@npm:^2.10.3":
version: 2.10.3
resolution: "wagmi@npm:2.10.3"
Expand Down
Loading