From 9e947e87b00b1e26e2f4e8841e3fa7e4487c0dfb Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Fri, 3 Nov 2023 13:29:27 -0700 Subject: [PATCH] feat: add breadcrumb --- apps/trading/client-pages/deposit/deposit.tsx | 296 +++++++++++------- 1 file changed, 188 insertions(+), 108 deletions(-) diff --git a/apps/trading/client-pages/deposit/deposit.tsx b/apps/trading/client-pages/deposit/deposit.tsx index 8cc59e236..5145fa126 100644 --- a/apps/trading/client-pages/deposit/deposit.tsx +++ b/apps/trading/client-pages/deposit/deposit.tsx @@ -21,6 +21,8 @@ import { TokenIcon, TradingButton, TradingInput, + VegaIcon, + VegaIconNames, } from '@vegaprotocol/ui-toolkit'; import { useWeb3React } from '@web3-react/core'; import { @@ -81,6 +83,18 @@ interface DepositState { } type SetDepositState = Dispatch>; +const getMarketsForAsset = ( + markets: MarketMaybeWithDataAndCandles[], + asset: AssetFieldsFragment +) => { + return markets + .filter((m) => { + const marketAsset = getAsset(m); + return marketAsset.id === asset.id; + }) + .slice(0, 4); +}; + const DepositFlow = ({ assets, assetId, @@ -111,7 +125,7 @@ const DepositFlow = ({ }); const handleAssetChanged = useCallback( - async (assetId: string | undefined) => { + async (assetId?: string) => { const asset = assets.find((a) => a.id === assetId); if (!asset) { @@ -168,62 +182,6 @@ const DepositFlow = ({ } }, [state.asset, handleAssetChanged]); - const getMarketsForAsset = (a: AssetFieldsFragment) => { - return markets - .filter((m) => { - const marketAsset = getAsset(m); - return marketAsset.id === a.id; - }) - .slice(0, 4); - }; - - if (state.asset && isAssetTypeERC20(state.asset)) { - return ( -
-
- {isApproved(state.allowance) ? ( - - ) : ( - - )} -
-
-
- -
- -
-
- -
- -
- handleAssetChanged(undefined)} - size="small" - intent={Intent.Danger} - > - {t('Cancel')} - -
-
-
-
- ); - } - const filteredAssets = assets .filter((a) => a.source.__typename === 'ERC20') .filter((a) => a.symbol.toLowerCase().includes(search.toLowerCase())); @@ -233,62 +191,162 @@ const DepositFlow = ({ return 0; }); + const isAssetSelected = state.asset && isAssetTypeERC20(state.asset); + + let step = 0; + if (isAssetSelected) { + if (!state.allowance || state.allowance.isLessThanOrEqualTo(0)) { + step = 1; + } else { + step = 2; + } + } + return (
- +
- setSearch(e.target.value)} - placeholder="Search..." - /> + {!isAssetSelected && ( + setSearch(e.target.value)} + placeholder="Search..." + /> + )}
-
- {filteredAssets.map((a) => { - if (!isAssetTypeERC20(a)) return null; - - const marketsForAsset = getMarketsForAsset(a); - - return ( -
{ - handleAssetChanged(a.id); - }} - role="button" - tabIndex={0} - onKeyDown={(e) => { - if (e.key === 'Enter') { - handleAssetChanged(a.id); - } - }} - className={classNames( - 'p-5 rounded text-left', - 'bg-vega-clight-800 dark:bg-vega-cdark-800 hover:bg-vega-clight-700 dark:hover:bg-vega-cdark-700 cursor-pointer' - )} - > -
-
- -
- -
-
- -
-
- ); - })} -
+ {isAssetSelected ? ( + handleAssetChanged()} + refetchBalances={refetchBalances} + /> + ) : ( + + )}
); }; +const AssetList = ({ + assets, + markets, + onSelect, +}: { + assets: AssetFieldsFragment[]; + markets: MarketMaybeWithDataAndCandles[]; + onSelect: (assetId: string) => void; +}) => { + return ( +
+ {assets.map((a) => { + if (!isAssetTypeERC20(a)) return null; + + const marketsForAsset = getMarketsForAsset(markets, a); + + return ( +
{ + onSelect(a.id); + }} + role="button" + tabIndex={0} + onKeyDown={(e) => { + if (e.key === 'Enter') { + onSelect(a.id); + } + }} + className={classNames( + 'p-5 rounded text-left', + 'bg-vega-clight-800 dark:bg-vega-cdark-800 hover:bg-vega-clight-700 dark:hover:bg-vega-cdark-700 cursor-pointer' + )} + > +
+
+ +
+ +
+
+ +
+
+ ); + })} +
+ ); +}; + +const AssetSelected = ({ + state, + setState, + markets, + bridgeAddress, + confirmations, + faucetEnabled, + refetchBalances, + onCancel, +}: { + state: DepositState; + setState: SetDepositState; + markets: MarketMaybeWithDataAndCandles[]; + bridgeAddress: string; + confirmations: number; + faucetEnabled: boolean; + refetchBalances: () => void; + onCancel: () => void; +}) => { + if (!state.asset) { + throw new Error('no asset selected'); + } + + return ( +
+
+ +
+ +
+
+ +
+ +
+ onCancel()} + size="small" + intent={Intent.Danger} + > + {t('Cancel')} + +
+
+
+ ); +}; const TransactionContainer = ({ state, setState, @@ -582,12 +640,34 @@ const TokenHeader = ({ asset }: { asset: AssetFieldsFragment }) => { ); }; -const StepTitle = ({ step, title }: { step: number; title: string }) => { +const StepBreadcrumb = ({ step }: { step: number }) => { return ( -

- {t('%s/3', step.toString())} - {title} -

+
    + {[ + 'Choose an asset to deposit to the Vega network', + 'Approve deposits', + 'Deposit', + ].map((text, i) => { + const stepNum = i + 1; + return ( +
  1. + {step >= stepNum ? ( + + + + ) : ( + + {stepNum} + + )}{' '} + {text} +
  2. + ); + })} +
); };