diff --git a/apps/trading/client-pages/deposit/deposit.tsx b/apps/trading/client-pages/deposit/deposit.tsx index c6934a375..f673018f0 100644 --- a/apps/trading/client-pages/deposit/deposit.tsx +++ b/apps/trading/client-pages/deposit/deposit.tsx @@ -34,7 +34,9 @@ import { MaxUint256 } from '@ethersproject/constants'; import { useTopTradedMarkets } from '../../lib/hooks/use-top-traded-markets'; import type { MarketMaybeWithDataAndCandles } from '@vegaprotocol/markets'; import { getAsset } from '@vegaprotocol/markets'; -import { CompactNumber } from '@vegaprotocol/react-helpers'; +import classNames from 'classnames'; +import { Networks, useEnvironment } from '@vegaprotocol/environment'; +import { Markets } from './markets'; export const Deposit = () => { return ( @@ -50,6 +52,7 @@ export const Deposit = () => { }; const DepositFlowContainer = () => { + const { VEGA_ENV } = useEnvironment(); const [searchParams] = useSearchParams(); const assetId = searchParams.get('assetId') || undefined; const { data } = useAssetsDataProvider(); @@ -65,6 +68,7 @@ const DepositFlowContainer = () => { assetId={assetId} bridgeAddress={config.collateral_bridge_contract.address} markets={markets || []} + faucetEnabled={VEGA_ENV !== Networks.MAINNET} /> ); }; @@ -89,11 +93,13 @@ const DepositFlow = ({ assetId, bridgeAddress, markets, + faucetEnabled, }: { assets: AssetFieldsFragment[]; assetId?: string; bridgeAddress: string; markets: MarketMaybeWithDataAndCandles[]; + faucetEnabled: boolean; }) => { const { provider, account } = useWeb3React(); const [state, setState] = useState(() => { @@ -187,6 +193,7 @@ const DepositFlow = ({ onSelect={handleAssetChanged} markets={markets} balance={state.balance} + faucetEnabled={faucetEnabled} /> @@ -213,13 +220,9 @@ const DepositFlow = ({ ); }; -//
-//  {JSON.stringify(state, null, 2)}
-// 
- const StepWrapper = ({ children }: { children: ReactNode }) => { return ( -
+
{children}
); @@ -231,14 +234,22 @@ const AssetSelector = ({ onSelect, markets, balance, + faucetEnabled, }: { asset?: AssetFieldsFragment; assets: AssetFieldsFragment[]; onSelect: (asset?: AssetFieldsFragment) => void; markets: MarketMaybeWithDataAndCandles[]; + faucetEnabled: boolean; balance: BigNumber | undefined; }) => { const [search, setSearch] = useState(''); + const [id, setId] = useState(null); + const { provider } = useWeb3React(); + const send = useEthTransactionStore((store) => store.create); + const tx = useEthTransactionStore((store) => { + return store.transactions.find((t) => t?.id == id); + }); const getTopMarkets = (a: AssetFieldsFragment) => { return markets .filter((m) => { @@ -248,36 +259,67 @@ const AssetSelector = ({ .slice(0, 4); }; + const submitFaucet = async () => { + if (!provider) throw new Error('no provider'); + if (!isAssetTypeERC20(asset)) throw new Error('no asset selected'); + const signer = provider.getSigner(); + const contract = new Token( + asset.source.contractAddress, + signer || provider + ); + const id = send(contract, 'faucet', []); + setId(id); + }; + + if (tx && tx.status === EthTxStatus.Pending) { + return ( +
+
+
+ +
+
+

{t('Waiting for faucet...')}

+
+
+
+ ); + } + if (asset && isAssetTypeERC20(asset)) { return ( -
-
- -
-
-

- {asset.symbol}{' '} - {truncateByChars(asset.source.contractAddress)} -

+
+ +
+
+

+ {asset.symbol}{' '} + {truncateByChars(asset.source.contractAddress)} +

+
-
- {balance && ( -
- {balance.toString()} - {asset.symbol} -
- )} +
onSelect(undefined)} size="small"> - Change asset + {t('Change asset')} + {faucetEnabled && ( + + {t('Faucet')} + + )}
+
+ {balance && ( +

+ {balance.toString()} + + {asset.symbol} + +

+ )} +
); @@ -294,7 +336,7 @@ const AssetSelector = ({ }); return ( -
+

{t('Choose an asset to deposit to the Vega network')}

@@ -392,8 +434,8 @@ const Approval = ({ if (!asset) { return (
-
-
+
+

{t('Approval')}

@@ -403,7 +445,10 @@ const Approval = ({ if (!account) { return (
-

{t('Approval')}

+
+ +

{t('Approval')}

+
{t('Connect Ethereum wallet')} @@ -413,38 +458,44 @@ const Approval = ({ if (tx && tx.status === EthTxStatus.Pending) { return ( -
-
- -

{t('Waiting for approval...')}

+
+
+
+ +
+
+

{t('Waiting for approval...')}

+ + {t('Re-approve')} + +
- - {t('Re-approve')} -
); } // APPROVED: show muted re-approve button - if (!allowance || allowance.isGreaterThan(0)) { + if (allowance && allowance.isGreaterThan(0)) { return ( -
-
-
- +
+
+ +
+

{t('Approved')}

+ + {t('Re-approve')} +
-

{t('Approved')}

-
+
{allowance && (
- {asset.symbol} + + {asset.symbol} +
)} - - {t('Re-approve')} -
); @@ -452,31 +503,39 @@ const Approval = ({ // NOT APPROVED: show primary approve button return ( -
-
-
-

{t('Approve deposits')}

+
+
+ +
+

{t('Approve deposits')}

+

+ {t( + 'Before you can make a deposit of %s you need to approve its use', + asset.symbol + )} +

+ { + if (!provider) throw new Error('no provider'); + if (!isAssetTypeERC20(asset)) throw new Error('no provider'); + const signer = provider.getSigner(); + const contract = new Token( + asset.source.contractAddress, + signer || provider + ); + const id = send(contract, 'approve', [ + bridgeAddress, + MaxUint256.toString(), + ]); + setId(id); + }} + size="small" + intent={Intent.Success} + > + {t('Approve %s deposits', asset.symbol)} + +
- { - if (!provider) throw new Error('no provider'); - if (!isAssetTypeERC20(asset)) throw new Error('no provider'); - const signer = provider.getSigner(); - const contract = new Token( - asset.source.contractAddress, - signer || provider - ); - const id = send(contract, 'approve', [ - bridgeAddress, - MaxUint256.toString(), - ]); - setId(id); - }} - size="small" - intent={Intent.Success} - > - {t('Approve %s deposits', asset.symbol)} -
); }; @@ -526,8 +585,8 @@ const SendDeposit = ({ const { account } = useWeb3React(); const fallback = ( -
-
+
+

{t('Deposit')}

); @@ -546,63 +605,62 @@ const SendDeposit = ({ if (!account) { return ( - - {t('Connect Ethereum wallet')} - +
+
+ +

{t('Deposit')}

+
+ + {t('Connect Ethereum wallet')} + +
); } return ( -
-
-
-

{t('Deposit')}

-
-
alert('TODO')}> -
-
- setAmount(e.target.value)} - placeholder="Enter amount" - className="w-full" - /> -
- {balance && ( - setAmount(balance.toString())} - > - {t('Use max')} +
+
+ +
+

{t('Deposit')}

+ alert('TODO')} + > +
+ setAmount(e.target.value)} + placeholder="Enter amount" + className="w-[300px]" + /> + {balance && ( + setAmount(balance.toString())} + > + {t('Use max')} + + )} +
+ + {t('Deposit %s', asset.symbol)} - )} - - {t('Deposit %s', asset.symbol)} - +
- +
); }; -const Markets = ({ markets }: { markets: MarketMaybeWithDataAndCandles[] }) => { +const StepIndicator = ({ complete }: { complete: boolean }) => { + const classes = classNames( + 'flex items-center mt-0.5 w-5 h-5 border-2 rounded border-vega-clight-600' + ); return ( -
- {markets.length ? ( - markets.map((m) => { - return ( -
- {m.tradableInstrument.instrument.code} {m.data?.markPrice} -
- ); - }) - ) : ( -

No markets

- )} +
+ {complete && }
); }; diff --git a/apps/trading/client-pages/deposit/markets.tsx b/apps/trading/client-pages/deposit/markets.tsx new file mode 100644 index 000000000..fc3729f86 --- /dev/null +++ b/apps/trading/client-pages/deposit/markets.tsx @@ -0,0 +1,26 @@ +import type { MarketMaybeWithDataAndCandles } from '@vegaprotocol/markets'; + +export const Markets = ({ + markets, +}: { + markets: MarketMaybeWithDataAndCandles[]; +}) => { + return ( +
+ {markets.length ? ( + markets.map((m) => { + return ( +
+ {m.tradableInstrument.instrument.code} {m.data?.markPrice} +
+ ); + }) + ) : ( +

No markets

+ )} +
+ ); +};