diff --git a/examples/react/src/components/BlockchainSelector.tsx b/examples/react/src/components/BlockchainSelector.tsx index 2be1253..5bd87d5 100644 --- a/examples/react/src/components/BlockchainSelector.tsx +++ b/examples/react/src/components/BlockchainSelector.tsx @@ -13,6 +13,10 @@ interface BlockchainSelectorProps { } const blockchains = [ + { + value: BLOCKCHAIN_NAME.AVALANCHE, + label: 'Avalanche' + }, { value: BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN, label: 'BNB Chain' @@ -20,6 +24,10 @@ const blockchains = [ { value: BLOCKCHAIN_NAME.POLYGON, label: 'Polygon' + }, + { + value: BLOCKCHAIN_NAME.FANTOM, + label: 'Fantom' } ]; diff --git a/examples/react/src/components/Form.tsx b/examples/react/src/components/Form.tsx index b817916..447c018 100644 --- a/examples/react/src/components/Form.tsx +++ b/examples/react/src/components/Form.tsx @@ -63,6 +63,7 @@ const Form = ({}: FormProps) => { if (sdk) { setLoading(true); try { + console.log('Calculating trade, be patient...') if (fromBlockchain === toBlockchain) { const wrappedTrades = await (sdk.instantTrades.calculateTrade(fromToken, String(amount), toToken)) const bestTrade = wrappedTrades.filter(el => !(el instanceof LifiTrade))[0]; @@ -71,8 +72,15 @@ const Form = ({}: FormProps) => { } } else { const wrappedTrades = await (sdk.crossChain.calculateTrade(fromToken, String(amount), toToken)) - const bestTrade = wrappedTrades[0]; - setTrade(bestTrade.trade); + console.log('Response:', wrappedTrades) + const validTrades = wrappedTrades.filter(x => x.trade != null) + const bestTrade = validTrades.length > 0 ? validTrades[0] : undefined + if (bestTrade) { + console.log('Best trade found:', bestTrade, bestTrade?.trade?.toTokenAmountMin.toString()) + setTrade(bestTrade.trade); + } else { + console.log(`0 valid trades found from ${wrappedTrades.length} in the response`) + } } } finally { setLoading(false); diff --git a/examples/react/src/constants/sdk-config.ts b/examples/react/src/constants/sdk-config.ts index 11cb843..6f268d9 100644 --- a/examples/react/src/constants/sdk-config.ts +++ b/examples/react/src/constants/sdk-config.ts @@ -1,12 +1,18 @@ import { BLOCKCHAIN_NAME, Configuration } from 'rubic-sdk'; export const configuration: Configuration = { - rpcProviders: { - [BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN]: { - mainRpc: 'https://bsc-dataseed.binance.org/' - }, - [BLOCKCHAIN_NAME.POLYGON]: { - mainRpc: 'https://polygon-rpc.com' - } - } -} + rpcProviders: { + [BLOCKCHAIN_NAME.AVALANCHE]: { + mainRpc: 'https://rpc.ankr.com/avalanche_fuji' + }, + [BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN]: { + mainRpc: 'https://bsc-dataseed.binance.org/' + }, + [BLOCKCHAIN_NAME.POLYGON]: { + mainRpc: 'https://polygon-rpc.com' + }, + [BLOCKCHAIN_NAME.FANTOM]: { + mainRpc: 'https://rpc.ftm.tools' + }, + } +} \ No newline at end of file diff --git a/examples/react/src/constants/tokens.ts b/examples/react/src/constants/tokens.ts index c6e0f74..97a6591 100644 --- a/examples/react/src/constants/tokens.ts +++ b/examples/react/src/constants/tokens.ts @@ -3,7 +3,52 @@ import {BLOCKCHAIN_NAME} from "rubic-sdk"; export const tokens = [ { address: '0x0000000000000000000000000000000000000000', - name: 'Polygon', + name: 'AVAX', + blockchain: BLOCKCHAIN_NAME.AVALANCHE + }, + { + address: '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7', + name: 'WAVAX', + blockchain: BLOCKCHAIN_NAME.AVALANCHE + }, + { + address: '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e', + name: 'USDC', + blockchain: BLOCKCHAIN_NAME.AVALANCHE + }, + { + address: '0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664', + name: 'USDC.e', + blockchain: BLOCKCHAIN_NAME.AVALANCHE + }, + { + address: '0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7', + name: 'USDT', + blockchain: BLOCKCHAIN_NAME.AVALANCHE + }, + { + address: '0xc7198437980c041c805a1edcba50c1ce5db95118', + name: 'USDT.e', + blockchain: BLOCKCHAIN_NAME.AVALANCHE + }, + { + address: '0x0000000000000000000000000000000000000000', + name: 'MATIC', + blockchain: BLOCKCHAIN_NAME.POLYGON + }, + { + address: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270', + name: 'WMATIC', + blockchain: BLOCKCHAIN_NAME.POLYGON + }, + { + address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', + name: 'USDC', + blockchain: BLOCKCHAIN_NAME.POLYGON + }, + { + address: '0xc2132d05d31c914a87c6611c10748aeb04b58e8f', + name: 'USDT', blockchain: BLOCKCHAIN_NAME.POLYGON }, { @@ -11,9 +56,44 @@ export const tokens = [ name: 'BNB', blockchain: BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN }, + { + address: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', + name: 'WBNB', + blockchain: BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN + }, { address: '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', name: 'USDC', blockchain: BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN - } + }, + { + address: '0x55d398326f99059ff775485246999027b3197955', + name: 'USDT', + blockchain: BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN + }, + { + address: '0xe9e7cea3dedca5984780bafc599bd69add087d56', + name: 'BUSD', + blockchain: BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN + }, + { + address: '0x0000000000000000000000000000000000000000', + name: 'FTM', + blockchain: BLOCKCHAIN_NAME.FANTOM + }, + { + address: '0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83', + name: 'WFTM', + blockchain: BLOCKCHAIN_NAME.FANTOM + }, + { + address: '0x04068da6c83afcfa0e13ba15a6696662335d5b75', + name: 'USDC', + blockchain: BLOCKCHAIN_NAME.FANTOM + }, + { + address: '0x049d68029688eabf473097a2fc38ef61633a3c7a', + name: 'fUSDT', + blockchain: BLOCKCHAIN_NAME.FANTOM + }, ]