From 684d922ab3d998257d8e7cbf1fbdf44ed004dca7 Mon Sep 17 00:00:00 2001 From: juan Date: Thu, 11 Mar 2021 15:46:11 -0500 Subject: [PATCH] Added solana tokens to token list and allow to select either network --- .../bridge/src/components/Input/input.tsx | 2 + .../src/components/TokenSelectModal/index.tsx | 72 +++++++++++++------ .../components/TokenSelectModal/style.less | 10 ++- .../bridge/src/components/Transfer/index.tsx | 15 +++- packages/bridge/src/contexts/chainPair.tsx | 12 +++- packages/bridge/src/contexts/ethereum.tsx | 32 +++++---- packages/bridge/src/utils/assets.ts | 4 ++ 7 files changed, 105 insertions(+), 42 deletions(-) diff --git a/packages/bridge/src/components/Input/input.tsx b/packages/bridge/src/components/Input/input.tsx index 3e6a73d..ec94502 100644 --- a/packages/bridge/src/components/Input/input.tsx +++ b/packages/bridge/src/components/Input/input.tsx @@ -12,6 +12,7 @@ export function Input(props: { chain?: ASSET_CHAIN; setAsset: (asset: string) => void; amount?: number | null; + onChain: (chain: ASSET_CHAIN) => void; onInputChange: (value: number | undefined) => void; }) { const [lastAmount, setLastAmount] = useState(''); @@ -64,6 +65,7 @@ export function Input(props: {
props.setAsset(token)} + onChain={(chain: ASSET_CHAIN) => props.onChain(chain)} asset={props.asset} chain={props.chain} /> diff --git a/packages/bridge/src/components/TokenSelectModal/index.tsx b/packages/bridge/src/components/TokenSelectModal/index.tsx index 8c2b838..cc8d1ee 100644 --- a/packages/bridge/src/components/TokenSelectModal/index.tsx +++ b/packages/bridge/src/components/TokenSelectModal/index.tsx @@ -1,22 +1,32 @@ -import React, { useMemo, useState } from 'react'; +import React, { useMemo, useRef, useState } from 'react'; import List from 'react-virtualized/dist/commonjs/List'; import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer'; import _ from 'lodash'; import './style.less'; -import { Modal, Input } from 'antd'; +import { Input, Modal } from 'antd'; import { useEthereum } from '../../contexts'; import { TokenDisplay } from '../TokenDisplay'; import { ASSET_CHAIN } from '../../models/bridge/constants'; +import { useConnectionConfig } from '@oyster/common'; +import { filterModalSolTokens } from '../../utils/assets'; export const TokenSelectModal = (props: { onSelectToken: (token: string) => void; + onChain: (chain: ASSET_CHAIN) => void; asset?: string; chain?: ASSET_CHAIN; }) => { - const { tokens } = useEthereum(); + const { tokens: ethTokens } = useEthereum(); + const { tokens: solTokens } = useConnectionConfig(); const [isModalVisible, setIsModalVisible] = useState(false); const [search, setSearch] = useState(''); + const inputRef = useRef(null); + const tokens = useMemo( + () => [...ethTokens, ...filterModalSolTokens(solTokens)], + [ethTokens, solTokens], + ); + const tokenList = useMemo(() => { if (tokens && search) { return tokens.filter(token => { @@ -30,6 +40,9 @@ export const TokenSelectModal = (props: { }, [tokens, search]); const showModal = () => { + if (inputRef && inputRef.current) { + setTimeout(() => inputRef.current?.focus(), 300); + } setIsModalVisible(true); }; @@ -47,29 +60,40 @@ export const TokenSelectModal = (props: { const rowRender = (rowProps: { index: number; key: string; style: any }) => { const token = tokenList[rowProps.index]; const mint = token.address; - return ( -
{ - props.onSelectToken(mint); - hideModal(); - }} - style={{ ...rowProps.style, cursor: 'pointer' }} - > -
- + return [ASSET_CHAIN.Solana, ASSET_CHAIN.Ethereum].map((chain, index) => { + return ( +
{ + props.onSelectToken(mint); + props.onChain(chain); + hideModal(); + }} + style={{ + ...rowProps.style, + cursor: 'pointer', + height: '70px', + top: `${rowProps.style.top + 70 * index}px`, + }} + >
- {token.symbol} - {token.name} + +
+ {token.symbol} + {token.name} +
-
- ); + ); + }); }; return ( @@ -97,6 +121,8 @@ export const TokenSelectModal = (props: { footer={null} > { setAsset={asset => setAssetInformation(asset)} chain={A.chain} amount={A.amount} + onChain={(chain: ASSET_CHAIN) => { + const from = A.chain; + A.setChain(chain); + B.setChain(from); + }} onInputChange={amount => { setLastTypedAccount(A.chain); A.setAmount(amount || 0); @@ -156,6 +161,7 @@ export const Transfer = () => {