@dodoex/widgets 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@lingui/react"),t=require("bignumber.js"),n=require("lodash"),o=require("@dodoex/components"),s=require("@ethersproject/address"),a=require("react"),i=require("react-redux"),r=require("@dodoex/icons"),l=require("identicon.js"),c=require("@web3-react/core"),d=require("@reduxjs/toolkit"),u=require("redux"),p=require("@ethersproject/contracts"),m=require("@ethersproject/constants"),h=require("@ethersproject/abi"),f=require("@web3-react/eip1193"),x=require("@web3-react/walletconnect"),g=require("@web3-react/metamask"),b=require("@ethersproject/providers"),y=require("@web3-react/types"),v=require("react/jsx-runtime"),E=require("@lingui/core"),C=require("react-window"),w=require("make-plural/plurals"),j=require("axios"),T=require("@ethersproject/bignumber"),A=require("react-dom/client");function O(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function B(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var k=O(t),S=B(a),R=O(l),I=O(j);function D({input:e,showDecimals:n=4,showPrecisionDecimals:o=2,showIntegerOnly:s=!1,showDecimalsOnly:a=!1,noGroupSeparator:i=!1}){const r=new t.BigNumber(e);if(r.isNaN())return"-";let l=r.dp(n,t.BigNumber.ROUND_DOWN);return l.eq(0)&&(r.gt(0)||r.lt(0))&&(l=r.sd(null!=o?o:n,t.BigNumber.ROUND_DOWN)),s&&(l=l.integerValue(t.BigNumber.ROUND_DOWN)),a&&(l=l.minus(l.integerValue(t.BigNumber.ROUND_DOWN))),i?l.toFormat({decimalSeparator:".",groupSeparator:"",groupSize:3,secondaryGroupSize:0,fractionGroupSeparator:"",fractionGroupSize:0}):l.toFormat()}function L({input:e,decimals:n,showPrecisionDecimals:o=2,noGroupSeparator:s}){if(null==e)return"-";const a=new t.BigNumber(e);if(a.isNaN())return"-";return D({input:a,showDecimals:void 0===n?0:n>6?6:n>4?4:n,showPrecisionDecimals:o,noGroupSeparator:s})}function N(e){if("number"==typeof e)return N(new t.BigNumber(e));if(e.isNaN())return"NaN";if(e.isNegative())return`-${N(e.negated())}`;if(e.isZero())return"0";let n=e.integerValue(t.BigNumber.ROUND_FLOOR),o=e.minus(n),s="";for(;!n.isZero();){s=n.modulo(10).toString().toString()+s,n=n.idiv(10)}if(""===s&&(s="0"),o.isZero())return s;s+=".";let a=0;for(;!o.isZero()&&a<100;){const e=o.times(10),n=e.integerValue(t.BigNumber.ROUND_FLOOR);s+=n.toString(),o=e.minus(n),a+=1}return s}const M=(e,n)=>{if("string"==typeof e&&!e.match(/[-+]?\d+(.+d+)?/))return e;const o=new t.BigNumber(e);if(n){let e=o.toFixed(n,t.BigNumber.ROUND_DOWN);return s=e,new t.BigNumber(s).isZero()&&(e=N(o.precision(n,t.BigNumber.ROUND_DOWN))),e}var s;return N(o)},_=(e,t)=>{let n=e;const o=n.match("[0-9。.]+");n=o&&o.length>0?o[0]:"",n=n.replace("。",".");let s=0;if(n){const e=n.split("."),t=0===e[0].length?["0"]:[e[0]];e.length>1?t[1]=e.slice(1,e.length).join(""):t[0].length>1&&"0"===t[0][0]&&(t[0]=t[0].slice(1,t[0].length)),t.length>1&&(s=t[1].length),n=t.join(".")}return t>=0&&s>t?M(n,t):n},P=(e,t)=>{if(0===e.length||0===t.length)return!1;if(t.length===e.length)return e.toLowerCase()===t.toLowerCase();const n=e.substring(2,e.length).toLowerCase(),o=t.substring(2,t.length).toLowerCase();return n.length>o.length?n.endsWith(o):o.endsWith(n)};function F(e){try{return s.getAddress(e)}catch(e){return!1}}const U=e=>{const t={isMainnet:1===e,isRinkeby:4===e,isGor:5===e};return Object.assign(Object.assign({},t),{isETH:t.isMainnet||t.isRinkeby||t.isGor})};var W;!function(e){e[e.MAINNET=1]="MAINNET",e[e.RINKEBY=4]="RINKEBY",e[e.GOERLI=5]="GOERLI",e[e.BSC=56]="BSC",e[e.HECO=128]="HECO",e[e.POLYGON=137]="POLYGON",e[e.ARBITRUM_ONE=42161]="ARBITRUM_ONE",e[e.ARBITRUM_RINKEBY=421611]="ARBITRUM_RINKEBY",e[e.AURORA=1313161554]="AURORA",e[e.MOONRIVER=1285]="MOONRIVER",e[e.OKCHAIN=66]="OKCHAIN",e[e.OPTIMISM=10]="OPTIMISM",e[e.BOBA=288]="BOBA",e[e.AVALANCHE=43114]="AVALANCHE",e[e.CRONOS=25]="CRONOS"}(W||(W={}));const H={[W.MAINNET]:["https://rpc.ankr.com/eth","https://eth-mainnet.public.blastapi.io","https://eth-rpc.gateway.pokt.network","https://main-rpc.linkpool.io"],[W.RINKEBY]:["https://rinkeby-light.eth.linkpool.io/"],[W.GOERLI]:["https://goerli.optimism.io/"],[W.BSC]:["https://bsc-dataseed1.binance.org","https://bsc-dataseed2.binance.org","https://bsc-dataseed3.binance.org","https://bsc-dataseed4.binance.org","https://bsc-dataseed1.defibit.io","https://bsc-dataseed2.defibit.io","https://bsc-dataseed3.defibit.io","https://bsc-dataseed4.defibit.io","https://bsc-dataseed1.ninicoin.io","https://bsc-dataseed2.ninicoin.io","https://bsc-dataseed3.ninicoin.io","https://bsc-dataseed4.ninicoin.io","https://bsc-dataseed.binance.org","https://rpc.ankr.com/bsc","https://bscrpc.com","https://bsc.mytokenpocket.vip","https://binance.nodereal.io","https://rpc-bsc.bnb48.club"],[W.HECO]:["https://http-mainnet.hecochain.com","https://pub001.hg.network/rpc"],[W.POLYGON]:["https://polygon-rpc.com","https://rpc-mainnet.matic.network","https://matic-mainnet.chainstacklabs.com","https://rpc-mainnet.maticvigil.com","https://rpc-mainnet.matic.quiknode.pro","https://matic-mainnet-full-rpc.bwarelabs.com","https://matic-mainnet-archive-rpc.bwarelabs.com","https://poly-rpc.gateway.pokt.network","https://rpc.ankr.com/polygon","https://polygon-mainnet.public.blastapi.io"],[W.ARBITRUM_ONE]:["https://arb1.arbitrum.io/rpc","https://rpc.ankr.com/arbitrum"],[W.ARBITRUM_RINKEBY]:["https://rinkeby.arbitrum.io/rpc"],[W.AURORA]:["https://mainnet.aurora.dev/"],[W.MOONRIVER]:["https://rpc.api.moonriver.moonbeam.network","https://moonriver.api.onfinality.io/rpc?apikey=673e1fae-c9c9-4c7f-a3d5-2121e8274366","https://moonriver.api.onfinality.io/public","https://moonriver.public.blastapi.io"],[W.OKCHAIN]:["https://exchainrpc.okex.org","https://okc-mainnet.gateway.pokt.network/v1/lb/6275309bea1b320039c893ff"],[W.OPTIMISM]:["https://mainnet.optimism.io","https://optimism-mainnet.public.blastapi.io"],[W.BOBA]:["https://mainnet.boba.network","https://boba-mainnet.gateway.pokt.network/v1/lb/623ad21b20354900396fed7f","https://lightning-replica.boba.network"],[W.AVALANCHE]:["https://api.avax.network/ext/bc/C/rpc","https://rpc.ankr.com/avalanche","https://ava-mainnet.public.blastapi.io/ext/bc/C/rpc"],[W.CRONOS]:["https://evm.cronos.org","https://cronos-rpc.heavenswail.one","https://evm-cronos.crypto.org","https://cronosrpc-1.xstaking.sg","https://cronos-rpc.elk.finance"]},$={symbol:"ETH",address:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",name:"Ether",decimals:18,showDecimals:4,wrappedTokenSymbol:"WETH"},z={[W.MAINNET]:Object.assign(Object.assign({},$),{wrappedTokenAddress:"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}),[W.RINKEBY]:Object.assign(Object.assign({},$),{wrappedTokenAddress:"0xB26c0d8Be2960c70641A95A9195BE1f59Ac83aC0"}),[W.GOERLI]:Object.assign(Object.assign({},$),{wrappedTokenAddress:"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6"}),[W.OPTIMISM]:Object.assign(Object.assign({},$),{wrappedTokenAddress:"0x4200000000000000000000000000000000000006"}),[W.CRONOS]:Object.assign(Object.assign({},$),{symbol:"CRO",name:"Cronos",wrappedTokenSymbol:"WCRO",wrappedTokenAddress:"0x5C7F8A570d578ED84E63fdFA7b1eE72dEae1AE23"}),[W.BOBA]:Object.assign(Object.assign({},$),{wrappedTokenAddress:"0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000"}),[W.BSC]:Object.assign(Object.assign({},$),{symbol:"BNB",name:"BNB",wrappedTokenSymbol:"WBNB",wrappedTokenAddress:"0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}),[W.OKCHAIN]:Object.assign(Object.assign({},$),{symbol:"OKT",name:"OKT",wrappedTokenSymbol:"WOKT",wrappedTokenAddress:"0x8F8526dbfd6E38E3D8307702cA8469Bae6C56C15"}),[W.HECO]:Object.assign(Object.assign({},$),{symbol:"HT",name:"HT",showDecimals:6,wrappedTokenSymbol:"WHT",wrappedTokenAddress:"0x5545153ccfca01fbd7dd11c0b23ba694d9509a6f"}),[W.POLYGON]:Object.assign(Object.assign({},$),{symbol:"MATIC",name:"MATIC",showDecimals:6,wrappedTokenSymbol:"WMATIC",wrappedTokenAddress:"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270"}),[W.MOONRIVER]:Object.assign(Object.assign({},$),{symbol:"MOVR",name:"MOVR",showDecimals:6,wrappedTokenSymbol:"WMOVR",wrappedTokenAddress:"0x98878b06940ae243284ca214f92bb71a2b032b8a"}),[W.ARBITRUM_ONE]:Object.assign(Object.assign({},$),{name:"Ethereum",showDecimals:6,wrappedTokenAddress:"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"}),[W.ARBITRUM_RINKEBY]:Object.assign(Object.assign({},$),{name:"Ether",showDecimals:6,wrappedTokenAddress:"0xEBbc3452Cc911591e4F18f3b36727Df45d6bd1f9"}),[W.AURORA]:Object.assign(Object.assign({},$),{name:"Ethereum",showDecimals:6,wrappedTokenAddress:"0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB"}),[W.AVALANCHE]:Object.assign(Object.assign({},$),{symbol:"AVAX",name:"Avalanche",showDecimals:6,wrappedTokenSymbol:"WAVAX",wrappedTokenAddress:"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7"})},V={[W.MAINNET]:"ethereum",[W.RINKEBY]:"rinkeby",[W.GOERLI]:"goerli",[W.OPTIMISM]:"optimism",[W.CRONOS]:"cronos",[W.BOBA]:"boba",[W.BSC]:"bsc",[W.OKCHAIN]:"okex-chain",[W.HECO]:"heco",[W.POLYGON]:"polygon",[W.MOONRIVER]:"moonriver",[W.ARBITRUM_ONE]:"arbitrum",[W.ARBITRUM_RINKEBY]:"arb-rinkeby",[W.AURORA]:"aurora",[W.AVALANCHE]:"avalanche"},q={[W.MAINNET]:"etherscan.io",[W.RINKEBY]:"rinkeby.etherscan.io",[W.GOERLI]:"goerli.etherscan.io",[W.OPTIMISM]:"optimistic.etherscan.io",[W.CRONOS]:"cronoscan.com",[W.BOBA]:"blockexplorer.boba.network",[W.BSC]:"bscscan.com",[W.OKCHAIN]:"www.oklink.com/okexchain",[W.HECO]:"hecoinfo.com",[W.POLYGON]:"polygonscan.com",[W.MOONRIVER]:"moonriver.moonscan.io",[W.ARBITRUM_ONE]:"arbiscan.io",[W.ARBITRUM_RINKEBY]:"testnet.arbiscan.io",[W.AURORA]:"aurorascan.dev",[W.AVALANCHE]:"snowtrace.io"};function K(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(o=Object.getOwnPropertySymbols(e);s<o.length;s++)t.indexOf(o[s])<0&&Object.prototype.propertyIsEnumerable.call(e,o[s])&&(n[o[s]]=e[o[s]])}return n}function G(e,t,n,o){return new(n||(n=Promise))((function(s,a){function i(e){try{l(o.next(e))}catch(e){a(e)}}function r(e){try{l(o.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,r)}l((o=o.apply(e,t||[])).next())}))}const Y={colorMode:"dark",slippage:3..toString(),ddl:20};var X=(e=Y,t)=>{switch(t.type){case"SET_COLOR_MODE":return Object.assign(Object.assign({},e),{colorMode:t.payload});case"SET_SLIPPAGE":return Object.assign(Object.assign({},e),{slippage:t.payload});case"SET_TRANSACTION_DDL":return Object.assign(Object.assign({},e),{ddl:t.payload});default:return e}};const Z={chainId:W.MAINNET,latestBlockNumber:0};var Q=(e=Z,t)=>{switch(t.type){case"SET_CHAIN_ID":return Object.assign(Object.assign({},e),{chainId:t.payload});case"SET_BLOCK_NUMBER":return Object.assign(Object.assign({},e),{latestBlockNumber:t.payload});default:return e}};const J={tokenList:[],popularTokenList:[],ethBalance:void 0,accountBalances:{},balanceLoadings:{},slippageWithTokens:[]};var ee,te=(e=J,t)=>{switch(t.type){case"SET_TOKEN_LIST":return Object.assign(Object.assign({},e),{tokenList:t.payload});case"SET_POPULAR_TOKEN_LIST":return Object.assign(Object.assign({},e),{popularTokenList:t.payload});case"SET_SLIPPAGE_WITH_TOKENS":return Object.assign(Object.assign({},e),{slippageWithTokens:t.payload});case"SET_ETH_BALANCE":return Object.assign(Object.assign({},e),{ethBalance:t.payload});case"SET_DEFAULT_FROM_TOKEN":return Object.assign(Object.assign({},e),{defaultFromToken:t.payload});case"SET_DEFAULT_TO_TOKEN":return Object.assign(Object.assign({},e),{defaultToToken:t.payload});case"SET_ACCOUNT_BALANCES":return Object.assign(Object.assign({},e),{accountBalances:Object.assign(Object.assign({},e.accountBalances),t.payload)});case"SET_ACCOUNT_ALLOWANCES":const n=e.accountBalances;return Object.keys(n).map((e=>{n[e].tokenAllowances=t.payload})),Object.assign(Object.assign({},e),{accountBalances:n});case"SET_BALANCE_LOADINGS":return Object.assign(Object.assign({},e),{balanceLoadings:Object.assign(Object.assign({},e.balanceLoadings),t.payload)});default:return e}};!function(e){e.Initial="Initial",e.Pending="Pending",e.ApproveSuccess="ApproveSuccess",e.TxSuccess="TxSuccess",e.Failed="Failed"}(ee||(ee={}));const ne={height:void 0,width:void 0,apikey:"",feeRate:0,rebateTo:"",isReverseRouting:!1,contractStatus:ee.Initial};var oe=(e=ne,t)=>"SET_GLOBAL_PROPS"===t.type?Object.assign(Object.assign({},e),t.payload):e;const se={settings:Y,wallet:Z,globals:ne,token:J},ae=u.combineReducers({settings:X,wallet:Q,token:te,globals:oe}),ie=d.configureStore({reducer:ae,middleware:e=>e({serializableCheck:{ignoredActions:["SET_ACCOUNT_BALANCES","SET_ETH_BALANCE"],ignoredPaths:["token.accountBalances","token.ethBalance"]}}),preloadedState:se}),re=e=>(null!=e?e:ie.getState()).wallet.chainId,le=e=>(null!=e?e:ie.getState()).wallet.latestBlockNumber,ce=e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_ACCOUNT_BALANCES",payload:e})})),de=e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_BALANCE_LOADINGS",payload:e})}));var ue=[{constant:!0,inputs:[],name:"getCurrentBlockTimestamp",outputs:[{name:"timestamp",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{components:[{name:"target",type:"address"},{name:"callData",type:"bytes"}],name:"calls",type:"tuple[]"}],name:"aggregate",outputs:[{name:"blockNumber",type:"uint256"},{name:"returnData",type:"bytes[]"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"getLastBlockHash",outputs:[{name:"blockHash",type:"bytes32"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"addr",type:"address"}],name:"getEthBalance",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"getCurrentBlockDifficulty",outputs:[{name:"difficulty",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"getCurrentBlockGasLimit",outputs:[{name:"gaslimit",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"getCurrentBlockCoinbase",outputs:[{name:"coinbase",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"blockNumber",type:"uint256"}],name:"getBlockHash",outputs:[{name:"blockHash",type:"bytes32"}],payable:!1,stateMutability:"view",type:"function"}],pe={[W.MAINNET]:{MULTI_CALL:"0xeefba1e63905ef1d7acba5a8513c70307c1ce441",DODO_APPROVE:"0xCB859eA579b28e02B87A1FDE08d087ab9dbE5149",ERC20_HELPER:"0xD9ef2d1583e8Aa196123e773BE38B539a4d149df"},[W.RINKEBY]:{MULTI_CALL:"0xb7E1C577f95959a3eD11f9281702850328b4e0e4",DODO_APPROVE:"0xcC8d87A7C747eeE4242045C47Ef25e0A81D56ae3",ERC20_HELPER:"0x6A42091d713A67E25a1D11aeE14E7AEB96E0331f"},[W.GOERLI]:{MULTI_CALL:"0x696E25A5e2AEd1C55E6d6Cfa0532Bbda9020165d",DODO_APPROVE:"0xC9143e54021f4a6d33b9b89DBB9F458AaEdd56FB",ERC20_HELPER:"0x24549FC74B3076A962624A26370ed556c467F74C"},[W.BSC]:{MULTI_CALL:"0x1Ee38d535d541c55C9dae27B12edf090C608E6Fb",DODO_APPROVE:"0xa128Ba44B2738A558A1fdC06d6303d52D3Cef8c1",ERC20_HELPER:"0x566651Ad34f6306872FaC5fB95bbF4C9beE8D8F2"},[W.HECO]:{MULTI_CALL:"0x76a328B3440B9276a31523e731B34082df7a6f1A",DODO_APPROVE:"0x68b6c06Ac8Aa359868393724d25D871921E97293",ERC20_HELPER:"0x270C2abC692Dd476B860CCbDfD6D8146BF61f8D8"},[W.POLYGON]:{MULTI_CALL:"0xc9eD9B18e447e600238fe50e944B9062B664DEa4",DODO_APPROVE:"0x292E6b2e054e1157df71C1C9510265CA8C0c7672",ERC20_HELPER:"0xfd24312Ec7871A6D1a31e454D5AbB16c6c25a9b3"},[W.ARBITRUM_ONE]:{MULTI_CALL:"0xF718F2bd590E5621e53f7b89398e52f7Acced8ca",DODO_APPROVE:"0xA867241cDC8d3b0C07C85cC06F25a0cD3b5474d8",ERC20_HELPER:"0x7C062B9C584fA6eC2504270790D38240A2c5fE72"},[W.ARBITRUM_RINKEBY]:{MULTI_CALL:"0x696E25A5e2AEd1C55E6d6Cfa0532Bbda9020165d",DODO_APPROVE:"0x5BaF16d57620Cb361F622232F3cb4090e35F3da2",ERC20_HELPER:"0x5B2fd46E6E3Ff1E479d651ec0b210882Aa9871dF"},[W.AURORA]:{MULTI_CALL:"0x989DcAA95801C527C5B73AA65d3962dF9aCe1b0C",DODO_APPROVE:"0x335aC99bb3E51BDbF22025f092Ebc1Cf2c5cC619",ERC20_HELPER:"0xE8C9A78725D0451FA19878D5f8A3dC0D55FECF25"},[W.MOONRIVER]:{MULTI_CALL:"0x2ff2CeE6E9359F9eA1cF2f51d18bF9F2045447E4",DODO_APPROVE:"0xE8C9A78725D0451FA19878D5f8A3dC0D55FECF25",ERC20_HELPER:"0x6373ceB657C83C91088d328622573FB766064Ac4"},[W.OKCHAIN]:{MULTI_CALL:"0x5e84190a270333aCe5B9202a3F4ceBf11b81bB01",DODO_APPROVE:"0x7737fd30535c69545deeEa54AB8Dd590ccaEBD3c",ERC20_HELPER:"0x4775b1858f1e417C9609D455C3Ad8751ec01daC4"},[W.OPTIMISM]:{MULTI_CALL:"0xb98Ac2fEFc8b73aeAE33D02BB00c26E12afCa9Df",DODO_APPROVE:"0xa492d6eABcdc3E204676f15B950bBdD448080364",ERC20_HELPER:"0x42E456ea0dd7538ea103fBb1d0388D14C97bB5b2"},[W.BOBA]:{MULTI_CALL:"0xD56281EF996B6B29874C77D2e1464216E8043127",DODO_APPROVE:"0x8F8Dd7DB1bDA5eD3da8C9daf3bfa471c12d58486",ERC20_HELPER:"0x9FCFD9ff955D36856F8EE480471B05488C0eB5cA"},[W.AVALANCHE]:{MULTI_CALL:"0x97f0153E7F5749640aDF3Ff9CFC518b79D6Fe53b",DODO_APPROVE:"0xCFea63e3DE31De53D68780Dd65675F169439e470",ERC20_HELPER:"0xC3528D128CC227fd60793007b5e3FdF7c2945282"},[W.CRONOS]:{MULTI_CALL:"0x4f4408D78F9E9e242c17C635FbD0f1952951c917",DODO_APPROVE:"0x9B736bB8f336f61E16454DCA4dE130703D151042",ERC20_HELPER:"0xbd2F5c60cf7d60daD2106ceD4D21b90722761f14"}};function me(e,t,...n){return G(this,void 0,void 0,(function*(){const o=[];for(const e of n)for(const t of e)t.callData&&o.push(t.callData);const s=yield function(e,t,n){return G(this,void 0,void 0,(function*(){const o=yield he(e,t,n),s=new Map;for(const{req:e,resp:t}of o)s.set(e,t);return e.map((e=>({req:e,resp:s.get(e)})))}))}(o,e,t),a=new Map;for(const{req:e,resp:t}of s)a.set(e,null==t?void 0:t.result);return n.map((e=>e.filter((e=>!e.callData||a.get(e.callData))).map(((e,t)=>e.processor(e.callData?a.get(e.callData):null,t)))))}))}function he(e,t,o){return G(this,void 0,void 0,(function*(){let s=[e];e.length>800&&(s=n.chunk(e,800));let a=[];const i=s.map((e=>G(this,void 0,void 0,(function*(){const n=e.map((e=>[e.to,e.data])),s={data:t.interface.encodeFunctionData("aggregate",[n]),to:o};let i;try{i=yield t.provider.call(s)}catch(n){const s=e.length;if(s>20){const n=Math.floor(s/2),[i,r]=yield Promise.all([he(e.slice(0,n),t,o),he(e.slice(n,s),t,o)]);a=[...a,...i,...r]}else{const e="[sendCallReqs] error";console.error(e,n)}}if(void 0===i)throw new Error("Unexpected batch result");const[r,l]=h.defaultAbiCoder.decode(["uint256","bytes[]"],i);if(e.length!==l.length)throw new Error("Unexpected length mismatch");return l.map(((t,n)=>({resp:{result:t},req:e[n]})))}))));return(yield Promise.allSettled(i)).filter((e=>"fulfilled"===e.status)).forEach((({value:e})=>{a=[...a,...e]})),a}))}function fe(e,t,n,o){if(!F(e)||e===m.AddressZero)throw Error(`Invalid 'address' parameter '${e}'.`);return new p.Contract(e,t,function(e,t){return t?function(e,t){return e.getSigner(t).connectUnchecked()}(e,t):e}(n,o))}function xe(){const{provider:e,account:t,chainId:n}=c.useWeb3React(),[o,s]=a.useState(!1),i=a.useMemo((()=>pe[n]),[n]),r=a.useCallback(((n,o)=>{if(e)return fe(n,o,e,t)}),[e,t]),l=a.useCallback((e=>{if(!i)return;const{MULTI_CALL:t}=i,n=r(t,ue);return(()=>G(this,void 0,void 0,(function*(){if(n){s(!0);try{const[o]=yield me(n,t,e);return o}catch(e){console.error("Contract: useMultiContract is error",e)}s(!1)}})))()}),[i,r]);return{getContract:r,contractConfig:i,call:l,loading:o}}var ge=[{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"isERC20",outputs:[{internalType:"bool",name:"isOk",type:"bool"},{internalType:"string",name:"symbol",type:"string"},{internalType:"string",name:"name",type:"string"},{internalType:"uint256",name:"decimals",type:"uint256"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"allownance",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"judgeERC20",outputs:[{internalType:"string",name:"symbol",type:"string"},{internalType:"string",name:"name",type:"string"},{internalType:"uint256",name:"decimals",type:"uint256"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"allownance",type:"uint256"}],stateMutability:"view",type:"function"}];function be(){const{provider:e,account:t}=c.useWeb3React(),n=i.useDispatch(),o=i.useSelector(le);a.useEffect((()=>{(()=>{G(this,void 0,void 0,(function*(){if(!e||!t)return;const o=yield e.getBalance(t);n((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_ETH_BALANCE",payload:e})})))(new k.default(o.toString()).div(1e18)))}))})()}),[e,t,n,o])}function ye(){const{provider:e,chainId:t}=c.useWeb3React(),n=i.useDispatch();a.useEffect((()=>{const o=e=>{n((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_BLOCK_NUMBER",payload:e})})))(e))};return(()=>{G(this,void 0,void 0,(function*(){if(!e||!t)return;const n=yield e.getBlockNumber();o(n),e.on("block",o)}))})(),()=>{null==e||e.off("block",o)}}),[e,n,t])}function ve(e){return Number.parseInt(e,16)}class Ee extends y.Connector{constructor(e,t){super(e),this.customProvider=t,t.on("connect",(({chainId:e})=>{this.actions.update({chainId:ve(e)})})).on("disconnect",(e=>{var t;null===(t=this.onError)||void 0===t||t.call(this,e),this.actions.resetState()})).on("chainChanged",(e=>{this.actions.update({chainId:ve(e)})})).on("accountsChanged",(e=>{this.actions.update({accounts:e})}))}activate(){return G(this,void 0,void 0,(function*(){this.actions.startActivation();const e=this.customProvider;try{const[{chainId:t},n]=yield Promise.all([e.getNetwork(),e.listAccounts()]);this.actions.update({chainId:t,accounts:n})}catch(e){throw this.actions.resetState(),e}}))}}function Ce([e,t]){return[e,t]}var we;function je(){return je=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},je.apply(this,arguments)}var Te,Ae;function Oe(){return Oe=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},Oe.apply(this,arguments)}var Be;!function(e){e.INTEGRATOR="integrator",e.METAMASK="metamask",e.WALLET_CONNECT="walletConnect"}(Be||(Be={}));const ke={[Be.METAMASK]:{name:"MetaMask",type:Be.METAMASK,icon:function(e){return S.createElement("svg",je({height:355,viewBox:"0 0 397 355",width:397,xmlns:"http://www.w3.org/2000/svg"},e),we||(we=S.createElement("g",{fill:"none",fillRule:"evenodd",transform:"translate(-1 -1)"},S.createElement("path",{d:"m114.622644 327.195472 52.004717 13.810198v-18.05949l4.245283-4.249292h29.716982v21.246459 14.872523h-31.839624l-39.268868-16.997169z",fill:"#cdbdb2"}),S.createElement("path",{d:"m199.528305 327.195472 50.943397 13.810198v-18.05949l4.245283-4.249292h29.716981v21.246459 14.872523h-31.839623l-39.268868-16.997169z",fill:"#cdbdb2",transform:"matrix(-1 0 0 1 483.96227 0)"}),S.createElement("path",{d:"m170.872644 287.889523-4.245283 35.056657 5.306604-4.249292h55.18868l6.367925 4.249292-4.245284-35.056657-8.490565-5.311615-42.452832 1.062323z",fill:"#393939"}),S.createElement("path",{d:"m142.216984 50.9915022 25.471698 59.4900858 11.674528 173.158643h41.391511l12.735849-173.158643 23.349056-59.4900858z",fill:"#f89c35"}),S.createElement("path",{d:"m30.7783023 181.657226-29.71698153 86.048161 74.29245393-4.249293h47.7594343v-37.181303l-2.122641-76.487253-10.613208 8.498583z",fill:"#f89d35"}),S.createElement("path",{d:"m87.0283032 191.218134 87.0283028 2.124646-9.551886 44.617563-41.391511-10.623229z",fill:"#d87c30"}),S.createElement("path",{d:"m87.0283032 192.280457 36.0849058 33.994334v33.994334z",fill:"#ea8d3a"}),S.createElement("path",{d:"m123.113209 227.337114 42.452831 10.623229 13.79717 45.679888-9.551886 5.311615-46.698115-27.620398z",fill:"#f89d35"}),S.createElement("path",{d:"m123.113209 261.331448-8.490565 65.864024 56.25-39.305949z",fill:"#eb8f35"}),S.createElement("path",{d:"m174.056606 193.34278 5.306604 90.297451-15.919812-46.211049z",fill:"#ea8e3a"}),S.createElement("path",{d:"m74.2924539 262.393771 48.8207551-1.062323-8.490565 65.864024z",fill:"#d87c30"}),S.createElement("path",{d:"m24.4103777 355.878193 90.2122663-28.682721-40.3301901-64.801701-73.23113313 5.311616z",fill:"#eb8f35"}),S.createElement("path",{d:"m167.688682 110.481588-45.636793 38.243627-35.0235858 42.492919 87.0283028 3.186969z",fill:"#e8821e"}),S.createElement("path",{d:"m114.622644 327.195472 56.25-39.305949-4.245283 33.994334v19.121813l-38.207548-7.43626z",fill:"#dfcec3"}),S.createElement("path",{d:"m229.245286 327.195472 55.18868-39.305949-4.245283 33.994334v19.121813l-38.207548-7.43626z",fill:"#dfcec3",transform:"matrix(-1 0 0 1 513.679252 0)"}),S.createElement("path",{d:"m132.665096 212.464593-11.674528 24.433427 41.39151-10.623229z",fill:"#393939",transform:"matrix(-1 0 0 1 283.372646 0)"}),S.createElement("path",{d:"m23.349057 1.06232296 144.339625 109.41926504-24.410378-59.4900858z",fill:"#e88f35"}),S.createElement("path",{d:"m23.349057 1.06232296-19.10377392 58.42776294 10.61320772 63.7393781-7.42924541 4.249292 10.61320771 9.560906-8.49056617 7.436261 11.67452847 10.623229-7.4292454 6.373938 16.9811323 21.246459 79.5990577-24.433428c38.915096-31.161473 58.018869-47.096318 57.311322-47.804533-.707548-.708215-48.820756-37.1813036-144.339625-109.41926504z",fill:"#8e5a30"}),S.createElement("g",{transform:"matrix(-1 0 0 1 399.056611 0)"},S.createElement("path",{d:"m30.7783023 181.657226-29.71698153 86.048161 74.29245393-4.249293h47.7594343v-37.181303l-2.122641-76.487253-10.613208 8.498583z",fill:"#f89d35"}),S.createElement("path",{d:"m87.0283032 191.218134 87.0283028 2.124646-9.551886 44.617563-41.391511-10.623229z",fill:"#d87c30"}),S.createElement("path",{d:"m87.0283032 192.280457 36.0849058 33.994334v33.994334z",fill:"#ea8d3a"}),S.createElement("path",{d:"m123.113209 227.337114 42.452831 10.623229 13.79717 45.679888-9.551886 5.311615-46.698115-27.620398z",fill:"#f89d35"}),S.createElement("path",{d:"m123.113209 261.331448-8.490565 65.864024 55.18868-38.243626z",fill:"#eb8f35"}),S.createElement("path",{d:"m174.056606 193.34278 5.306604 90.297451-15.919812-46.211049z",fill:"#ea8e3a"}),S.createElement("path",{d:"m74.2924539 262.393771 48.8207551-1.062323-8.490565 65.864024z",fill:"#d87c30"}),S.createElement("path",{d:"m24.4103777 355.878193 90.2122663-28.682721-40.3301901-64.801701-73.23113313 5.311616z",fill:"#eb8f35"}),S.createElement("path",{d:"m167.688682 110.481588-45.636793 38.243627-35.0235858 42.492919 87.0283028 3.186969z",fill:"#e8821e"}),S.createElement("path",{d:"m132.665096 212.464593-11.674528 24.433427 41.39151-10.623229z",fill:"#393939",transform:"matrix(-1 0 0 1 283.372646 0)"}),S.createElement("path",{d:"m23.349057 1.06232296 144.339625 109.41926504-24.410378-59.4900858z",fill:"#e88f35"}),S.createElement("path",{d:"m23.349057 1.06232296-19.10377392 58.42776294 10.61320772 63.7393781-7.42924541 4.249292 10.61320771 9.560906-8.49056617 7.436261 11.67452847 10.623229-7.4292454 6.373938 16.9811323 21.246459 79.5990577-24.433428c38.915096-31.161473 58.018869-47.096318 57.311322-47.804533-.707548-.708215-48.820756-37.1813036-144.339625-109.41926504z",fill:"#8e5a30"})))))},link:"https://metamask.io"},[Be.WALLET_CONNECT]:{name:"WalletConnect",type:Be.WALLET_CONNECT,icon:function(e){return S.createElement("svg",Oe({height:512,viewBox:"0 0 512 512",width:512,xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink"},e),Te||(Te=S.createElement("radialGradient",{id:"a",cx:"0%",cy:"50%",r:"100%"},S.createElement("stop",{offset:0,stopColor:"#5d9df6"}),S.createElement("stop",{offset:1,stopColor:"#006fff"}))),Ae||(Ae=S.createElement("g",{fill:"none",fillRule:"evenodd"},S.createElement("path",{d:"m256 0c141.384896 0 256 114.615104 256 256s-114.615104 256-256 256-256-114.615104-256-256 114.615104-256 256-256z",fill:"url(#a)"}),S.createElement("path",{d:"m64.6917558 37.7088298c51.5328072-50.2784397 135.0839942-50.2784397 186.6167992 0l6.202057 6.0510906c2.57664 2.5139218 2.57664 6.5897948 0 9.1037177l-21.215998 20.6995759c-1.288321 1.2569619-3.3771 1.2569619-4.665421 0l-8.534766-8.3270205c-35.950573-35.0754962-94.237969-35.0754962-130.188544 0l-9.1400282 8.9175519c-1.2883217 1.2569609-3.3771016 1.2569609-4.6654208 0l-21.2159973-20.6995759c-2.5766403-2.5139229-2.5766403-6.5897958 0-9.1037177zm230.4934852 42.8089117 18.882279 18.4227262c2.576627 2.5139103 2.576642 6.5897593.000032 9.1036863l-85.141498 83.070358c-2.576623 2.513941-6.754182 2.513969-9.33084.000066-.00001-.00001-.000023-.000023-.000033-.000034l-60.428256-58.957451c-.64416-.628481-1.68855-.628481-2.33271 0-.000004.000004-.000008.000007-.000012.000011l-60.4269683 58.957408c-2.5766141 2.513947-6.7541746 2.51399-9.3308408.000092-.0000151-.000014-.0000309-.000029-.0000467-.000046l-85.14386774-83.071463c-2.57663928-2.513921-2.57663928-6.589795 0-9.1037163l18.88231264-18.4226955c2.5766393-2.5139222 6.7541993-2.5139222 9.3308397 0l60.4291347 58.9582758c.6441608.62848 1.6885495.62848 2.3327103 0 .0000095-.000009.0000182-.000018.0000277-.000025l60.4261065-58.9582508c2.576581-2.51398 6.754142-2.5140743 9.33084-.0002103.000037.0000354.000072.0000709.000107.0001063l60.429056 58.9583548c.644159.628479 1.688549.628479 2.332709 0l60.428079-58.9571925c2.57664-2.5139231 6.754199-2.5139231 9.330839 0z",fill:"#fff",fillRule:"nonzero",transform:"translate(98 160)"}))))}}},Se={};function Re({provider:e,jsonRpcUrlMap:t,defaultChainId:n}){const o=console.error,s=a.useMemo((()=>function(e,t){if(t){if(b.JsonRpcProvider.isProvider(t))return Ce(c.initializeConnector((e=>new Ee(e,t))));if(b.JsonRpcProvider.isProvider(t.provider))throw new Error("Eip1193Bridge is experimental: pass your ethers Provider directly");return Ce(c.initializeConnector((n=>new f.EIP1193({actions:n,provider:t,onError:e}))))}}(o,e)),[o,e]),i=a.useMemo((()=>function(e){return Ce(c.initializeConnector((t=>new g.MetaMask({actions:t,onError:e}))))}(o)),[o]),r=a.useMemo((()=>t?Object.assign(Object.assign({},H),t):H),[t]),l=a.useMemo((()=>function(e,t,n,o){return Ce(c.initializeConnector((s=>new x.WalletConnect({actions:s,options:{rpc:t,qrcode:e},onError:o,defaultChainId:n}))))}(!0,r,n,o)),[r,n,o]);return s&&(Se[Be.INTEGRATOR]=s),Se[Be.METAMASK]=i,Se[Be.WALLET_CONNECT]=l,Object.values(Se)}function Ie(){const{chainId:e}=c.useWeb3React(),t=i.useSelector(re);return a.useMemo((()=>e||t||1),[e,t])}function De({tokenList:e,popularTokenList:t}){const n=i.useDispatch(),[o,s]=a.useState([]),{account:r}=c.useWeb3React(),l=Ie(),d=i.useSelector(le),u=a.useMemo((()=>(null==t?void 0:t.filter((e=>e.chainId===l)))||[]),[t,l]),p=a.useMemo((()=>{const e=o.map((({address:e})=>e));return null==t||t.forEach((({address:t})=>{e.includes(t)||e.push(t)})),e}),[o,t]);!function({tokenList:e,addresses:t,blockNumber:n}){const{account:o}=c.useWeb3React(),s=i.useDispatch(),r=a.useMemo((()=>[...(null==e?void 0:e.map((e=>e.address)))||[],...t||[]].map((e=>e.toLocaleLowerCase()))),[e,t]),{getContract:l,contractConfig:d,call:u}=xe(),[p,m]=a.useState(),f=a.useMemo((()=>{if(!o||!r.length||!d)return;const{DODO_APPROVE:e,ERC20_HELPER:t}=d,n=l(t,ge);if(!n)return;let a={};const i=r.map((s=>(a[s]=!0,{callData:{data:n.interface.encodeFunctionData("isERC20",[s,o,e]),to:t},processor:e=>{const t=new h.Interface(ge).decodeFunctionResult("isERC20",e),{balance:n,isOk:o}=t,a=parseInt(t.decimals),i=new k.default(10).pow(a),r=new k.default(t.allownance.toString()).div(i);return o?{address:s,decimals:a,symbol:t.symbol,name:t.name,balance:new k.default(n.toString()).div(i),allowance:r}:{address:s,balance:new k.default(0),allowance:new k.default(0)}}})));return s(de(a)),i}),[o,l,r]);a.useEffect((()=>{(()=>{G(this,void 0,void 0,(function*(){if(!f)return;const e=yield u(f),t={};e&&(e.forEach((e=>{t[e.address.toLocaleLowerCase()]={tokenBalances:e.balance,tokenAllowances:e.allowance}})),s(ce(t))),m(e);let n={};r.forEach((e=>{n[e]=!1})),s(de(n))}))})()}),[f,n])}({addresses:p,blockNumber:d}),a.useEffect((()=>{(()=>{G(this,void 0,void 0,(function*(){let t=[];if(e)t=e;else{t=(yield Promise.resolve().then((function(){return require("./tokenList-ee5e15c8.cjs")}))).default}const o=l,a=t.filter((e=>e.chainId===o));s(a),n((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_TOKEN_LIST",payload:e})})))(a))}))})()}),[e,n,l]),a.useEffect((()=>{n(ce({}))}),[r,l]),a.useEffect((()=>{n((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_POPULAR_TOKEN_LIST",payload:e})})))(u))}),[u,n])}const Le=e=>(null!=e?e:ie.getState()).token.tokenList,Ne=e=>(null!=e?e:ie.getState()).token.accountBalances,Me=e=>(null!=e?e:ie.getState()).token.ethBalance||new k.default(NaN),_e=e=>(null!=e?e:ie.getState()).token.defaultFromToken,Pe=e=>(null!=e?e:ie.getState()).token.defaultToToken,Fe=e=>(null!=e?e:ie.getState()).token.balanceLoadings;function Ue(){const{account:e,chainId:t}=c.useWeb3React(),n=i.useSelector(Ne),o=i.useSelector(Me),s=a.useMemo((()=>z[t||1]),[t]),r=a.useCallback((t=>{var a;if(!e)return null;if(t.symbol===s.symbol&&P(t.address,s.address))return!o||(null==o?void 0:o.isNaN())?null:o;const i=null===(a=n[t.address.toLocaleLowerCase()])||void 0===a?void 0:a.tokenBalances;return!i||(null==i?void 0:i.isNaN())?null:i}),[n,o,e]);return r}var We;function He(e,t,n,o=0){if(n&&(e=e.toLocaleLowerCase(),t=t.toLocaleLowerCase()),e===t)return We.fully+o;const s=e.indexOf(t);return 0===s?We.prefix+o:s>0?We.other+o:We.none}!function(e){e[e.fully=1]="fully",e[e.prefix=2]="prefix",e[e.other=3]="other",e[e.none=0]="none"}(We||(We={}));function $e({value:e,onChange:t,occupiedAddrs:n,hiddenAddrs:o,showAddrs:s}){const[r,l]=a.useState(""),c=i.useSelector(Le),d=Ie(),u=Ue(),p=a.useMemo((()=>new Set(o?o.map((e=>e.toLowerCase())):void 0)),[o]),m=a.useMemo((()=>s?new Set(s.map((e=>e.toLowerCase()))):void 0),[s]),h=a.useCallback((e=>e.filter((e=>{if(e.chainId!==d)return!1;let t=!0;return t=m?m.has(e.address.toLowerCase()):!p.has(e.address.toLowerCase()),t}))),[m,d,p]),f=a.useCallback((t=>{if(null===t)return null;const o=[];r?t.forEach((e=>{const t=((e,t,{matchAddress:n}={})=>{if(!t)return 0;const o=t.toLocaleLowerCase();let s=0;n&&e.address.toLocaleLowerCase()===o&&(s=1),s||(s=He(e.symbol.toLocaleLowerCase(),o,!1,1));if(s)e.name.toLocaleLowerCase()===o&&(s=We.fully+1);else{let t=He(e.name.toLocaleLowerCase(),o,!1,10);t=t===We.fully+10?We.fully+1:t,s=t}return s})(e,r,{matchAddress:!0});t&&o.push({sort:t,token:e})})):t.forEach((e=>{o.push({sort:0,token:e})}));const s=[];return o.sort(((t,o)=>{const s=t.token,a=o.token;if(e){if(s.address===e.address)return-1;if(a.address===e.address)return 1}if(null==n?void 0:n.includes(s.address))return-1;if(null==n?void 0:n.includes(a.address))return 1;const i=u&&u(s)||new k.default(0),r=u&&u(a)||new k.default(0);return i.eq(r)?t.sort!==o.sort?t.sort>o.sort?1:-1:s.symbol.localeCompare(a.symbol):i.gt(r)?-1:1})).some((e=>!!(r&&s.length>21)||(s.push(e.token),!1))),s}),[r,u,n,e]),x=a.useCallback((e=>{const o=e.address.toLowerCase();t(e,!!(null==n?void 0:n.some((e=>e.toLowerCase()===o))))}),[t,n]),g=a.useMemo((()=>{const e=h(c);return f(e)||[]}),[c,h,f]);return{filter:r,setFilter:l,showTokenList:g,onSelectToken:x}}function ze({width:e=24,height:t=24,marginRight:n=8,url:s,zIndex:r,cross:l,address:d,token:u,sx:p}){const[m,h]=a.useState(!1),[f,x]=a.useState(""),[g,b]=a.useState(""),[y,E]=a.useState(!1),C=a.useCallback((()=>h(!0)),[]);let w=function(e){const t=i.useSelector(Le),{chainId:n}=c.useWeb3React();return a.useMemo((()=>{if(!e)return;let o=t.find((({address:t,chainId:o})=>o===n&&t===e));return o||(o=t.find((({address:t})=>t===e))),o}),[e,t,n])}(d);u&&(w=u);const j=d||(null==w?void 0:w.address),T=null==w?void 0:w.symbol,A=null==T?void 0:T.charAt(0).toUpperCase(),O=a.useMemo((()=>{const e=null==w?void 0:w.logoURI;return s||e||""}),[s,w]);return a.useEffect((()=>{E(!1)}),[j,O]),a.useEffect((()=>{l&&(O?function(e,t){const n=new XMLHttpRequest;let o;n.onload=function(){const e=new FileReader;e.onloadend=function(){t(e.result)},e.readAsDataURL(n.response)},n.onerror=function(){t()};try{o=new URL(e)}catch(e){}finally{n.open("GET",o||e),n.responseType="blob",n.send()}}(O,(e=>{x(e)})):x(""))}),[O,l]),a.useEffect((()=>{try{let t=j;if(t&&t.length<15&&(t=t.padEnd(15,"0")),t){const n=new R.default(t,{size:e,format:"svg",margin:.2,background:[255,234,4,255]}).toString();b(`data:image/svg+xml;base64,${n}`)}}catch(e){console.error("generate Identicon error: ",e)}}),[j,e]),v.jsxs(o.Box,{sx:Object.assign({position:"relative",display:"flex",alignItems:"center",justifyContent:"center",minWidth:e,width:e,height:t,marginRight:n,zIndex:r},p||{}),style:{width:e,height:t},children:[!m&&v.jsx(o.Box,{sx:{typography:"ht",height:"100%",width:"100%",borderRadius:"50%",border:"transparent 2px solid",borderColor:"text.primary",color:"text.primary",display:"flex",alignItems:"center",justifyContent:"center"},children:A}),v.jsx(o.Box,{component:"img",src:!(l?f:O)||y?g:l?f:O,onLoad:C,onError:e=>{const t=e.target;j&&g&&E(!0),t.onerror=null},sx:{position:"absolute",top:"0",bottom:"0",left:"0",right:"0",borderRadius:"50%",overflow:"hidden",width:"100%",height:"100%"}})]})}function Ve({token:t,onClick:n}){var s,a;const i=o.useTheme();return v.jsxs(o.Box,{component:o.BaseButton,sx:{display:"flex",alignItems:"center",color:i.palette.text.primary,typography:"h5",fontWeight:600},onClick:e=>{n&&n(e)},"data-testid":"swap-select-token-btn",children:[(null==t?void 0:t.address)?v.jsxs(v.Fragment,{children:[v.jsx(ze,{address:null!==(s=null==t?void 0:t.address)&&void 0!==s?s:"",marginRight:6}),v.jsx(o.Box,{children:null!==(a=null==t?void 0:t.symbol)&&void 0!==a?a:"-"})]}):v.jsx(e.Trans,{id:"SELECT TOKEN"}),v.jsx(o.Box,{sx:{ml:7,width:12,transform:"rotateX(180deg)"},component:r.CaretUp})]})}function qe({onClick:t,balance:n,decimals:s,address:a,showMaxBtn:i}){const{palette:r}=o.useTheme();return v.jsxs(o.Box,{sx:{display:"flex",typography:"body2",color:r.text.secondary},children:[v.jsx(e.Trans,{id:"Balance:"})," ",a?L({input:n,decimals:Math.min(s||4,4)}):"-",i&&n&&n.gt(0)&&v.jsx(o.Box,{component:o.BaseButton,sx:{ml:6,color:(null==n?void 0:n.gt(0))?r.primary.main:r.text.disabled,cursor:a&&t?"pointer":"unset"},onClick:()=>t&&t(n?n.toString():""),children:v.jsx(e.Trans,{id:"Max"})})]})}function Ke({readOnly:e,sx:t,value:n,decimals:s,onChange:i,suffix:l,withClear:c,onFocus:d,placeholder:u}){const p=o.useTheme(),m=a.useMemo((()=>l||(c&&n&&i?v.jsx(o.Box,{component:o.BaseButton,sx:{ml:5,width:18,height:18,borderRadius:"50%",backgroundColor:"border.main",display:"flex",justifyContent:"center",alignItems:"center"},onClick:()=>{i&&i("")},children:v.jsx(o.Box,{component:r.Error,sx:{width:12,color:"text.primary"}})}):void 0)),[i,l,p.palette.text.primary,n,c]);return v.jsxs(o.Box,{sx:Object.assign({mt:12,display:"flex",justifyContent:"space-between",alignItems:"center"},t),"data-testid":"number-input-wrapper",children:[v.jsx(o.Input,{fullWidth:!0,value:n,readOnly:e,placeholder:u||"0.00",onFocus:d,onChange:e=>{const t=e.target.value,n=0===t.length?"":_(t,s);i&&i(n)},sx:{width:"inherit",border:"none","& .MuiInput-input":{fontSize:24,border:"none",outline:"none",height:24,padding:0,color:"text.primary","&::placeholder":{fontSize:24,color:"text.disabled"}}}}),!e&&n&&m]})}function Ge({open:e,onClose:t,title:n,rightSlot:s,canBack:a=!0,children:i,height:l,testId:c}){return v.jsxs(o.Box,{sx:{position:"absolute",top:e?0:"100%",transition:"top 300ms",zIndex:1,left:0,right:0,bottom:0,display:"flex",flexDirection:"column",backgroundColor:"background.paper",borderRadius:16,height:l},"data-testid":c,"data-active":e?"1":"0",children:[n?v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:20},children:[v.jsx(o.Box,{sx:{display:"flex",alignItems:"center",typography:"caption"},children:n}),s,!s&&a&&v.jsx(o.Box,{component:r.Error,sx:{color:"text.secondary",cursor:"pointer"},onClick:t})]}):"",i]})}const Ye=e=>(null!=e?e:ie.getState()).globals;function Xe({token:e,disabled:t,onClick:n}){return v.jsxs(o.Box,{sx:Object.assign({display:"inline-flex",alignItems:"center",p:8,border:"solid 1px",typography:"body2",borderRadius:8},t?{borderColor:"transparent",backgroundColor:"border.disabled",cursor:"auto"}:{borderColor:"border.main",cursor:"pointer","&:hover":{backgroundColor:"hover.default"}}),onClick:()=>{t||n()},children:[v.jsx(ze,{token:e}),e.symbol]})}function Ze({token:e,disabled:t,style:n,onClick:s}){const a=Ue()(e),i=a?D({input:a}):"";return v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",typography:"body2",px:6,py:5,borderRadius:8,cursor:t?"auto":"pointer",opacity:t?.5:1,"&:hover":{backgroundColor:"hover.default"}},style:n,onClick:()=>{t||s()},"data-testid":"token-picker-item",children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(ze,{token:e}),v.jsxs(o.Box,{children:[v.jsx(o.Box,{sx:{fontWeight:600,textAlign:"left"},children:e.symbol}),v.jsx(o.Box,{sx:{mt:4,textAlign:"left"},children:i})]})]}),v.jsx(o.Box,{sx:{color:"text.secondary"},children:e.name})]})}function Qe({value:e,onChange:t,occupiedAddrs:n,hiddenAddrs:s,showAddrs:r,visible:l}){var c;const d=Ie(),u=i.useSelector((e=>((e,t)=>(null!=t?t:ie.getState()).token.popularTokenList.filter((({chainId:t})=>e===t)))(d,e))),{showTokenList:p,filter:m,setFilter:h,onSelectToken:f}=$e({value:e,onChange:t,occupiedAddrs:n,hiddenAddrs:s,showAddrs:r}),x=a.useRef(null),g=a.useRef(null),[b,y]=a.useState(0);a.useEffect((()=>{l&&x.current&&y(x.current.offsetHeight-34)}),[x,l]);const w=a.useCallback((({index:t,style:n})=>{const s=!!(null==u?void 0:u.length);if(0===t&&s)return v.jsx(o.Box,{sx:{position:"relative",display:"flex",gap:8,flexWrap:"wrap",pb:32,"&::after":{content:'""',position:"absolute",bottom:16,left:0,right:0,height:"1px",backgroundColor:"border.main"}},ref:g,style:Object.assign(Object.assign({},n),{visibility:n.height?"visible":"hidden",height:n.height?n.height:"auto"}),children:u.map((t=>v.jsx(Xe,{token:t,disabled:(null==e?void 0:e.address)===t.address,onClick:()=>f(t)},t.address)))});const a=p[s?t-1:t];return v.jsx(Ze,{token:a,disabled:!!e&&e.address===a.address,style:n,onClick:()=>f(a)})}),[p,u,g,e]),j=a.useCallback((e=>{var t;if(0===e&&(null==u?void 0:u.length)){const e=(null===(t=g.current)||void 0===t?void 0:t.offsetHeight)||0;return e<=52?0:e}return 52}),[g,u]);return v.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",px:20,flex:1},children:[v.jsx(o.SearchInput,{fullWidth:!0,height:48,value:m,onChange:e=>h(e.target.value),clearValue:()=>h(""),placeholder:E.i18n._("Enter the token symbol or address")}),v.jsx(o.Box,{sx:{mt:16,pb:16,flex:1,minHeight:64},ref:x,children:v.jsx(C.VariableSizeList,{height:b,itemCount:p.length+((null==u?void 0:u.length)?1:0),itemSize:j,width:"100%",className:"token-list",children:w},null===(c=g.current)||void 0===c?void 0:c.offsetHeight)})]})}function Je({open:t,value:n,onClose:o,occupiedAddrs:s,onTokenChange:a}){const{height:r}=i.useSelector(Ye);return v.jsx(Ge,{height:r,open:t,onClose:o,title:v.jsx(e.Trans,{id:"Select a token"}),testId:"token-picker-wrapper",children:v.jsx(Qe,{value:n,visible:t,onChange:a,occupiedAddrs:s})})}function et({sx:e,amt:t,token:n,readOnly:s,showMaxBtn:i,onMaxClick:r,fiatPriceTxt:l,occupiedAddrs:c,onInputFocus:d,onTokenClick:u,onInputChange:p,onTokenChange:m}){const h=o.useTheme(),f=Ue(),[x,g]=a.useState(!1),b=n?f(n):null;return v.jsxs(o.Box,{sx:Object.assign({width:"100%",minHeight:133,padding:20,borderRadius:12,overflow:"hidden",display:"flex",flexDirection:"column",justifyContent:"space-between",backgroundColor:h.palette.background.input},e),children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[v.jsx(Ve,{token:n,onClick:()=>g(!0)}),v.jsx(qe,{balance:b,onClick:r,showMaxBtn:i,address:null==n?void 0:n.address,decimals:null==n?void 0:n.decimals})]}),v.jsx(Ke,{value:t,onFocus:d,onChange:p,readOnly:s,withClear:!0}),v.jsx(o.Box,{sx:{mt:4,typography:"body2",color:h.palette.text.secondary},children:l}),v.jsx(Je,{value:n,open:x,occupiedAddrs:c,onClose:()=>{u&&u(),g(!1)},onTokenChange:(e,t)=>{m(e,t),g(!1)}})]})}const tt={"en-US":w.en,"zh-CN":w.zh,pseudo:w.en};function nt({locale:t,children:n}){return a.useEffect((()=>{(()=>{G(this,void 0,void 0,(function*(){yield function(e="en-US"){return G(this,void 0,void 0,(function*(){E.i18n.loadLocaleData(e,{plurals:()=>tt[e]});try{const n=yield(t=`./locales/${e}.js`,Promise.resolve().then((function(){return B(require(t))})));E.i18n.load(e,n.messages||n.default.messages)}catch(e){}var t;E.i18n.activate(e)}))}(t)}))})()}),[t]),v.jsx(e.I18nProvider,{i18n:E.i18n,children:n})}var ot,st,at;!function(e){e[e.Running=0]="Running",e[e.Success=1]="Success",e[e.Failed=2]="Failed",e[e.Warning=3]="Warning"}(ot||(ot={})),function(e){e.Canceled="canceled",e.Failed="failed",e.Success="success",e.Submitted="submitted"}(st||(st={})),function(e){e[e.Failed=0]="Failed",e[e.Success=1]="Success"}(at||(at={}));var it,rt=[{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"guy",type:"address"},{name:"wad",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"}];!function(e){e[e.Failed=0]="Failed",e[e.Success=1]="Success",e[e.Warning=2]="Warning"}(it||(it={}));const lt=(e,t)=>G(void 0,void 0,void 0,(function*(){const{value:n,from:o,to:s,data:a}=e,i={from:o,to:s,value:n,data:a};n&&!/^0x0*$/.test(n)||delete i.value;try{return(yield t.estimateGas(i)).add(5e4)}catch(e){t.call(i).then((e=>{if("test"!==process.env.NODE_ENV)throw new Error("Unexpected issue with estimating the gas. Please try again.")})).catch((e=>{if("test"!==process.env.NODE_ENV)throw e}))}return null})),ct=(e,t)=>G(void 0,void 0,void 0,(function*(){try{return yield t.getSigner().sendTransaction(e)}catch(e){throw 4001===(null==e?void 0:e.code)?new Error(E.i18n._("Transaction rejected.")):e}}));var dt,ut;!function(e){e.Approval="APPROVAL",e.TX="TX",e.TypedSign="TypedSign"}(dt||(dt={})),function(e){e.Normal="Normal",e.Privacy="Privacy",e.LimitOrder="LimitOrder",e.RFQ="RFQ"}(ut||(ut={}));const pt=new k.default(2).pow(256).minus(1),mt=e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_GLOBAL_PROPS",payload:e})}));function ht({onTxFail:e,onTxSubmit:t,onTxSuccess:n}={}){const{account:o,provider:s}=c.useWeb3React(),r=Ie(),[l,d]=a.useState(!1),[u,p]=a.useState(new Map),m=i.useDispatch(),[h,f]=a.useState(null),[x,g]=a.useState(""),[b,y]=a.useState(null),[v,C]=a.useState(!1),[w,j]=a.useState(),T=a.useCallback(((a,i,l,c=!1,u,h,x,b)=>G(this,void 0,void 0,(function*(){if(g(""),f(""),!o||!s)throw new Error("Submission: Cannot execute step when the wallet is disconnected");let v,w,T;j((()=>x)),d(!1);try{if(d(!0),i.opcode===dt.Approval)T=yield((e,t,n,o,s,a)=>G(void 0,void 0,void 0,(function*(){const i=fe(e,rt,s,a).interface.encodeFunctionData("approve",[n,o.toFixed()]),r={from:t,to:e,data:i,value:`0x${new k.default("0").toString(16)}`,gasLimit:void 0},l=yield lt(r,s);return l&&(r.gasLimit=l),yield ct(r,s)})))(i.token.address,o,i.contract,i.amt||pt,s,o),v=T.hash,g(v);else{if(i.opcode!==dt.TX)throw new Error(`Op ${i.opcode} not implemented!`);if(""===i.to)throw new Error("Submission: malformed to");if(0===i.data.length)throw new Error("Submission: malformed data");if(0===i.data.indexOf("0x")&&i.data.length<=2)throw new Error("Submission: malformed data");if(w={value:i.value,data:i.data,to:i.to,gasLimit:i.gasLimit,from:o,chainId:r},!w.gasLimit)try{const e=yield lt(w,s);e&&(w.gasLimit=e)}catch(e){console.debug(e)}if(T=yield ct(w,s),v=T.hash,g(v),!v)throw new Error(`Unexpected tx: ${v}`)}}catch(t){if(d(!1),y({spec:i,brief:a,subtitle:l}),console.error(t),t.message){m(mt({contractStatus:ee.Failed}));const n={error:t.message,brief:a};h&&Object.assign(n,h),e&&e(t,h),f(function(e,t){var n;const o=null===(n=z[e])||void 0===n?void 0:n.symbol,s=[{error:"insufficient",msg:E.i18n._("Insufficient funds - Please retry after depositing more {EtherTokenSymbol} into your wallet",{EtherTokenSymbol:o})},{error:["External Swap execution Failed","Return amount is not enough"],msg:E.i18n._("Price impact exceeds the slippage tolerance you set. Try increasing the slippage tolerance.")},{error:"SafeERC20: low-level call failed",msg:E.i18n._("SafeERC20: low-level call failed. Please log a Zendesk support ticket or contact the DODO team.")},{error:["User denied","cancel","User rejected","user rejected"],msg:E.i18n._("User denied transaction signature.")},{error:["Cannot set properties of undefined (setting 'loadingDefauIts'){\"originalError\":{",'[ethjs-query]while formatting outputs from RPC\'["value":["code":-32000,"message":"header not found"))'],msg:E.i18n._("RPC node data exception")},{error:['execution reverted:FORCESTOP ["originalError"'],msg:E.i18n._("ForceStop exception")},{error:["replacement transaction underpriced","Gasprice too low","transaction underprice"],msg:E.i18n._("Gas price is too low, please adjust in your wallet and try again")},{error:["MINT_INVALID"],msg:E.i18n._("No ForceStop access")},{error:["NOT_PHASE_EXE"],msg:E.i18n._("Unable to SETTLE during the cooling-off period")},{error:["params specify an EIP-1559transaction but the currentnetwork does not support"],msg:E.i18n._("Wallet incompatibility")},{error:["ALREADY_SETTLED"],msg:E.i18n._("This CP has been settled by other addrs")},{error:["create RFQ order failed]:LESS_THAN_FEE_LIMIT"],msg:E.i18n._("Service update, please wait and try again")}];let a="";return s.some((e=>Array.isArray(e.error)?e.error.some((n=>t.indexOf(n)>-1&&(a=e.msg,!0))):t.indexOf(e.error)>-1&&(a=e.msg,!0))),a||t}(r,t.message))}return st.Failed}y({spec:i,brief:a,subtitle:l}),C(!1),d(!1);const A=Object.assign(Object.assign(Object.assign(Object.assign({brief:a},i),w),{tx:v,subtitle:l}),h);m(mt({contractStatus:ee.Pending})),t&&t(v,A),u&&u();const O={brief:a,spec:i,tx:v,subtitle:l};if(p((e=>e.set(v,[O,ot.Running]))),c)return st.Submitted;if(u&&u(),null==T?void 0:T.wait){const e=yield T.wait(1);if(C(!0),e.status===at.Success)return"TX"===A.opcode&&m(mt({contractStatus:ee.TxSuccess})),"APPROVAL"===A.opcode&&m(mt({contractStatus:ee.ApproveSuccess})),b&&b(v),n&&n(v,A),p((e=>e.set(v,[O,ot.Success]))),st.Success}return C(!0),p((e=>e.set(v,[O,ot.Failed]))),st.Failed}))),[o,r,d,s]),A=a.useMemo((()=>({execute:T,requests:u,setShowing:y,waitingSubmit:l})),[T,u,y]),O=a.useCallback((()=>{y(null),w&&(w(),j(void 0))}),[w]);return{showing:b,showingDone:v,transactionTx:x,errorMessage:h,setErrorMessage:f,closeShowing:O,ctxVal:A,requests:u}}function ft(){const{requests:e}=gt(),t=[];return null==e||e.forEach((function([e,n]){n===ot.Running&&t.push(e)})),{runningRequests:t,isInflight:t.length>0}}const xt=a.createContext({execute:()=>Promise.resolve(st.Canceled),requests:void 0,waitingSubmit:!1});function gt(){return a.useContext(xt)}var bt;function yt(){return yt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},yt.apply(this,arguments)}var vt=function(e){return S.createElement("svg",yt({width:"33px",height:"33px",viewBox:"0 0 33 33",xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink"},e),bt||(bt=S.createElement("g",{stroke:"none",strokeWidth:1,fill:"none",fillRule:"evenodd",strokeLinecap:"round",strokeLinejoin:"round"},S.createElement("g",{transform:"translate(-186.000000, -375.000000)",stroke:"currentColor",strokeWidth:4},S.createElement("g",{transform:"translate(18.000000, 291.000000)"},S.createElement("g",{transform:"translate(40.000000, 83.000000)"},S.createElement("path",{d:"M159,32 C159,15.9837423 146.016258,3 130,3"})))))))};function Et({showingDone:e,errorMessage:t}){return t?v.jsx(o.Box,{component:r.ErrorWarn,sx:{width:64,height:64,color:"error.main"}}):e?v.jsx(o.Box,{component:r.DoneBorder,sx:{width:64,height:64,color:"success.main"}}):v.jsx(o.Box,{sx:{mx:"auto",border:e=>{var t;return`6px solid ${null===(t=e.palette)||void 0===t?void 0:t.background.input}`},borderRadius:"50%",width:"64px",height:"64px",position:"relative",animation:"loadingRotate 1.1s infinite linear","@keyframes loadingRotate":{"0%":{transform:"rotate(0deg)"},"100%":{transform:"rotate(359deg)"}}},children:v.jsx(o.Box,{component:vt,sx:{position:"absolute",top:"-6px",right:"-6px",color:"primary.main"}})})}function Ct({showingDone:e,showing:t}){return v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",flexDirection:"column"},children:[v.jsx(o.Box,{sx:{mt:60},children:e?E.i18n._("{0} confirmed",{0:null==t?void 0:t.brief}):E.i18n._("{0} pending",{0:null==t?void 0:t.brief})}),(null==t?void 0:t.subtitle)?v.jsx(o.Box,{sx:{mt:20,typography:"body2"},children:null==t?void 0:t.subtitle}):""]})}function wt({isStarted:t,isEnded:n,tx:s}){const[i,l]=a.useState(0),{chainId:d}=c.useWeb3React(),u=a.useMemo((()=>`https://${q[d||1]}/tx/${s}`),[s,d]),p=a.useMemo((()=>{const e=Math.floor(i/60),t=i%60;return e?`${e}m ${t}s`:`${t}s`}),[i]),m=a.useRef();return a.useEffect((()=>(l(0),m.current=setInterval((()=>{l((e=>e+1))}),1e3),()=>{clearInterval(m.current)})),[t]),a.useEffect((()=>{clearInterval(m.current)}),[n]),v.jsxs(o.Box,{sx:{mt:20,pt:20,display:"flex",justifyContent:"space-between",alignItems:"center",typography:"body2",color:"text.secondary",border:"solid 1px transparent",borderTopColor:"border.main"},children:[v.jsxs(o.Box,{children:[v.jsx(e.Trans,{id:"Transaction Time:"}),p]}),v.jsxs(o.HoverOpacity,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},component:"a",href:u,target:"_blank",rel:"noopener noreferrer",children:[v.jsx(e.Trans,{id:"Tx"}),v.jsx(o.Box,{component:r.ArrowTopRightBorder,sx:{width:16,height:16,ml:6}})]})]})}function jt(t){var{children:n}=t,s=K(t,["children"]);const{ctxVal:a,showing:r,closeShowing:l,showingDone:c,errorMessage:d,transactionTx:u}=ht(s),p=i.useDispatch();return v.jsxs(xt.Provider,{value:a,children:[n,v.jsx(Ge,{open:!!r,onClose:l,children:v.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",justifyContent:"space-between",px:20,pb:20,flex:1,overflowY:"auto"},children:[v.jsxs(o.Box,{children:[v.jsx(o.Box,{sx:{textAlign:"center",pt:60},children:v.jsx(Et,{showingDone:c,errorMessage:d})}),d?v.jsxs(o.Box,{sx:{textAlign:"center",mt:60},children:[v.jsx(o.Box,{children:v.jsx(e.Trans,{id:"Something went wrong."})}),v.jsx(o.Box,{sx:{color:"text.secondary",mt:12,typography:"body2",wordBreak:"break-all"},children:d})]}):v.jsxs(v.Fragment,{children:[v.jsx(Ct,{showingDone:c,showing:r}),v.jsx(wt,{isStarted:!!r,isEnded:c,tx:u})]})]}),v.jsx(o.Button,{fullWidth:!0,size:o.Button.Size.big,onClick:()=>{p(mt({contractStatus:ee.Initial})),l()},sx:{mt:20},children:d?v.jsx(e.Trans,{id:"Dismiss"}):v.jsx(e.Trans,{id:"Close"})})]})})]})}function Tt({token:e,fiatPrice:n}){return{marginAmount:a.useMemo((()=>{var o;const s=null!==(o=null==e?void 0:e.decimals)&&void 0!==o?o:6,a=((e,n,o)=>{const s=new t.BigNumber(e).times(new t.BigNumber(10).pow(n));return o?s:s.dp(0)})(null!=n?new k.default(500).div(n):new k.default(0),s);return(a.lt(new k.default(1).times(new k.default(10).pow(s-3)))?new k.default(0):a).toString(10)}),[null==e?void 0:e.decimals,n])}}function At({width:e,height:t,feeRate:n,rebateTo:o,colorMode:s,apikey:r,defaultChainId:l,defaultToToken:c,defaultFromToken:d}){const u=i.useDispatch();a.useEffect((()=>{s&&u((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_COLOR_MODE",payload:e})})))(s))}),[s]),a.useEffect((()=>{var e;l&&u((e=l,t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_CHAIN_ID",payload:e})}))))}),[l]),a.useEffect((()=>{u(mt({height:t}))}),[t]),a.useEffect((()=>{u(mt({width:e}))}),[e]),a.useEffect((()=>{r&&u(mt({apikey:r}))}),[r]),a.useEffect((()=>{n&&u(mt({feeRate:n}))}),[n]),a.useEffect((()=>{o&&u(mt({rebateTo:o}))}),[o]),a.useEffect((()=>{d&&u((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_DEFAULT_FROM_TOKEN",payload:e})})))(d))}),[d]),a.useEffect((()=>{c&&u((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_DEFAULT_TO_TOKEN",payload:e})})))(c))}),[c])}function Ot({refetch:e,interval:t}){let n;a.useEffect((()=>(e(),clearTimeout(n),n=setInterval((()=>{e()}),null!=t?t:15e3),()=>clearTimeout(n))),[e])}function Bt({fromToken:e,toToken:t,chainId:n}){const[o,s]=a.useState(!1),[i,r]=a.useState(""),[l,c]=a.useState(""),d=a.useCallback((()=>{if(!n||!e||!t)return;s(!0);const o=[e,t];I.default.post("https://api.dodoex.io/price-api/api/v1/price/current/batch",{networks:o.map((()=>(e=>V[e]||V[W.MAINNET])(n))),addresses:o.map((e=>e.address)),symbols:o.map((e=>e.symbol)),isCache:!0},{headers:{apikey:"dodofrontend777888ofopensource"}}).then((n=>{var o;s(!1);const a=null===(o=n.data)||void 0===o?void 0:o.data;a&&(r(a.find((t=>t.address===e.address)).price),c(a.find((e=>e.address===t.address)).price))})).catch((e=>{s(!1),console.error(e)}))}),[n,e,t]);return Ot({refetch:d}),{loading:o,refetch:d,toFiatPrice:l,fromFiatPrice:i}}const kt=e=>(null!=e?e:ie.getState()).settings.slippage,St=e=>(null!=e?e:ie.getState()).settings.ddl;var Rt;function It({toToken:e,fromToken:t,fromAmount:n,toAmount:o,marginAmount:s}){const{account:r,chainId:l,provider:d}=c.useWeb3React(),u=i.useSelector(re),p=a.useMemo((()=>l||u),[l,u]),m=i.useSelector(kt)||3,h=i.useSelector(St)||20,{feeRate:f,rebateTo:x,apikey:g,isReverseRouting:b}=i.useSelector(Ye),y=a.useMemo((()=>Math.floor(Date.now()/1e3)+60*h),[h]),[v,C]=a.useState(Rt.Initial),[w,j]=a.useState(null),[A,O]=a.useState(""),[B,k]=a.useState(null),[S,R]=a.useState(null),[D,L]=a.useState(null),[N,M]=a.useState(T.BigNumber.from(0)),[_,P]=a.useState(null),[F,U]=a.useState(null),[W,H]=a.useState(""),[$,z]=a.useState(""),[V,q]=a.useState(""),[K,Y]=a.useState(0),X=a.useCallback((()=>G(this,void 0,void 0,(function*(){if(!p||!t||!e)return;if(!b&&!n)return;if(b&&!o)return;C(Rt.Loading);const s={chainId:p,deadLine:y,apikey:g,slippage:m,source:"dodoV2AndMixWasm",toTokenAddress:e.address,toTokenDecimals:e.decimals,fromTokenAddress:t.address,fromTokenDecimals:t.decimals,userAddr:r||"0x0000000000000000000000000000000000000000"};b?s.toAmount=T.parseFixed(String(o||1),e.decimals).toString():s.fromAmount=T.parseFixed(String(n||1),t.decimals).toString(),x&&f&&(s.rebateTo=x,s.fee=f);try{const e=(yield I.default.get("https://api.dodoex.io/route-service/v2/widget/getdodoroute",{params:s})).data.data;if((null==e?void 0:e.resAmount)?(C(Rt.Success),j(e.resAmount),L(e.priceImpact),P(e.resPricePerFromToken),U(e.resPricePerToToken),k(e.baseFeeAmount),R(e.additionalFeeAmount),H(e.to),z(e.data),O(e.value),q(e.useSource),Y(e.duration)):C(Rt.Failed),!r||!d)return;const t=yield lt({from:r,to:e.to,value:e.value,data:e.data},d);t&&M(t)}catch(e){C(Rt.Failed),console.error(e)}}))),[y,r,p,e,f,m,x,t,d,n,o,g,b]);Ot({refetch:X});const Z=a.useMemo((()=>{const e=b?o:n;return v!==Rt.Loading&&e?w:null}),[v,b,o,n,w]),Q=function(){const{chainId:e,account:t}=c.useWeb3React(),n=gt();return a.useCallback((({to:e,data:o,useSource:s,duration:a,ddl:i,gasLimit:r,subtitle:l,value:c})=>{const d=60*i,u=c;s&&"weth"!==s.toLowerCase()&&r&&r.lt(3e4)&&console.debug("Warning: GasLimit less than the minimum!");const p={from:t,to:e,data:o,value:u,route:s,duration:a,ddlSecRel:d,gasLimit:r};n.execute(E.i18n._("Swap"),Object.assign({opcode:dt.TX},p),l)}),[t,e])}(),J=a.useCallback((e=>{t&&(b?w:n)&&Q({to:W,data:$,useSource:V,duration:K,ddl:h,value:A,subtitle:e})}),[W,h,$,K,V,t,n,N,w,A,b]);return{status:v,refetch:X,priceImpact:D,executeSwap:J,baseFeeAmount:B,resAmount:Z,additionalFeeAmount:S,resPricePerToToken:F,resPricePerFromToken:_}}!function(e){e.Initial="Initial",e.Loading="Loading",e.Failed="Failed",e.Success="Success"}(Rt||(Rt={}));function Dt(e){De(e),be(),ye();const{provider:t,connector:n}=c.useWeb3React();a.useEffect((()=>{const t=e.defaultChainId||1;(null==n?void 0:n.connectEagerly)?n.connectEagerly(t):n.activate(t)}),[n]),a.useEffect((()=>{const e=null==t?void 0:t.provider;e&&e.once&&e.once("chainChanged",(()=>{setTimeout((()=>{window.location.reload()}),200||100)}))}),[t]);const s=e.width||375,i=e.height||494;return At(Object.assign(Object.assign({},e),{width:s,height:i})),v.jsx(o.Box,{sx:{width:s,height:i,overflow:"hidden",position:"relative",display:"flex",flexDirection:"column",minWidth:335,minHeight:494,borderRadius:16,backgroundColor:"background.paper"},className:"dodo-widget-container",children:v.jsx(jt,{...e,children:e.children})})}function Lt(e){const t=o.createTheme({mode:e.colorMode,theme:e.theme,lang:e.locale||"en-US"}),n=a.useMemo((()=>e.defaultChainId||1),[e.defaultChainId]),s=Re({provider:e.provider,jsonRpcUrlMap:e.jsonRpcUrlMap,defaultChainId:n}),r=`${s.length}+${e.jsonRpcUrlMap?Object.entries(e.jsonRpcUrlMap):""}+${e.defaultChainId}+${n}`;return v.jsx(i.Provider,{store:ie,children:v.jsx(nt,{locale:e.locale,children:v.jsx(o.ThemeProvider,{theme:t,children:v.jsxs(c.Web3ReactProvider,{connectors:s,children:[v.jsx(o.CssBaseline,{container:".dodo-widget-container"}),v.jsx(Dt,{...e})]},r)})})})}function Nt(e){const{width:t}=i.useSelector(Ye),n=a.useMemo((()=>{let e="";return"number"==typeof t?e=`${t}px`:t&&(e=t),e?`calc(${e} - 40px)`:"auto"}),[t]);return v.jsx(o.QuestionTooltip,{container:document.querySelector(".dodo-widget-container"),maxWidth:n,...e})}function Mt({onClick:e}){const t=o.useTheme();return v.jsx(o.HoverOpacity,{sx:{width:"100%",position:"relative"},onClick:e,children:v.jsx(o.Box,{component:o.BaseButton,sx:{width:36,height:36,borderRadius:"50%",backgroundColor:t.palette.background.input,border:`4px solid ${t.palette.background.paper}`,display:"flex",alignItems:"center",justifyContent:"center",position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -50%) rotate(-90deg)"},children:v.jsx(o.Box,{component:r.ArrowBack,sx:{width:18,color:"text.secondary"}})})})}function _t({open:t,execute:n,onClose:s,toToken:l,fromToken:c,fromAmount:d,toAmount:u,priceImpact:p,clearFromAmt:m,clearToAmt:h,baseFeeAmount:f,curToFiatPrice:x,curFromFiatPrice:g,pricePerFromToken:b,additionalFeeAmount:y}){var E,C;const w=o.useTheme(),j=i.useSelector(kt),T=i.useDispatch(),{contractStatus:A}=i.useSelector(Ye),O=a.useMemo((()=>new k.default(p).gt(15)),[p]),[B,S]=a.useState(!1),[R,I]=a.useState(!1);return a.useEffect((()=>{A!==ee.Pending&&s(),A===ee.TxSuccess&&(h(),m())}),[A]),a.useEffect((()=>{S(!1)}),[x]),v.jsx(Ge,{open:t,onClose:()=>{T(mt({contractStatus:ee.Initial})),s()},title:v.jsx(e.Trans,{id:"Swap summary"}),children:v.jsxs(o.Box,{sx:{margin:20,display:"flex",height:"100%",flexDirection:"column",borderTop:`1px solid ${w.palette.border.main}`},children:[v.jsxs(o.Box,{sx:{py:20,display:"flex",typography:"body2",alignItems:"center",justifyContent:"center",flexDirection:"column",borderBottom:`1px solid ${w.palette.border.main}`},children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsxs(o.Box,{children:[v.jsxs(o.Box,{sx:{display:"flex"},children:[v.jsx(ze,{width:16,height:16,address:null!==(E=null==c?void 0:c.address)&&void 0!==E?E:"",marginRight:6}),v.jsx(o.Box,{children:`${L({input:d,decimals:null==c?void 0:c.decimals})} ${null==c?void 0:c.symbol}`})]}),v.jsx(o.Box,{sx:{mt:4,typography:"h6",color:w.palette.text.secondary},children:g?`$${D({input:g,showDecimals:1})}`:"-"})]}),v.jsx(o.Box,{sx:{width:16,mx:16},component:r.DoubleRight}),v.jsxs(o.Box,{children:[v.jsxs(o.Box,{sx:{display:"flex"},children:[v.jsx(ze,{width:16,height:16,marginRight:6,address:null!==(C=null==l?void 0:l.address)&&void 0!==C?C:""}),v.jsx(o.Box,{children:`${L({input:u,decimals:null==l?void 0:l.decimals})} ${null==l?void 0:l.symbol}`})]}),v.jsx(o.Box,{sx:{typography:"h6",mt:4,color:w.palette.text.secondary},children:x?`$${D({input:x,showDecimals:1})}(${p}%)`:"-"})]})]}),v.jsx(o.Box,{sx:{mt:12,typography:"h6"},children:`1 ${null==c?void 0:c.symbol} = ${L({input:new k.default(u).dividedBy(new k.default(d)),decimals:null==l?void 0:l.decimals})} ${null==l?void 0:l.symbol}`})]}),v.jsxs(o.Box,{sx:{py:15,typography:"body2",borderBottom:`1px solid ${w.palette.border.main}`},children:[v.jsxs(o.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",color:w.palette.text.secondary},children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(o.Box,{sx:{width:16,mr:7},component:r.DetailBorder}),v.jsx(e.Trans,{id:"Swap Detail"})]}),v.jsx(o.Box,{component:o.BaseButton,children:v.jsx(o.Box,{onClick:()=>I(!R),sx:{width:10,color:"text.secondary",transform:R?"rotateX(0deg)":"rotateX(180deg)"},component:r.CaretUp})})]}),v.jsxs(o.Box,{sx:{mt:16,display:R?"initial":"none"},children:[v.jsxs(o.Box,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(e.Trans,{id:"Basic Fee"}),v.jsx(Nt,{title:v.jsx(e.Trans,{id:"Estimated service provider fees"}),ml:5})]}),v.jsx(o.Box,{children:`${L({input:f,decimals:null==l?void 0:l.decimals})} ${null==l?void 0:l.symbol}`})]}),v.jsxs(o.Box,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(e.Trans,{id:"Additional Fee"}),v.jsx(Nt,{title:v.jsx(e.Trans,{id:"Additional routing fees set by the Widget user"}),ml:5})]}),v.jsx(o.Box,{children:`${L({input:y,decimals:null==l?void 0:l.decimals})} ${null==l?void 0:l.symbol}`})]}),v.jsxs(o.Box,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(e.Trans,{id:"Price Impact"}),v.jsx(Nt,{title:v.jsx(e.Trans,{id:"Due to the market condition, market price and estimated price may have a slight difference"}),ml:5})]}),v.jsx(o.Box,{children:`${p}%`})]}),v.jsxs(o.Box,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(e.Trans,{id:"Slippage"}),v.jsx(Nt,{title:v.jsx(e.Trans,{id:"High slippage tolerance will increase the success rate of transaction, but might not get the best quote."}),ml:5})]}),v.jsx(o.Box,{children:j})]})]})]}),v.jsx(o.Box,{sx:{flex:1}}),O&&v.jsxs(o.Box,{sx:{mb:14,display:"flex",cursor:"pointer",justifyContent:"center",alignItems:"center",typography:"h6"},onClick:()=>S(!B),children:[v.jsx(o.Box,{sx:{mr:4,width:18,height:18,alignItems:"center"},children:B?v.jsx(o.Box,{sx:{width:"100%",height:"100%",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"secondary.main"},children:v.jsx(o.Box,{component:r.Done,sx:{width:14,color:"#1a1a1b"}})}):v.jsx(o.Box,{sx:{width:"100%",height:"100%",borderRadius:4,border:`1px solid ${w.palette.text.secondary}`}})}),v.jsx(o.Box,{children:v.jsx(e.Trans,{components:{0:v.jsx(o.Box,{component:"span",sx:{color:"error.main"}})},values:{priceImpact:p},id:"Price impact reaches <0>{priceImpact}</0>%, accept the quote"})})]}),v.jsx(o.Button,{isLoading:A==ee.Pending,disabled:O&&!B,fullWidth:!0,onClick:()=>{n(),T(mt({contractStatus:ee.Pending}))},children:A==ee.Pending?v.jsx(e.Trans,{id:"Confirming"}):v.jsx(e.Trans,{id:"Confirm swap"})})]})})}function Pt(e){var{sx:n,maxVal:s,decimals:a=2,onInputChange:i}=e,r=K(e,["sx","maxVal","decimals","onInputChange"]);return o.useTheme(),v.jsx(o.Input,{...r,onChange:e=>{const n=0===e.target.value.length?null:_(e.target.value,a),o=s&&n&&new t.BigNumber(n).gt(s)?s.toString():n;console.log("finalVal:",o),i&&i(o)}})}function Ft({open:t,onClose:n}){const s=o.useTheme(),r=i.useDispatch(),l=i.useSelector(kt),c=i.useSelector(St),d=a.useMemo((()=>Number(l)>=50),[l]);return v.jsx(Ge,{open:t,onClose:n,title:v.jsx(e.Trans,{id:"Settings"}),children:v.jsxs(o.Box,{sx:{mx:20},children:[v.jsxs(o.Box,{sx:{py:20,borderTop:`1px solid ${s.palette.border.main}`},children:[v.jsxs(o.Box,{sx:{mb:16,display:"flex",alignItems:"center"},children:[v.jsx(e.Trans,{id:"Slippage Tolerance"}),v.jsx(Nt,{title:v.jsx(e.Trans,{id:"Attention: High slippage tolerance will increase the success rate of transaction, but might not get the best quote."}),ml:7})]}),v.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column"},children:[v.jsx(Pt,{fullWidth:!0,maxVal:100,value:l,placeholder:3..toString(),onInputChange:e=>{r((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_SLIPPAGE",payload:e})})))(e))},suffix:v.jsx(o.Box,{sx:{color:"text.disabled"},children:"%"}),height:36}),d&&v.jsx(o.Box,{sx:{typography:"h6",mt:6,color:"error.main"},children:v.jsx(e.Trans,{id:"Maximum slippage do not exceed 50%"})})]})]}),v.jsxs(o.Box,{sx:{py:20,borderTop:`1px solid ${s.palette.border.main}`},children:[v.jsxs(o.Box,{sx:{mb:16,display:"flex",alignItems:"center"},children:[v.jsx(e.Trans,{id:"Transaction Deadline"}),v.jsx(Nt,{title:v.jsx(e.Trans,{id:"If your transaction time exceeds the deadline, your transaction will be rescinded."}),ml:7})]}),v.jsx(Pt,{value:c,fullWidth:!0,height:36,placeholder:E.i18n._("{DEFAULT_SWAP_DDL} minutes",{DEFAULT_SWAP_DDL:20}),onInputChange:e=>{r((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_TRANSACTION_DDL",payload:e})})))(e?Math.max(Number(e),1):""))}})]})]})})}function Ut({toToken:t,fromToken:n,priceStatus:s,pricePerToToken:i,pricePerFromToken:l}){const[c,d]=a.useState("-"),[u,p]=a.useState(null),[m,h]=a.useState("-"),[f,x]=a.useState(null);a.useEffect((()=>{d(null==n?void 0:n.symbol),h(null==t?void 0:t.symbol),p(i),x(l)}),[n,t,i,l]);const g=a.useCallback((()=>{d(m),h(c),p(f),x(u)}),[c,u,m,f]);return v.jsx(o.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center"},children:{[Rt.Initial]:"-",[Rt.Loading]:v.jsxs(v.Fragment,{children:[v.jsx(o.RotatingIcon,{sx:{mr:5}}),v.jsx(e.Trans,{id:"Fetching best price..."})]}),[Rt.Failed]:v.jsxs(v.Fragment,{children:[v.jsx(o.Box,{component:r.Warn,sx:{width:15,mr:5,color:"warning.main"}}),v.jsx(e.Trans,{id:"Quote not available"})]}),[Rt.Success]:v.jsxs(v.Fragment,{children:[v.jsx(o.Box,{sx:{typography:"body2"},children:`1 ${c} = ${D({input:f,showDecimals:4})} ${m}`}),v.jsx(o.Box,{component:o.BaseButton,sx:{width:18,height:18,ml:6,borderRadius:"50%",backgroundColor:"border.main",display:"flex",justifyContent:"center",alignItems:"center"},children:v.jsx(o.Box,{sx:{width:16,color:"text.secondary"},onClick:g,component:r.Switch})})]})}[s]})}function Wt({open:t,onClose:n}){const s=i.useSelector(re);return v.jsx(Ge,{title:v.jsx(e.Trans,{id:"Connect to your wallet"}),open:t,onClose:n,children:v.jsx(o.Box,{sx:{mx:20,pb:20,border:"1px solid transparent",borderTopColor:"border.main"},children:Object.values(ke).map((t=>v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",flexDirection:"column",mt:20,p:20,backgroundColor:"background.tag",borderRadius:12,cursor:"pointer","&:hover":{backgroundColor:"hover.default"}},onClick:()=>{!function(e,t,n){var o;const s=Se[e];if(!s)throw new Error(`Unknown wallet type: ${e}`);const[a]=s;null===(o=a.activate(t))||void 0===o||o.catch((e=>{4001!==e.code?n(e):a.connectEagerly?a.connectEagerly(t):a.activate(t)}))}(t.type,s,(e=>{console.error(e)}))},children:[v.jsx(o.Box,{component:t.icon,sx:{width:32,height:32}}),v.jsx(o.Box,{sx:{mt:8,typography:"caption"},children:t.name}),v.jsx(o.Box,{sx:{mt:4,typography:"body2",color:"text.secondary"},children:v.jsx(e.Trans,{id:"Connect to your {0} Wallet",values:{0:t.name}})})]},t.type)))})})}function Ht(){const{connector:t}=c.useWeb3React(),[n,s]=a.useState(!1);return v.jsxs(v.Fragment,{children:[v.jsx(o.Button,{size:o.Button.Size.big,fullWidth:!0,onClick:()=>{t.deactivate?t.deactivate():t.resetState(),s(!0)},"data-testid":"connect-wallet-btn",children:v.jsx(e.Trans,{id:"Connect to a wallet"})}),v.jsx(Wt,{open:n,onClose:()=>s(!1)})]})}var $t;!function(e){e.Loading="Loading",e.Insufficient="ApprovalInsufficient",e.Approving="Approving",e.Sufficient="Sufficient",e.Unchecked="Unchecked"}($t||($t={}));const zt=({account:e,chainId:t,offset:n,contractAddress:o})=>{var s;const r=i.useSelector(re),l=a.useMemo((()=>{var e;return pe[null!==(e=t)&&void 0!==e?e:r]}),[t]),{isETH:d}=a.useMemo((()=>U(t)),[t]),{DODO_APPROVE:u}=l||{},p=null!==(s=null!=o?o:u)&&void 0!==s?s:null,m=function(e){const{account:t}=c.useWeb3React(),n=i.useSelector(re),o=i.useSelector(Ne),s=a.useMemo((()=>z[n]),[n]),r=a.useCallback((n=>{var a;if(!t||!e)return null;if(n.symbol===s.symbol&&P(n.address,s.address))return new k.default(pt);const i=null===(a=null==o?void 0:o[n.address.toLowerCase()])||void 0===a?void 0:a.tokenAllowances;return null!=i?i:null}),[t,e,s.symbol,s.address,o]);return r}(p),h=Ue(),{runningRequests:f}=ft(),x=i.useSelector(Fe),g=a.useMemo((()=>{var e;return null===(e=z[null!=t?t:r])||void 0===e?void 0:e.address}),[t]),b=a.useCallback(((t,o,s)=>{if(!t)return $t.Loading;const a=!!(null==f?void 0:f.find((e=>e.spec.opcode===dt.Approval&&e.spec.token.address===(null==t?void 0:t.address)))),i=null!=s?s:t?h(t):null,r=t?m(t):null,l=new k.default(null!=o?o:0);if(!e)return $t.Unchecked;if(!i||l.minus(null!=n?n:0).gt(i))return $t.Unchecked;if(l.isZero())return $t.Unchecked;return t.address===g?$t.Sufficient:a?$t.Approving:r&&l.minus(null!=n?n:0).gt(r)?$t.Insufficient:$t.Sufficient}),[h,m,e,n,p,t,x,f,g]),y=a.useCallback((e=>{const t=e?m(e):null;return("USDT"===(null==e?void 0:e.symbol)||(null==e?void 0:e.address.toLowerCase())==="0x6426e6017968377529487E0ef0aA4E7759724e05".toLowerCase())&&null!==t&&t.gt(0)}),[m]),v=gt(),C=i.useDispatch(),w=a.useCallback(((t,n)=>G(void 0,void 0,void 0,(function*(){if(!p||!e||!t)return;const o=(e=>{let t=e.symbol;return t.indexOf("DLP_")>-1&&(t=t.replace("DLP_","")),t.indexOf("DLP")>-1&&(t=t.replace("DLP","LP")),t})(t),s=n?new k.default(0):void 0,a=n?E.i18n._("Reset"):E.i18n._("Approve");var i;(yield v.execute(`${a} ${o}`,{opcode:dt.Approval,token:t,contract:p,amt:s}))===st.Success&&C((i=null!=s?s:pt,e=>G(void 0,void 0,void 0,(function*(){e({type:"SET_ACCOUNT_ALLOWANCES",payload:i})}))))}))),[p,e,t,v,C]),j=a.useCallback((e=>{const t=new k.default(0);if(!e)return t.toNumber();const n=h(e);if(!n)return t.toNumber();let o=n;const s=d?.1:.02;return g===(null==e?void 0:e.address)&&(o=n.gt(s)?n.minus(s):t),o.toNumber()}),[t,h,d]);return{getApprovalState:b,getPendingRest:y,getMaxBalance:j,submitApprove:w}};function Vt(){var t,s;const l=o.useTheme(),{isInflight:d}=ft(),{chainId:u,account:p}=c.useWeb3React(),m=i.useDispatch(),{isReverseRouting:h}=i.useSelector(Ye),f=i.useSelector(re),x=i.useSelector(Pe),g=i.useSelector(_e),{isETH:b}=a.useMemo((()=>U(u)),[u]),y=a.useMemo((()=>{var e;return null===(e=z[null!=u?u:f])||void 0===e?void 0:e.address}),[u]),[E,C]=a.useState(""),[w,j]=a.useState(""),[T,A]=a.useState(""),[O,B]=a.useState(""),S=a.useMemo((()=>n.debounce((e=>A(e)),1e3)),[]),R=a.useMemo((()=>n.debounce((e=>B(e)),1e3)),[]),[I,N]=a.useState(null),[M,_]=a.useState(null),[P,F]=a.useState(!1),[H,$]=a.useState(!1),{toFiatPrice:V,fromFiatPrice:q}=Bt({chainId:u,toToken:M,fromToken:I}),K=Ue(),G=a.useMemo((()=>I?K(I):null),[I,K]);a.useMemo((()=>M?K(M):null),[M,K]);const{getApprovalState:Y,submitApprove:X,getPendingRest:Z,getMaxBalance:Q}=zt({account:p,chainId:u}),J=a.useMemo((()=>Z(h?M:I)),[null==I?void 0:I.address,null==M?void 0:M.address,Z,h]),{marginAmount:ee}=Tt({token:h?M:I,fiatPrice:h?V:q}),{resAmount:te,priceImpact:ne,executeSwap:oe,baseFeeAmount:se,additionalFeeAmount:ae,resPricePerToToken:ie,resPricePerFromToken:le,status:ce}=It({toToken:M,fromToken:I,marginAmount:ee,fromAmount:T,toAmount:O}),de=a.useCallback((e=>{const t=e.toString();C(t),S(t)}),[C,S]),ue=a.useCallback((e=>{const t=e.toString();j(t),R(t)}),[j,R]);a.useEffect((()=>{u&&(_(null),N(null),h?ue(""):de("")),g&&g.chainId===u&&(N(g),g.amount&&(m(mt({isReverseRouting:!1})),de(g.amount))),x&&x.chainId===u&&(_(x),x.amount&&g&&!g.amount&&(m(mt({isReverseRouting:!0})),ue(x.amount)))}),[x,g,u,de,ue]);const pe=a.useCallback((()=>{de(""),ue(""),N(M),_(I)}),[N,M,_,I,de,ue]),me=a.useCallback((e=>h?ue(Q(M)):de(Q(I))),[de,ue,Q,I,M,h]),he=a.useMemo((()=>(100*Number(ne)).toFixed(2)),[ne]),fe=a.useMemo((()=>{const e=h?te:T;return e&&q?new k.default(q).multipliedBy(e):null}),[q,T,h,te]),xe=a.useMemo((()=>{const e=h?O:te;return e&&V?new k.default(V).multipliedBy(e):null}),[V,O,h,te]),ge=a.useMemo((()=>v.jsxs(o.Box,{sx:{display:"flex",fontWeight:600,typography:"body2",alignItems:"center",justifyContent:"center"},children:[v.jsx(Nt,{title:v.jsx(e.Trans,{id:"Due to the market condition, market price and estimated price may have a slight difference"}),mr:8}),v.jsxs(o.Box,{sx:{display:"flex"},children:[v.jsx(e.Trans,{id:"Current price impact"}),v.jsxs(o.Box,{sx:{color:l.palette.error.main,ml:4},children:[he,"%"]})]})]})),[he]),be=a.useMemo((()=>v.jsx(Ut,{toToken:M,fromToken:I,priceStatus:ce,pricePerToToken:ie,pricePerFromToken:le})),[M,I,ce,ie,le]),ye=a.useMemo((()=>!W[u||1]),[u]),ve=a.useMemo((()=>ce===Rt.Loading?v.jsx(o.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center"},children:v.jsxs(v.Fragment,{children:[v.jsx(o.RotatingIcon,{sx:{mr:5}}),v.jsx(e.Trans,{id:"Fetching best price..."})]})}):ye?v.jsxs(v.Fragment,{children:[v.jsx(o.Box,{component:r.Warn,sx:{mr:6,width:16,color:"warning.main"}}),v.jsx(e.Trans,{id:"Unsupported network - switch to trade"})]}):E&&new k.default(he).gt(15)?ge:be),[ce,be,E,ge,he,ye]),Ee=a.useMemo((()=>h?new k.default(w).gt(0)?L({input:te,decimals:null==I?void 0:I.decimals}):"-":E),[E,w,te,I,h]),Ce=a.useMemo((()=>h?w:new k.default(E).gt(0)?L({input:te,decimals:null==M?void 0:M.decimals}):"-"),[E,w,te,M,h]),we=a.useMemo((()=>{const t=Y(I,T),n=t===$t.Approving,s=t===$t.Insufficient&&!J,a=b?.1:.02,i=y===(null==I?void 0:I.address),r=new k.default(G||0);return p?d?v.jsx(o.Button,{fullWidth:!0,isLoading:!0,disabled:!0,children:v.jsx(e.Trans,{id:"Transaction Pending"})}):I&&M?s?v.jsx(o.Button,{fullWidth:!0,disabled:n,onClick:()=>X(I),children:n?v.jsx(e.Trans,{id:"Approving"}):v.jsx(e.Trans,{id:"Approve"})}):new k.default(h?O:T).gt(0)?ce===Rt.Loading?v.jsx(o.Button,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-fetch-price-btn",children:v.jsx(e.Trans,{id:"Fetching Price..."})}):te?r.lt(h?te:T)||i&&r.lte(a)?v.jsx(o.Button,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-insufficient-balance-btn",children:v.jsx(e.Trans,{id:"Insufficient balance"})}):v.jsx(o.Button,{fullWidth:!0,onClick:()=>F(!0),"data-testid":"swap-review-btn",children:v.jsx(e.Trans,{id:"Review Swap"})}):v.jsx(o.Button,{fullWidth:!0,disabled:!0,children:v.jsx(e.Trans,{id:"Quote not available"})}):v.jsx(o.Button,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-enter-amount-btn",children:v.jsx(e.Trans,{id:"Enter an amount"})}):v.jsx(o.Button,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-select-token-btn",children:v.jsx(e.Trans,{id:"Select Tokens"})}):v.jsx(Ht,{})}),[b,p,O,T,M,te,I,d,oe,J,X,ce,G,Y,y,h]),je=a.useMemo((()=>I&&M?v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(ze,{token:I,sx:{width:16,height:16,mr:6}}),`${L({input:h?te:T,decimals:null==I?void 0:I.decimals})} ${I.symbol}`,v.jsx(o.Box,{component:r.DoubleRight,sx:{width:12,height:12,mx:16}}),v.jsx(ze,{token:M,sx:{width:16,height:16,mr:6}}),`${L({input:h?O:te,decimals:null==M?void 0:M.decimals})} ${M.symbol}`]}):v.jsx(o.Box,{})),[I,M,T,O,te,h]);return v.jsxs(v.Fragment,{children:[v.jsxs(o.Box,{sx:{display:"flex",justifyContent:"space-between",typography:"caption",margin:20},children:[v.jsx(e.Trans,{id:"Swap"}),v.jsx(o.Box,{component:o.BaseButton,children:v.jsx(o.Box,{component:r.Setting,onClick:()=>$(!0),sx:{width:19,height:19,color:"text.primary",cursor:"pointer"}})})]}),v.jsxs(o.Box,{sx:{flex:1,padding:"0 20px 20px",overflowY:"auto"},children:[v.jsxs(o.Box,{children:[v.jsx(et,{sx:{mb:4},token:I,amt:Ee,onMaxClick:me,onInputChange:de,onInputFocus:()=>{h&&de(""),m(mt({isReverseRouting:!1}))},showMaxBtn:!h&&!E,occupiedAddrs:[null!==(t=null==M?void 0:M.address)&&void 0!==t?t:""],fiatPriceTxt:fe?`$${D({input:fe,showDecimals:1})}`:"-",onTokenChange:(e,t)=>{if(t)return pe();de(""),ue(""),N(e)},readOnly:h}),v.jsx(Mt,{onClick:pe}),v.jsx(et,{token:M,amt:Ce,onInputChange:ue,onInputFocus:()=>{h||ue(""),m(mt({isReverseRouting:!0}))},occupiedAddrs:[null!==(s=null==I?void 0:I.address)&&void 0!==s?s:""],fiatPriceTxt:xe?`$${D({input:xe,showDecimals:1})}(${he}%)`:"-",onTokenChange:(e,t)=>{if(t)return pe();de(""),ue(""),_(e)},readOnly:!h}),v.jsx(o.Box,{sx:{py:12,display:"flex",typography:"body2",alignItems:"center",justifyContent:"center",flexWrap:"wrap"},children:ve})]}),we,v.jsxs(o.Box,{sx:{mt:13,display:"flex",typography:"h6",cursor:"pointer",justifyContent:"center",alignItems:"center",color:l.palette.text.disabled},onClick:()=>window.open("https://app.dodoex.io"),children:[v.jsx(o.Box,{sx:{width:24,typography:"body2",transform:"translate(1px, 2px)","& path":{fill:l.palette.text.disabled}},component:r.Dodo}),v.jsx(e.Trans,{id:"Powered by DODO protocol"})]})]}),v.jsx(_t,{toToken:M,fromToken:I,fromAmount:h?te:T,toAmount:h?O:te,open:P,baseFeeAmount:se,priceImpact:he,additionalFeeAmount:ae,curToFiatPrice:xe,execute:()=>oe(je),clearFromAmt:()=>de(""),clearToAmt:()=>ue(""),curFromFiatPrice:fe,pricePerFromToken:le,onClose:()=>F(!1)}),v.jsx(Ft,{open:H,onClose:()=>$(!1)})]})}exports.InitSwapWidget=function(e){const t=document.getElementById("dodo-swap-widget");A.createRoot(t).render(v.jsx(Lt,{...e,children:v.jsx(Vt,{})}))},exports.SwapWidget=function(e){return v.jsx(Lt,{...e,children:v.jsx(Vt,{})})};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@lingui/react"),t=require("bignumber.js"),n=require("lodash"),o=require("@dodoex/components"),s=require("@ethersproject/address"),a=require("react"),i=require("react-redux"),r=require("@dodoex/icons"),l=require("identicon.js"),c=require("@web3-react/core"),d=require("@reduxjs/toolkit"),u=require("redux"),p=require("@ethersproject/contracts"),m=require("@ethersproject/constants"),h=require("@ethersproject/abi"),f=require("@web3-react/eip1193"),x=require("@web3-react/walletconnect"),g=require("@web3-react/metamask"),b=require("@ethersproject/providers"),y=require("@web3-react/types"),v=require("react/jsx-runtime"),E=require("@lingui/core"),C=require("react-window"),w=require("make-plural/plurals"),j=require("axios"),T=require("@ethersproject/bignumber"),A=require("react-dom/client");function O(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function B(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var k=O(t),S=B(a),R=O(l),I=O(j);function D({input:e,showDecimals:n=4,showPrecisionDecimals:o=2,showIntegerOnly:s=!1,showDecimalsOnly:a=!1,noGroupSeparator:i=!1}){const r=new t.BigNumber(e);if(r.isNaN())return"-";let l=r.dp(n,t.BigNumber.ROUND_DOWN);return l.eq(0)&&(r.gt(0)||r.lt(0))&&(l=r.sd(null!=o?o:n,t.BigNumber.ROUND_DOWN)),s&&(l=l.integerValue(t.BigNumber.ROUND_DOWN)),a&&(l=l.minus(l.integerValue(t.BigNumber.ROUND_DOWN))),i?l.toFormat({decimalSeparator:".",groupSeparator:"",groupSize:3,secondaryGroupSize:0,fractionGroupSeparator:"",fractionGroupSize:0}):l.toFormat()}function L({input:e,decimals:n,showPrecisionDecimals:o=2,noGroupSeparator:s}){if(null==e)return"-";const a=new t.BigNumber(e);if(a.isNaN())return"-";return D({input:a,showDecimals:void 0===n?0:n>6?6:n>4?4:n,showPrecisionDecimals:o,noGroupSeparator:s})}function N(e){if("number"==typeof e)return N(new t.BigNumber(e));if(e.isNaN())return"NaN";if(e.isNegative())return`-${N(e.negated())}`;if(e.isZero())return"0";let n=e.integerValue(t.BigNumber.ROUND_FLOOR),o=e.minus(n),s="";for(;!n.isZero();){s=n.modulo(10).toString().toString()+s,n=n.idiv(10)}if(""===s&&(s="0"),o.isZero())return s;s+=".";let a=0;for(;!o.isZero()&&a<100;){const e=o.times(10),n=e.integerValue(t.BigNumber.ROUND_FLOOR);s+=n.toString(),o=e.minus(n),a+=1}return s}const M=(e,n)=>{if("string"==typeof e&&!e.match(/[-+]?\d+(.+d+)?/))return e;const o=new t.BigNumber(e);if(n){let e=o.toFixed(n,t.BigNumber.ROUND_DOWN);return s=e,new t.BigNumber(s).isZero()&&(e=N(o.precision(n,t.BigNumber.ROUND_DOWN))),e}var s;return N(o)},_=(e,t)=>{let n=e;const o=n.match("[0-9。.]+");n=o&&o.length>0?o[0]:"",n=n.replace("。",".");let s=0;if(n){const e=n.split("."),t=0===e[0].length?["0"]:[e[0]];e.length>1?t[1]=e.slice(1,e.length).join(""):t[0].length>1&&"0"===t[0][0]&&(t[0]=t[0].slice(1,t[0].length)),t.length>1&&(s=t[1].length),n=t.join(".")}return t>=0&&s>t?M(n,t):n},P=(e,t)=>{if(0===e.length||0===t.length)return!1;if(t.length===e.length)return e.toLowerCase()===t.toLowerCase();const n=e.substring(2,e.length).toLowerCase(),o=t.substring(2,t.length).toLowerCase();return n.length>o.length?n.endsWith(o):o.endsWith(n)};function F(e){try{return s.getAddress(e)}catch(e){return!1}}const U=e=>{const t={isMainnet:1===e,isRinkeby:4===e,isGor:5===e};return Object.assign(Object.assign({},t),{isETH:t.isMainnet||t.isRinkeby||t.isGor})};var W;!function(e){e[e.MAINNET=1]="MAINNET",e[e.RINKEBY=4]="RINKEBY",e[e.GOERLI=5]="GOERLI",e[e.BSC=56]="BSC",e[e.HECO=128]="HECO",e[e.POLYGON=137]="POLYGON",e[e.ARBITRUM_ONE=42161]="ARBITRUM_ONE",e[e.ARBITRUM_RINKEBY=421611]="ARBITRUM_RINKEBY",e[e.AURORA=1313161554]="AURORA",e[e.MOONRIVER=1285]="MOONRIVER",e[e.OKCHAIN=66]="OKCHAIN",e[e.OPTIMISM=10]="OPTIMISM",e[e.BOBA=288]="BOBA",e[e.AVALANCHE=43114]="AVALANCHE",e[e.CRONOS=25]="CRONOS"}(W||(W={}));const H={[W.MAINNET]:["https://rpc.ankr.com/eth","https://eth-mainnet.public.blastapi.io","https://eth-rpc.gateway.pokt.network","https://main-rpc.linkpool.io"],[W.RINKEBY]:["https://rinkeby-light.eth.linkpool.io/"],[W.GOERLI]:["https://goerli.optimism.io/"],[W.BSC]:["https://bsc-dataseed1.binance.org","https://bsc-dataseed2.binance.org","https://bsc-dataseed3.binance.org","https://bsc-dataseed4.binance.org","https://bsc-dataseed1.defibit.io","https://bsc-dataseed2.defibit.io","https://bsc-dataseed3.defibit.io","https://bsc-dataseed4.defibit.io","https://bsc-dataseed1.ninicoin.io","https://bsc-dataseed2.ninicoin.io","https://bsc-dataseed3.ninicoin.io","https://bsc-dataseed4.ninicoin.io","https://bsc-dataseed.binance.org","https://rpc.ankr.com/bsc","https://bscrpc.com","https://bsc.mytokenpocket.vip","https://binance.nodereal.io","https://rpc-bsc.bnb48.club"],[W.HECO]:["https://http-mainnet.hecochain.com","https://pub001.hg.network/rpc"],[W.POLYGON]:["https://polygon-rpc.com","https://rpc-mainnet.matic.network","https://matic-mainnet.chainstacklabs.com","https://rpc-mainnet.maticvigil.com","https://rpc-mainnet.matic.quiknode.pro","https://matic-mainnet-full-rpc.bwarelabs.com","https://matic-mainnet-archive-rpc.bwarelabs.com","https://poly-rpc.gateway.pokt.network","https://rpc.ankr.com/polygon","https://polygon-mainnet.public.blastapi.io"],[W.ARBITRUM_ONE]:["https://arb1.arbitrum.io/rpc","https://rpc.ankr.com/arbitrum"],[W.ARBITRUM_RINKEBY]:["https://rinkeby.arbitrum.io/rpc"],[W.AURORA]:["https://mainnet.aurora.dev/"],[W.MOONRIVER]:["https://rpc.api.moonriver.moonbeam.network","https://moonriver.api.onfinality.io/rpc?apikey=673e1fae-c9c9-4c7f-a3d5-2121e8274366","https://moonriver.api.onfinality.io/public","https://moonriver.public.blastapi.io"],[W.OKCHAIN]:["https://exchainrpc.okex.org","https://okc-mainnet.gateway.pokt.network/v1/lb/6275309bea1b320039c893ff"],[W.OPTIMISM]:["https://mainnet.optimism.io","https://optimism-mainnet.public.blastapi.io"],[W.BOBA]:["https://mainnet.boba.network","https://boba-mainnet.gateway.pokt.network/v1/lb/623ad21b20354900396fed7f","https://lightning-replica.boba.network"],[W.AVALANCHE]:["https://api.avax.network/ext/bc/C/rpc","https://rpc.ankr.com/avalanche","https://ava-mainnet.public.blastapi.io/ext/bc/C/rpc"],[W.CRONOS]:["https://evm.cronos.org","https://cronos-rpc.heavenswail.one","https://evm-cronos.crypto.org","https://cronosrpc-1.xstaking.sg","https://cronos-rpc.elk.finance"]},$={symbol:"ETH",address:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",name:"Ether",decimals:18,showDecimals:4,wrappedTokenSymbol:"WETH"},z={[W.MAINNET]:Object.assign(Object.assign({},$),{wrappedTokenAddress:"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}),[W.RINKEBY]:Object.assign(Object.assign({},$),{wrappedTokenAddress:"0xB26c0d8Be2960c70641A95A9195BE1f59Ac83aC0"}),[W.GOERLI]:Object.assign(Object.assign({},$),{wrappedTokenAddress:"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6"}),[W.OPTIMISM]:Object.assign(Object.assign({},$),{wrappedTokenAddress:"0x4200000000000000000000000000000000000006"}),[W.CRONOS]:Object.assign(Object.assign({},$),{symbol:"CRO",name:"Cronos",wrappedTokenSymbol:"WCRO",wrappedTokenAddress:"0x5C7F8A570d578ED84E63fdFA7b1eE72dEae1AE23"}),[W.BOBA]:Object.assign(Object.assign({},$),{wrappedTokenAddress:"0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000"}),[W.BSC]:Object.assign(Object.assign({},$),{symbol:"BNB",name:"BNB",wrappedTokenSymbol:"WBNB",wrappedTokenAddress:"0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}),[W.OKCHAIN]:Object.assign(Object.assign({},$),{symbol:"OKT",name:"OKT",wrappedTokenSymbol:"WOKT",wrappedTokenAddress:"0x8F8526dbfd6E38E3D8307702cA8469Bae6C56C15"}),[W.HECO]:Object.assign(Object.assign({},$),{symbol:"HT",name:"HT",showDecimals:6,wrappedTokenSymbol:"WHT",wrappedTokenAddress:"0x5545153ccfca01fbd7dd11c0b23ba694d9509a6f"}),[W.POLYGON]:Object.assign(Object.assign({},$),{symbol:"MATIC",name:"MATIC",showDecimals:6,wrappedTokenSymbol:"WMATIC",wrappedTokenAddress:"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270"}),[W.MOONRIVER]:Object.assign(Object.assign({},$),{symbol:"MOVR",name:"MOVR",showDecimals:6,wrappedTokenSymbol:"WMOVR",wrappedTokenAddress:"0x98878b06940ae243284ca214f92bb71a2b032b8a"}),[W.ARBITRUM_ONE]:Object.assign(Object.assign({},$),{name:"Ethereum",showDecimals:6,wrappedTokenAddress:"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"}),[W.ARBITRUM_RINKEBY]:Object.assign(Object.assign({},$),{name:"Ether",showDecimals:6,wrappedTokenAddress:"0xEBbc3452Cc911591e4F18f3b36727Df45d6bd1f9"}),[W.AURORA]:Object.assign(Object.assign({},$),{name:"Ethereum",showDecimals:6,wrappedTokenAddress:"0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB"}),[W.AVALANCHE]:Object.assign(Object.assign({},$),{symbol:"AVAX",name:"Avalanche",showDecimals:6,wrappedTokenSymbol:"WAVAX",wrappedTokenAddress:"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7"})},V={[W.MAINNET]:"ethereum",[W.RINKEBY]:"rinkeby",[W.GOERLI]:"goerli",[W.OPTIMISM]:"optimism",[W.CRONOS]:"cronos",[W.BOBA]:"boba",[W.BSC]:"bsc",[W.OKCHAIN]:"okex-chain",[W.HECO]:"heco",[W.POLYGON]:"polygon",[W.MOONRIVER]:"moonriver",[W.ARBITRUM_ONE]:"arbitrum",[W.ARBITRUM_RINKEBY]:"arb-rinkeby",[W.AURORA]:"aurora",[W.AVALANCHE]:"avalanche"},q={[W.MAINNET]:"etherscan.io",[W.RINKEBY]:"rinkeby.etherscan.io",[W.GOERLI]:"goerli.etherscan.io",[W.OPTIMISM]:"optimistic.etherscan.io",[W.CRONOS]:"cronoscan.com",[W.BOBA]:"blockexplorer.boba.network",[W.BSC]:"bscscan.com",[W.OKCHAIN]:"www.oklink.com/okexchain",[W.HECO]:"hecoinfo.com",[W.POLYGON]:"polygonscan.com",[W.MOONRIVER]:"moonriver.moonscan.io",[W.ARBITRUM_ONE]:"arbiscan.io",[W.ARBITRUM_RINKEBY]:"testnet.arbiscan.io",[W.AURORA]:"aurorascan.dev",[W.AVALANCHE]:"snowtrace.io"};function K(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(o=Object.getOwnPropertySymbols(e);s<o.length;s++)t.indexOf(o[s])<0&&Object.prototype.propertyIsEnumerable.call(e,o[s])&&(n[o[s]]=e[o[s]])}return n}function G(e,t,n,o){return new(n||(n=Promise))((function(s,a){function i(e){try{l(o.next(e))}catch(e){a(e)}}function r(e){try{l(o.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,r)}l((o=o.apply(e,t||[])).next())}))}const Y={colorMode:"dark",slippage:3..toString(),ddl:20};var X=(e=Y,t)=>{switch(t.type){case"SET_COLOR_MODE":return Object.assign(Object.assign({},e),{colorMode:t.payload});case"SET_SLIPPAGE":return Object.assign(Object.assign({},e),{slippage:t.payload});case"SET_TRANSACTION_DDL":return Object.assign(Object.assign({},e),{ddl:t.payload});default:return e}};const Z={chainId:W.MAINNET,latestBlockNumber:0};var Q=(e=Z,t)=>{switch(t.type){case"SET_CHAIN_ID":return Object.assign(Object.assign({},e),{chainId:t.payload});case"SET_BLOCK_NUMBER":return Object.assign(Object.assign({},e),{latestBlockNumber:t.payload});default:return e}};const J={tokenList:[],popularTokenList:[],ethBalance:void 0,accountBalances:{},balanceLoadings:{},slippageWithTokens:[]};var ee,te=(e=J,t)=>{switch(t.type){case"SET_TOKEN_LIST":return Object.assign(Object.assign({},e),{tokenList:t.payload});case"SET_POPULAR_TOKEN_LIST":return Object.assign(Object.assign({},e),{popularTokenList:t.payload});case"SET_SLIPPAGE_WITH_TOKENS":return Object.assign(Object.assign({},e),{slippageWithTokens:t.payload});case"SET_ETH_BALANCE":return Object.assign(Object.assign({},e),{ethBalance:t.payload});case"SET_DEFAULT_FROM_TOKEN":return Object.assign(Object.assign({},e),{defaultFromToken:t.payload});case"SET_DEFAULT_TO_TOKEN":return Object.assign(Object.assign({},e),{defaultToToken:t.payload});case"SET_ACCOUNT_BALANCES":return Object.assign(Object.assign({},e),{accountBalances:Object.assign(Object.assign({},e.accountBalances),t.payload)});case"SET_ACCOUNT_ALLOWANCES":const n=e.accountBalances;return Object.keys(n).map((e=>{n[e].tokenAllowances=t.payload})),Object.assign(Object.assign({},e),{accountBalances:n});case"SET_BALANCE_LOADINGS":return Object.assign(Object.assign({},e),{balanceLoadings:Object.assign(Object.assign({},e.balanceLoadings),t.payload)});default:return e}};!function(e){e.Initial="Initial",e.Pending="Pending",e.ApproveSuccess="ApproveSuccess",e.TxSuccess="TxSuccess",e.Failed="Failed"}(ee||(ee={}));const ne={height:void 0,width:void 0,apikey:"",feeRate:0,rebateTo:"",isReverseRouting:!1,contractStatus:ee.Initial};var oe=(e=ne,t)=>"SET_GLOBAL_PROPS"===t.type?Object.assign(Object.assign({},e),t.payload):e;const se={settings:Y,wallet:Z,globals:ne,token:J},ae=u.combineReducers({settings:X,wallet:Q,token:te,globals:oe}),ie=d.configureStore({reducer:ae,middleware:e=>e({serializableCheck:{ignoredActions:["SET_ACCOUNT_BALANCES","SET_ETH_BALANCE"],ignoredPaths:["token.accountBalances","token.ethBalance"]}}),preloadedState:se}),re=e=>(null!=e?e:ie.getState()).wallet.chainId,le=e=>(null!=e?e:ie.getState()).wallet.latestBlockNumber,ce=e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_ACCOUNT_BALANCES",payload:e})})),de=e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_BALANCE_LOADINGS",payload:e})}));var ue=[{constant:!0,inputs:[],name:"getCurrentBlockTimestamp",outputs:[{name:"timestamp",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{components:[{name:"target",type:"address"},{name:"callData",type:"bytes"}],name:"calls",type:"tuple[]"}],name:"aggregate",outputs:[{name:"blockNumber",type:"uint256"},{name:"returnData",type:"bytes[]"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"getLastBlockHash",outputs:[{name:"blockHash",type:"bytes32"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"addr",type:"address"}],name:"getEthBalance",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"getCurrentBlockDifficulty",outputs:[{name:"difficulty",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"getCurrentBlockGasLimit",outputs:[{name:"gaslimit",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"getCurrentBlockCoinbase",outputs:[{name:"coinbase",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"blockNumber",type:"uint256"}],name:"getBlockHash",outputs:[{name:"blockHash",type:"bytes32"}],payable:!1,stateMutability:"view",type:"function"}],pe={[W.MAINNET]:{MULTI_CALL:"0xeefba1e63905ef1d7acba5a8513c70307c1ce441",DODO_APPROVE:"0xCB859eA579b28e02B87A1FDE08d087ab9dbE5149",ERC20_HELPER:"0xD9ef2d1583e8Aa196123e773BE38B539a4d149df"},[W.RINKEBY]:{MULTI_CALL:"0xb7E1C577f95959a3eD11f9281702850328b4e0e4",DODO_APPROVE:"0xcC8d87A7C747eeE4242045C47Ef25e0A81D56ae3",ERC20_HELPER:"0x6A42091d713A67E25a1D11aeE14E7AEB96E0331f"},[W.GOERLI]:{MULTI_CALL:"0x696E25A5e2AEd1C55E6d6Cfa0532Bbda9020165d",DODO_APPROVE:"0xC9143e54021f4a6d33b9b89DBB9F458AaEdd56FB",ERC20_HELPER:"0x24549FC74B3076A962624A26370ed556c467F74C"},[W.BSC]:{MULTI_CALL:"0x1Ee38d535d541c55C9dae27B12edf090C608E6Fb",DODO_APPROVE:"0xa128Ba44B2738A558A1fdC06d6303d52D3Cef8c1",ERC20_HELPER:"0x566651Ad34f6306872FaC5fB95bbF4C9beE8D8F2"},[W.HECO]:{MULTI_CALL:"0x76a328B3440B9276a31523e731B34082df7a6f1A",DODO_APPROVE:"0x68b6c06Ac8Aa359868393724d25D871921E97293",ERC20_HELPER:"0x270C2abC692Dd476B860CCbDfD6D8146BF61f8D8"},[W.POLYGON]:{MULTI_CALL:"0xc9eD9B18e447e600238fe50e944B9062B664DEa4",DODO_APPROVE:"0x292E6b2e054e1157df71C1C9510265CA8C0c7672",ERC20_HELPER:"0xfd24312Ec7871A6D1a31e454D5AbB16c6c25a9b3"},[W.ARBITRUM_ONE]:{MULTI_CALL:"0xF718F2bd590E5621e53f7b89398e52f7Acced8ca",DODO_APPROVE:"0xA867241cDC8d3b0C07C85cC06F25a0cD3b5474d8",ERC20_HELPER:"0x7C062B9C584fA6eC2504270790D38240A2c5fE72"},[W.ARBITRUM_RINKEBY]:{MULTI_CALL:"0x696E25A5e2AEd1C55E6d6Cfa0532Bbda9020165d",DODO_APPROVE:"0x5BaF16d57620Cb361F622232F3cb4090e35F3da2",ERC20_HELPER:"0x5B2fd46E6E3Ff1E479d651ec0b210882Aa9871dF"},[W.AURORA]:{MULTI_CALL:"0x989DcAA95801C527C5B73AA65d3962dF9aCe1b0C",DODO_APPROVE:"0x335aC99bb3E51BDbF22025f092Ebc1Cf2c5cC619",ERC20_HELPER:"0xE8C9A78725D0451FA19878D5f8A3dC0D55FECF25"},[W.MOONRIVER]:{MULTI_CALL:"0x2ff2CeE6E9359F9eA1cF2f51d18bF9F2045447E4",DODO_APPROVE:"0xE8C9A78725D0451FA19878D5f8A3dC0D55FECF25",ERC20_HELPER:"0x6373ceB657C83C91088d328622573FB766064Ac4"},[W.OKCHAIN]:{MULTI_CALL:"0x5e84190a270333aCe5B9202a3F4ceBf11b81bB01",DODO_APPROVE:"0x7737fd30535c69545deeEa54AB8Dd590ccaEBD3c",ERC20_HELPER:"0x4775b1858f1e417C9609D455C3Ad8751ec01daC4"},[W.OPTIMISM]:{MULTI_CALL:"0xb98Ac2fEFc8b73aeAE33D02BB00c26E12afCa9Df",DODO_APPROVE:"0xa492d6eABcdc3E204676f15B950bBdD448080364",ERC20_HELPER:"0x42E456ea0dd7538ea103fBb1d0388D14C97bB5b2"},[W.BOBA]:{MULTI_CALL:"0xD56281EF996B6B29874C77D2e1464216E8043127",DODO_APPROVE:"0x8F8Dd7DB1bDA5eD3da8C9daf3bfa471c12d58486",ERC20_HELPER:"0x9FCFD9ff955D36856F8EE480471B05488C0eB5cA"},[W.AVALANCHE]:{MULTI_CALL:"0x97f0153E7F5749640aDF3Ff9CFC518b79D6Fe53b",DODO_APPROVE:"0xCFea63e3DE31De53D68780Dd65675F169439e470",ERC20_HELPER:"0xC3528D128CC227fd60793007b5e3FdF7c2945282"},[W.CRONOS]:{MULTI_CALL:"0x4f4408D78F9E9e242c17C635FbD0f1952951c917",DODO_APPROVE:"0x9B736bB8f336f61E16454DCA4dE130703D151042",ERC20_HELPER:"0xbd2F5c60cf7d60daD2106ceD4D21b90722761f14"}};function me(e,t,...n){return G(this,void 0,void 0,(function*(){const o=[];for(const e of n)for(const t of e)t.callData&&o.push(t.callData);const s=yield function(e,t,n){return G(this,void 0,void 0,(function*(){const o=yield he(e,t,n),s=new Map;for(const{req:e,resp:t}of o)s.set(e,t);return e.map((e=>({req:e,resp:s.get(e)})))}))}(o,e,t),a=new Map;for(const{req:e,resp:t}of s)a.set(e,null==t?void 0:t.result);return n.map((e=>e.filter((e=>!e.callData||a.get(e.callData))).map(((e,t)=>e.processor(e.callData?a.get(e.callData):null,t)))))}))}function he(e,t,o){return G(this,void 0,void 0,(function*(){let s=[e];e.length>800&&(s=n.chunk(e,800));let a=[];const i=s.map((e=>G(this,void 0,void 0,(function*(){const n=e.map((e=>[e.to,e.data])),s={data:t.interface.encodeFunctionData("aggregate",[n]),to:o};let i;try{i=yield t.provider.call(s)}catch(n){const s=e.length;if(s>20){const n=Math.floor(s/2),[i,r]=yield Promise.all([he(e.slice(0,n),t,o),he(e.slice(n,s),t,o)]);a=[...a,...i,...r]}else{const e="[sendCallReqs] error";console.error(e,n)}}if(void 0===i)throw new Error("Unexpected batch result");const[r,l]=h.defaultAbiCoder.decode(["uint256","bytes[]"],i);if(e.length!==l.length)throw new Error("Unexpected length mismatch");return l.map(((t,n)=>({resp:{result:t},req:e[n]})))}))));return(yield Promise.allSettled(i)).filter((e=>"fulfilled"===e.status)).forEach((({value:e})=>{a=[...a,...e]})),a}))}function fe(e,t,n,o){if(!F(e)||e===m.AddressZero)throw Error(`Invalid 'address' parameter '${e}'.`);return new p.Contract(e,t,function(e,t){return t?function(e,t){return e.getSigner(t).connectUnchecked()}(e,t):e}(n,o))}function xe(){const{provider:e,account:t,chainId:n}=c.useWeb3React(),[o,s]=a.useState(!1),i=a.useMemo((()=>pe[n]),[n]),r=a.useCallback(((n,o)=>{if(e)return fe(n,o,e,t)}),[e,t]),l=a.useCallback((e=>{if(!i)return;const{MULTI_CALL:t}=i,n=r(t,ue);return(()=>G(this,void 0,void 0,(function*(){if(n){s(!0);try{const[o]=yield me(n,t,e);return o}catch(e){console.error("Contract: useMultiContract is error",e)}s(!1)}})))()}),[i,r]);return{getContract:r,contractConfig:i,call:l,loading:o}}var ge=[{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"isERC20",outputs:[{internalType:"bool",name:"isOk",type:"bool"},{internalType:"string",name:"symbol",type:"string"},{internalType:"string",name:"name",type:"string"},{internalType:"uint256",name:"decimals",type:"uint256"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"allownance",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"judgeERC20",outputs:[{internalType:"string",name:"symbol",type:"string"},{internalType:"string",name:"name",type:"string"},{internalType:"uint256",name:"decimals",type:"uint256"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"allownance",type:"uint256"}],stateMutability:"view",type:"function"}];function be(){const{provider:e,account:t}=c.useWeb3React(),n=i.useDispatch(),o=i.useSelector(le);a.useEffect((()=>{(()=>{G(this,void 0,void 0,(function*(){if(!e||!t)return;const o=yield e.getBalance(t);n((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_ETH_BALANCE",payload:e})})))(new k.default(o.toString()).div(1e18)))}))})()}),[e,t,n,o])}function ye(){const{provider:e,chainId:t}=c.useWeb3React(),n=i.useDispatch();a.useEffect((()=>{const o=e=>{n((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_BLOCK_NUMBER",payload:e})})))(e))};return(()=>{G(this,void 0,void 0,(function*(){if(!e||!t)return;const n=yield e.getBlockNumber();o(n),e.on("block",o)}))})(),()=>{null==e||e.off("block",o)}}),[e,n,t])}function ve(e){return Number.parseInt(e,16)}class Ee extends y.Connector{constructor(e,t){super(e),this.customProvider=t,t.on("connect",(({chainId:e})=>{this.actions.update({chainId:ve(e)})})).on("disconnect",(e=>{var t;null===(t=this.onError)||void 0===t||t.call(this,e),this.actions.resetState()})).on("chainChanged",(e=>{this.actions.update({chainId:ve(e)})})).on("accountsChanged",(e=>{this.actions.update({accounts:e})}))}activate(){return G(this,void 0,void 0,(function*(){this.actions.startActivation();const e=this.customProvider;try{const[{chainId:t},n]=yield Promise.all([e.getNetwork(),e.listAccounts()]);this.actions.update({chainId:t,accounts:n})}catch(e){throw this.actions.resetState(),e}}))}}function Ce([e,t]){return[e,t]}var we;function je(){return je=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},je.apply(this,arguments)}var Te,Ae;function Oe(){return Oe=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},Oe.apply(this,arguments)}var Be;!function(e){e.INTEGRATOR="integrator",e.METAMASK="metamask",e.WALLET_CONNECT="walletConnect"}(Be||(Be={}));const ke={[Be.METAMASK]:{name:"MetaMask",type:Be.METAMASK,icon:function(e){return S.createElement("svg",je({height:355,viewBox:"0 0 397 355",width:397,xmlns:"http://www.w3.org/2000/svg"},e),we||(we=S.createElement("g",{fill:"none",fillRule:"evenodd",transform:"translate(-1 -1)"},S.createElement("path",{d:"m114.622644 327.195472 52.004717 13.810198v-18.05949l4.245283-4.249292h29.716982v21.246459 14.872523h-31.839624l-39.268868-16.997169z",fill:"#cdbdb2"}),S.createElement("path",{d:"m199.528305 327.195472 50.943397 13.810198v-18.05949l4.245283-4.249292h29.716981v21.246459 14.872523h-31.839623l-39.268868-16.997169z",fill:"#cdbdb2",transform:"matrix(-1 0 0 1 483.96227 0)"}),S.createElement("path",{d:"m170.872644 287.889523-4.245283 35.056657 5.306604-4.249292h55.18868l6.367925 4.249292-4.245284-35.056657-8.490565-5.311615-42.452832 1.062323z",fill:"#393939"}),S.createElement("path",{d:"m142.216984 50.9915022 25.471698 59.4900858 11.674528 173.158643h41.391511l12.735849-173.158643 23.349056-59.4900858z",fill:"#f89c35"}),S.createElement("path",{d:"m30.7783023 181.657226-29.71698153 86.048161 74.29245393-4.249293h47.7594343v-37.181303l-2.122641-76.487253-10.613208 8.498583z",fill:"#f89d35"}),S.createElement("path",{d:"m87.0283032 191.218134 87.0283028 2.124646-9.551886 44.617563-41.391511-10.623229z",fill:"#d87c30"}),S.createElement("path",{d:"m87.0283032 192.280457 36.0849058 33.994334v33.994334z",fill:"#ea8d3a"}),S.createElement("path",{d:"m123.113209 227.337114 42.452831 10.623229 13.79717 45.679888-9.551886 5.311615-46.698115-27.620398z",fill:"#f89d35"}),S.createElement("path",{d:"m123.113209 261.331448-8.490565 65.864024 56.25-39.305949z",fill:"#eb8f35"}),S.createElement("path",{d:"m174.056606 193.34278 5.306604 90.297451-15.919812-46.211049z",fill:"#ea8e3a"}),S.createElement("path",{d:"m74.2924539 262.393771 48.8207551-1.062323-8.490565 65.864024z",fill:"#d87c30"}),S.createElement("path",{d:"m24.4103777 355.878193 90.2122663-28.682721-40.3301901-64.801701-73.23113313 5.311616z",fill:"#eb8f35"}),S.createElement("path",{d:"m167.688682 110.481588-45.636793 38.243627-35.0235858 42.492919 87.0283028 3.186969z",fill:"#e8821e"}),S.createElement("path",{d:"m114.622644 327.195472 56.25-39.305949-4.245283 33.994334v19.121813l-38.207548-7.43626z",fill:"#dfcec3"}),S.createElement("path",{d:"m229.245286 327.195472 55.18868-39.305949-4.245283 33.994334v19.121813l-38.207548-7.43626z",fill:"#dfcec3",transform:"matrix(-1 0 0 1 513.679252 0)"}),S.createElement("path",{d:"m132.665096 212.464593-11.674528 24.433427 41.39151-10.623229z",fill:"#393939",transform:"matrix(-1 0 0 1 283.372646 0)"}),S.createElement("path",{d:"m23.349057 1.06232296 144.339625 109.41926504-24.410378-59.4900858z",fill:"#e88f35"}),S.createElement("path",{d:"m23.349057 1.06232296-19.10377392 58.42776294 10.61320772 63.7393781-7.42924541 4.249292 10.61320771 9.560906-8.49056617 7.436261 11.67452847 10.623229-7.4292454 6.373938 16.9811323 21.246459 79.5990577-24.433428c38.915096-31.161473 58.018869-47.096318 57.311322-47.804533-.707548-.708215-48.820756-37.1813036-144.339625-109.41926504z",fill:"#8e5a30"}),S.createElement("g",{transform:"matrix(-1 0 0 1 399.056611 0)"},S.createElement("path",{d:"m30.7783023 181.657226-29.71698153 86.048161 74.29245393-4.249293h47.7594343v-37.181303l-2.122641-76.487253-10.613208 8.498583z",fill:"#f89d35"}),S.createElement("path",{d:"m87.0283032 191.218134 87.0283028 2.124646-9.551886 44.617563-41.391511-10.623229z",fill:"#d87c30"}),S.createElement("path",{d:"m87.0283032 192.280457 36.0849058 33.994334v33.994334z",fill:"#ea8d3a"}),S.createElement("path",{d:"m123.113209 227.337114 42.452831 10.623229 13.79717 45.679888-9.551886 5.311615-46.698115-27.620398z",fill:"#f89d35"}),S.createElement("path",{d:"m123.113209 261.331448-8.490565 65.864024 55.18868-38.243626z",fill:"#eb8f35"}),S.createElement("path",{d:"m174.056606 193.34278 5.306604 90.297451-15.919812-46.211049z",fill:"#ea8e3a"}),S.createElement("path",{d:"m74.2924539 262.393771 48.8207551-1.062323-8.490565 65.864024z",fill:"#d87c30"}),S.createElement("path",{d:"m24.4103777 355.878193 90.2122663-28.682721-40.3301901-64.801701-73.23113313 5.311616z",fill:"#eb8f35"}),S.createElement("path",{d:"m167.688682 110.481588-45.636793 38.243627-35.0235858 42.492919 87.0283028 3.186969z",fill:"#e8821e"}),S.createElement("path",{d:"m132.665096 212.464593-11.674528 24.433427 41.39151-10.623229z",fill:"#393939",transform:"matrix(-1 0 0 1 283.372646 0)"}),S.createElement("path",{d:"m23.349057 1.06232296 144.339625 109.41926504-24.410378-59.4900858z",fill:"#e88f35"}),S.createElement("path",{d:"m23.349057 1.06232296-19.10377392 58.42776294 10.61320772 63.7393781-7.42924541 4.249292 10.61320771 9.560906-8.49056617 7.436261 11.67452847 10.623229-7.4292454 6.373938 16.9811323 21.246459 79.5990577-24.433428c38.915096-31.161473 58.018869-47.096318 57.311322-47.804533-.707548-.708215-48.820756-37.1813036-144.339625-109.41926504z",fill:"#8e5a30"})))))},link:"https://metamask.io"},[Be.WALLET_CONNECT]:{name:"WalletConnect",type:Be.WALLET_CONNECT,icon:function(e){return S.createElement("svg",Oe({height:512,viewBox:"0 0 512 512",width:512,xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink"},e),Te||(Te=S.createElement("radialGradient",{id:"a",cx:"0%",cy:"50%",r:"100%"},S.createElement("stop",{offset:0,stopColor:"#5d9df6"}),S.createElement("stop",{offset:1,stopColor:"#006fff"}))),Ae||(Ae=S.createElement("g",{fill:"none",fillRule:"evenodd"},S.createElement("path",{d:"m256 0c141.384896 0 256 114.615104 256 256s-114.615104 256-256 256-256-114.615104-256-256 114.615104-256 256-256z",fill:"url(#a)"}),S.createElement("path",{d:"m64.6917558 37.7088298c51.5328072-50.2784397 135.0839942-50.2784397 186.6167992 0l6.202057 6.0510906c2.57664 2.5139218 2.57664 6.5897948 0 9.1037177l-21.215998 20.6995759c-1.288321 1.2569619-3.3771 1.2569619-4.665421 0l-8.534766-8.3270205c-35.950573-35.0754962-94.237969-35.0754962-130.188544 0l-9.1400282 8.9175519c-1.2883217 1.2569609-3.3771016 1.2569609-4.6654208 0l-21.2159973-20.6995759c-2.5766403-2.5139229-2.5766403-6.5897958 0-9.1037177zm230.4934852 42.8089117 18.882279 18.4227262c2.576627 2.5139103 2.576642 6.5897593.000032 9.1036863l-85.141498 83.070358c-2.576623 2.513941-6.754182 2.513969-9.33084.000066-.00001-.00001-.000023-.000023-.000033-.000034l-60.428256-58.957451c-.64416-.628481-1.68855-.628481-2.33271 0-.000004.000004-.000008.000007-.000012.000011l-60.4269683 58.957408c-2.5766141 2.513947-6.7541746 2.51399-9.3308408.000092-.0000151-.000014-.0000309-.000029-.0000467-.000046l-85.14386774-83.071463c-2.57663928-2.513921-2.57663928-6.589795 0-9.1037163l18.88231264-18.4226955c2.5766393-2.5139222 6.7541993-2.5139222 9.3308397 0l60.4291347 58.9582758c.6441608.62848 1.6885495.62848 2.3327103 0 .0000095-.000009.0000182-.000018.0000277-.000025l60.4261065-58.9582508c2.576581-2.51398 6.754142-2.5140743 9.33084-.0002103.000037.0000354.000072.0000709.000107.0001063l60.429056 58.9583548c.644159.628479 1.688549.628479 2.332709 0l60.428079-58.9571925c2.57664-2.5139231 6.754199-2.5139231 9.330839 0z",fill:"#fff",fillRule:"nonzero",transform:"translate(98 160)"}))))}}},Se={};function Re({provider:e,jsonRpcUrlMap:t,defaultChainId:n}){const o=console.error,s=a.useMemo((()=>function(e,t){if(t){if(b.JsonRpcProvider.isProvider(t))return Ce(c.initializeConnector((e=>new Ee(e,t))));if(b.JsonRpcProvider.isProvider(t.provider))throw new Error("Eip1193Bridge is experimental: pass your ethers Provider directly");return Ce(c.initializeConnector((n=>new f.EIP1193({actions:n,provider:t,onError:e}))))}}(o,e)),[o,e]),i=a.useMemo((()=>function(e){return Ce(c.initializeConnector((t=>new g.MetaMask({actions:t,onError:e}))))}(o)),[o]),r=a.useMemo((()=>t?Object.assign(Object.assign({},H),t):H),[t]),l=a.useMemo((()=>function(e,t,n,o){return Ce(c.initializeConnector((s=>new x.WalletConnect({actions:s,options:{rpc:t,qrcode:e},onError:o,defaultChainId:n}))))}(!0,r,n,o)),[r,n,o]);return s&&(Se[Be.INTEGRATOR]=s),Se[Be.METAMASK]=i,Se[Be.WALLET_CONNECT]=l,Object.values(Se)}function Ie(){const{chainId:e}=c.useWeb3React(),t=i.useSelector(re);return a.useMemo((()=>e||t||1),[e,t])}function De({tokenList:e,popularTokenList:t}){const o=i.useDispatch(),[s,r]=a.useState([]),{account:l}=c.useWeb3React(),d=Ie(),u=i.useSelector(le),p=a.useMemo((()=>(null==t?void 0:t.filter((e=>e.chainId===d)))||[]),[t,d]),m=a.useMemo((()=>{const e=s.map((({address:e})=>e));return null==t||t.forEach((({address:t})=>{e.includes(t)||e.push(t)})),e}),[s,t]);!function({tokenList:e,addresses:t,blockNumber:n}){const{account:o}=c.useWeb3React(),s=i.useDispatch(),r=a.useMemo((()=>[...(null==e?void 0:e.map((e=>e.address)))||[],...t||[]].map((e=>e.toLocaleLowerCase()))),[e,t]),{getContract:l,contractConfig:d,call:u}=xe(),[p,m]=a.useState(),f=a.useMemo((()=>{if(!o||!r.length||!d)return;const{DODO_APPROVE:e,ERC20_HELPER:t}=d,n=l(t,ge);if(!n)return;let a={};const i=r.map((s=>(a[s]=!0,{callData:{data:n.interface.encodeFunctionData("isERC20",[s,o,e]),to:t},processor:e=>{const t=new h.Interface(ge).decodeFunctionResult("isERC20",e),{balance:n,isOk:o}=t,a=parseInt(t.decimals),i=new k.default(10).pow(a),r=new k.default(t.allownance.toString()).div(i);return o?{address:s,decimals:a,symbol:t.symbol,name:t.name,balance:new k.default(n.toString()).div(i),allowance:r}:{address:s,balance:new k.default(0),allowance:new k.default(0)}}})));return s(de(a)),i}),[o,l,JSON.stringify(r)]);a.useEffect((()=>{(()=>{G(this,void 0,void 0,(function*(){if(!f)return;const e=yield u(f),t={};e&&(e.forEach((e=>{t[e.address.toLocaleLowerCase()]={tokenBalances:e.balance,tokenAllowances:e.allowance}})),s(ce(t))),m(e);let n={};r.forEach((e=>{n[e]=!1})),s(de(n))}))})()}),[f,n])}({addresses:m,blockNumber:u}),a.useEffect((()=>{(()=>{G(this,void 0,void 0,(function*(){let t=[];if(e)t=e;else{const e=yield Promise.resolve().then((function(){return require("./tokenList-ee5e15c8.cjs")}));t=n.unionBy(e.default,p,"address")}const s=d,a=t.filter((e=>e.chainId===s));r(a),o((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_TOKEN_LIST",payload:e})})))(a))}))})()}),[e,o,d,p]),a.useEffect((()=>{o(ce({}))}),[l,d]),a.useEffect((()=>{o((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_POPULAR_TOKEN_LIST",payload:e})})))(p))}),[p,o])}const Le=e=>(null!=e?e:ie.getState()).token.tokenList,Ne=e=>(null!=e?e:ie.getState()).token.accountBalances,Me=e=>(null!=e?e:ie.getState()).token.ethBalance||new k.default(NaN),_e=e=>(null!=e?e:ie.getState()).token.defaultFromToken,Pe=e=>(null!=e?e:ie.getState()).token.defaultToToken,Fe=e=>(null!=e?e:ie.getState()).token.balanceLoadings;function Ue(){const{account:e,chainId:t}=c.useWeb3React(),n=i.useSelector(Ne),o=i.useSelector(Me),s=a.useMemo((()=>z[t||1]),[t]),r=a.useCallback((t=>{var a;if(!e)return null;if(t.symbol===s.symbol&&P(t.address,s.address))return!o||(null==o?void 0:o.isNaN())?null:o;const i=null===(a=n[t.address.toLocaleLowerCase()])||void 0===a?void 0:a.tokenBalances;return!i||(null==i?void 0:i.isNaN())?null:i}),[n,o,e]);return r}var We;function He(e,t,n,o=0){if(n&&(e=e.toLocaleLowerCase(),t=t.toLocaleLowerCase()),e===t)return We.fully+o;const s=e.indexOf(t);return 0===s?We.prefix+o:s>0?We.other+o:We.none}!function(e){e[e.fully=1]="fully",e[e.prefix=2]="prefix",e[e.other=3]="other",e[e.none=0]="none"}(We||(We={}));function $e({value:e,onChange:t,occupiedAddrs:n,hiddenAddrs:o,showAddrs:s}){const[r,l]=a.useState(""),c=i.useSelector(Le),d=Ie(),u=Ue(),p=a.useMemo((()=>new Set(o?o.map((e=>e.toLowerCase())):void 0)),[o]),m=a.useMemo((()=>s?new Set(s.map((e=>e.toLowerCase()))):void 0),[s]),h=a.useCallback((e=>e.filter((e=>{if(e.chainId!==d)return!1;let t=!0;return t=m?m.has(e.address.toLowerCase()):!p.has(e.address.toLowerCase()),t}))),[m,d,p]),f=a.useCallback((t=>{if(null===t)return null;const o=[];r?t.forEach((e=>{const t=((e,t,{matchAddress:n}={})=>{if(!t)return 0;const o=t.toLocaleLowerCase();let s=0;n&&e.address.toLocaleLowerCase()===o&&(s=1),s||(s=He(e.symbol.toLocaleLowerCase(),o,!1,1));if(s)e.name.toLocaleLowerCase()===o&&(s=We.fully+1);else{let t=He(e.name.toLocaleLowerCase(),o,!1,10);t=t===We.fully+10?We.fully+1:t,s=t}return s})(e,r,{matchAddress:!0});t&&o.push({sort:t,token:e})})):t.forEach((e=>{o.push({sort:0,token:e})}));const s=[];return o.sort(((t,o)=>{const s=t.token,a=o.token;if(e){if(s.address===e.address)return-1;if(a.address===e.address)return 1}if(null==n?void 0:n.includes(s.address))return-1;if(null==n?void 0:n.includes(a.address))return 1;const i=u&&u(s)||new k.default(0),r=u&&u(a)||new k.default(0);return i.eq(r)?t.sort!==o.sort?t.sort>o.sort?1:-1:s.symbol.localeCompare(a.symbol):i.gt(r)?-1:1})).some((e=>!!(r&&s.length>21)||(s.push(e.token),!1))),s}),[r,u,n,e]),x=a.useCallback((e=>{const o=e.address.toLowerCase();t(e,!!(null==n?void 0:n.some((e=>e.toLowerCase()===o))))}),[t,n]),g=a.useMemo((()=>{const e=h(c);return f(e)||[]}),[c,h,f]);return{filter:r,setFilter:l,showTokenList:g,onSelectToken:x}}function ze({width:e=24,height:t=24,marginRight:n=8,url:s,zIndex:r,cross:l,address:d,token:u,sx:p}){const[m,h]=a.useState(!1),[f,x]=a.useState(""),[g,b]=a.useState(""),[y,E]=a.useState(!1),C=a.useCallback((()=>h(!0)),[]);let w=function(e){const t=i.useSelector(Le),{chainId:n}=c.useWeb3React();return a.useMemo((()=>{if(!e)return;let o=t.find((({address:t,chainId:o})=>o===n&&t===e));return o||(o=t.find((({address:t})=>t===e))),o}),[e,t,n])}(d);u&&(w=u);const j=d||(null==w?void 0:w.address),T=null==w?void 0:w.symbol,A=null==T?void 0:T.charAt(0).toUpperCase(),O=a.useMemo((()=>{const e=null==w?void 0:w.logoURI;return s||e||""}),[s,w]);return a.useEffect((()=>{E(!1)}),[j,O]),a.useEffect((()=>{l&&(O?function(e,t){const n=new XMLHttpRequest;let o;n.onload=function(){const e=new FileReader;e.onloadend=function(){t(e.result)},e.readAsDataURL(n.response)},n.onerror=function(){t()};try{o=new URL(e)}catch(e){}finally{n.open("GET",o||e),n.responseType="blob",n.send()}}(O,(e=>{x(e)})):x(""))}),[O,l]),a.useEffect((()=>{try{let t=j;if(t&&t.length<15&&(t=t.padEnd(15,"0")),t){const n=new R.default(t,{size:e,format:"svg",margin:.2,background:[255,234,4,255]}).toString();b(`data:image/svg+xml;base64,${n}`)}}catch(e){console.error("generate Identicon error: ",e)}}),[j,e]),v.jsxs(o.Box,{sx:Object.assign({position:"relative",display:"flex",alignItems:"center",justifyContent:"center",minWidth:e,width:e,height:t,marginRight:n,zIndex:r},p||{}),style:{width:e,height:t},children:[!m&&v.jsx(o.Box,{sx:{typography:"ht",height:"100%",width:"100%",borderRadius:"50%",border:"transparent 2px solid",borderColor:"text.primary",color:"text.primary",display:"flex",alignItems:"center",justifyContent:"center"},children:A}),v.jsx(o.Box,{component:"img",src:!(l?f:O)||y?g:l?f:O,onLoad:C,onError:e=>{const t=e.target;j&&g&&E(!0),t.onerror=null},sx:{position:"absolute",top:"0",bottom:"0",left:"0",right:"0",borderRadius:"50%",overflow:"hidden",width:"100%",height:"100%"}})]})}function Ve({token:t,onClick:n}){var s,a;const i=o.useTheme();return v.jsxs(o.Box,{component:o.BaseButton,sx:{display:"flex",alignItems:"center",color:i.palette.text.primary,typography:"h5",fontWeight:600},onClick:e=>{n&&n(e)},"data-testid":"swap-select-token-btn",children:[(null==t?void 0:t.address)?v.jsxs(v.Fragment,{children:[v.jsx(ze,{url:null==t?void 0:t.logoURI,address:null!==(s=null==t?void 0:t.address)&&void 0!==s?s:"",marginRight:6}),v.jsx(o.Box,{children:null!==(a=null==t?void 0:t.symbol)&&void 0!==a?a:"-"})]}):v.jsx(e.Trans,{id:"SELECT TOKEN"}),v.jsx(o.Box,{sx:{ml:7,width:12,transform:"rotateX(180deg)"},component:r.CaretUp})]})}function qe({onClick:t,balance:n,decimals:s,address:a,showMaxBtn:i}){const{palette:r}=o.useTheme();return v.jsxs(o.Box,{sx:{display:"flex",typography:"body2",color:r.text.secondary},children:[v.jsx(e.Trans,{id:"Balance:"})," ",a?L({input:n,decimals:Math.min(s||4,4)}):"-",i&&n&&n.gt(0)&&v.jsx(o.Box,{component:o.BaseButton,sx:{ml:6,color:(null==n?void 0:n.gt(0))?r.primary.main:r.text.disabled,cursor:a&&t?"pointer":"unset"},onClick:()=>t&&t(n?n.toString():""),children:v.jsx(e.Trans,{id:"Max"})})]})}function Ke({readOnly:e,sx:t,value:n,decimals:s,onChange:i,suffix:l,withClear:c,onFocus:d,placeholder:u}){const p=o.useTheme(),m=a.useMemo((()=>l||(c&&n&&i?v.jsx(o.Box,{component:o.BaseButton,sx:{ml:5,width:18,height:18,borderRadius:"50%",backgroundColor:"border.main",display:"flex",justifyContent:"center",alignItems:"center"},onClick:()=>{i&&i("")},children:v.jsx(o.Box,{component:r.Error,sx:{width:12,color:"text.primary"}})}):void 0)),[i,l,p.palette.text.primary,n,c]);return v.jsxs(o.Box,{sx:Object.assign({mt:12,display:"flex",justifyContent:"space-between",alignItems:"center"},t),"data-testid":"number-input-wrapper",children:[v.jsx(o.Input,{fullWidth:!0,value:n,readOnly:e,placeholder:u||"0.00",onFocus:d,onChange:e=>{const t=e.target.value,n=0===t.length?"":_(t,s);i&&i(n)},sx:{width:"inherit",border:"none","& .MuiInput-input":{fontSize:24,border:"none",outline:"none",height:24,padding:0,color:"text.primary","&::placeholder":{fontSize:24,color:"text.disabled"}}}}),!e&&n&&m]})}function Ge({open:e,onClose:t,title:n,rightSlot:s,canBack:a=!0,children:i,height:l,testId:c}){return v.jsxs(o.Box,{sx:{position:"absolute",top:e?0:"100%",transition:"top 300ms",zIndex:1,left:0,right:0,bottom:0,display:"flex",flexDirection:"column",backgroundColor:"background.paper",borderRadius:16,height:l},"data-testid":c,"data-active":e?"1":"0",children:[n?v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:20},children:[v.jsx(o.Box,{sx:{display:"flex",alignItems:"center",typography:"caption"},children:n}),s,!s&&a&&v.jsx(o.Box,{component:r.Error,sx:{color:"text.secondary",cursor:"pointer"},onClick:t})]}):"",i]})}const Ye=e=>(null!=e?e:ie.getState()).globals;function Xe({token:e,disabled:t,onClick:n}){return v.jsxs(o.Box,{sx:Object.assign({display:"inline-flex",alignItems:"center",p:8,border:"solid 1px",typography:"body2",borderRadius:8},t?{borderColor:"transparent",backgroundColor:"border.disabled",cursor:"auto"}:{borderColor:"border.main",cursor:"pointer","&:hover":{backgroundColor:"hover.default"}}),onClick:()=>{t||n()},children:[v.jsx(ze,{token:e}),e.symbol]})}function Ze({token:e,disabled:t,style:n,onClick:s}){const a=Ue()(e),i=a?D({input:a}):"";return v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",typography:"body2",px:6,py:5,borderRadius:8,cursor:t?"auto":"pointer",opacity:t?.5:1,"&:hover":{backgroundColor:"hover.default"}},style:n,onClick:()=>{t||s()},"data-testid":"token-picker-item",children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(ze,{token:e}),v.jsxs(o.Box,{children:[v.jsx(o.Box,{sx:{fontWeight:600,textAlign:"left"},children:e.symbol}),v.jsx(o.Box,{sx:{mt:4,textAlign:"left"},children:i})]})]}),v.jsx(o.Box,{sx:{color:"text.secondary"},children:e.name})]})}function Qe({value:e,onChange:t,occupiedAddrs:n,hiddenAddrs:s,showAddrs:r,visible:l}){var c;const d=Ie(),u=i.useSelector((e=>((e,t)=>(null!=t?t:ie.getState()).token.popularTokenList.filter((({chainId:t})=>e===t)))(d,e))),{showTokenList:p,filter:m,setFilter:h,onSelectToken:f}=$e({value:e,onChange:t,occupiedAddrs:n,hiddenAddrs:s,showAddrs:r}),x=a.useRef(null),g=a.useRef(null),[b,y]=a.useState(0);a.useEffect((()=>{l&&x.current&&y(x.current.offsetHeight-34)}),[x,l]);const w=a.useCallback((({index:t,style:n})=>{const s=!!(null==u?void 0:u.length);if(0===t&&s)return v.jsx(o.Box,{sx:{position:"relative",display:"flex",gap:8,flexWrap:"wrap",pb:32,"&::after":{content:'""',position:"absolute",bottom:16,left:0,right:0,height:"1px",backgroundColor:"border.main"}},ref:g,style:Object.assign(Object.assign({},n),{visibility:n.height?"visible":"hidden",height:n.height?n.height:"auto"}),children:u.map((t=>v.jsx(Xe,{token:t,disabled:(null==e?void 0:e.address)===t.address,onClick:()=>f(t)},t.address)))});const a=p[s?t-1:t];return v.jsx(Ze,{token:a,disabled:!!e&&e.address===a.address,style:n,onClick:()=>f(a)})}),[p,u,g,e]),j=a.useCallback((e=>{var t;if(0===e&&(null==u?void 0:u.length)){const e=(null===(t=g.current)||void 0===t?void 0:t.offsetHeight)||0;return e<=52?0:e}return 52}),[g,u]);return v.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",px:20,flex:1},children:[v.jsx(o.SearchInput,{fullWidth:!0,height:48,value:m,onChange:e=>h(e.target.value),clearValue:()=>h(""),placeholder:E.i18n._("Enter the token symbol or address")}),v.jsx(o.Box,{sx:{mt:16,pb:16,flex:1,minHeight:64},ref:x,children:v.jsx(C.VariableSizeList,{height:b,itemCount:p.length+((null==u?void 0:u.length)?1:0),itemSize:j,width:"100%",className:"token-list",children:w},null===(c=g.current)||void 0===c?void 0:c.offsetHeight)})]})}function Je({open:t,value:n,onClose:o,occupiedAddrs:s,onTokenChange:a}){const{height:r}=i.useSelector(Ye);return v.jsx(Ge,{height:r,open:t,onClose:o,title:v.jsx(e.Trans,{id:"Select a token"}),testId:"token-picker-wrapper",children:v.jsx(Qe,{value:n,visible:t,onChange:a,occupiedAddrs:s})})}function et({sx:e,amt:t,token:n,readOnly:s,showMaxBtn:i,onMaxClick:r,fiatPriceTxt:l,occupiedAddrs:c,onInputFocus:d,onTokenClick:u,onInputChange:p,onTokenChange:m}){const h=o.useTheme(),f=Ue(),[x,g]=a.useState(!1),b=n?f(n):null;return v.jsxs(o.Box,{sx:Object.assign({width:"100%",minHeight:133,padding:20,borderRadius:12,overflow:"hidden",display:"flex",flexDirection:"column",justifyContent:"space-between",backgroundColor:h.palette.background.input},e),children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[v.jsx(Ve,{token:n,onClick:()=>g(!0)}),v.jsx(qe,{balance:b,onClick:r,showMaxBtn:i,address:null==n?void 0:n.address,decimals:null==n?void 0:n.decimals})]}),v.jsx(Ke,{value:t,onFocus:d,onChange:p,readOnly:s,withClear:!0}),v.jsx(o.Box,{sx:{mt:4,typography:"body2",color:h.palette.text.secondary},children:l}),v.jsx(Je,{value:n,open:x,occupiedAddrs:c,onClose:()=>{u&&u(),g(!1)},onTokenChange:(e,t)=>{m(e,t),g(!1)}})]})}const tt={"en-US":w.en,"zh-CN":w.zh,pseudo:w.en};function nt({locale:t,children:n}){return a.useEffect((()=>{(()=>{G(this,void 0,void 0,(function*(){yield function(e="en-US"){return G(this,void 0,void 0,(function*(){E.i18n.loadLocaleData(e,{plurals:()=>tt[e]});try{const n=yield(t=`./locales/${e}.js`,Promise.resolve().then((function(){return B(require(t))})));E.i18n.load(e,n.messages||n.default.messages)}catch(e){}var t;E.i18n.activate(e)}))}(t)}))})()}),[t]),v.jsx(e.I18nProvider,{i18n:E.i18n,children:n})}var ot,st,at;!function(e){e[e.Running=0]="Running",e[e.Success=1]="Success",e[e.Failed=2]="Failed",e[e.Warning=3]="Warning"}(ot||(ot={})),function(e){e.Canceled="canceled",e.Failed="failed",e.Success="success",e.Submitted="submitted"}(st||(st={})),function(e){e[e.Failed=0]="Failed",e[e.Success=1]="Success"}(at||(at={}));var it,rt=[{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"guy",type:"address"},{name:"wad",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"}];!function(e){e[e.Failed=0]="Failed",e[e.Success=1]="Success",e[e.Warning=2]="Warning"}(it||(it={}));const lt=(e,t)=>G(void 0,void 0,void 0,(function*(){const{value:n,from:o,to:s,data:a}=e,i={from:o,to:s,value:n,data:a};n&&!/^0x0*$/.test(n)||delete i.value;try{return(yield t.estimateGas(i)).add(5e4)}catch(e){t.call(i).then((e=>{if("test"!==process.env.NODE_ENV)throw new Error("Unexpected issue with estimating the gas. Please try again.")})).catch((e=>{if("test"!==process.env.NODE_ENV)throw e}))}return null})),ct=(e,t)=>G(void 0,void 0,void 0,(function*(){try{return yield t.getSigner().sendTransaction(e)}catch(e){throw 4001===(null==e?void 0:e.code)?new Error(E.i18n._("Transaction rejected.")):e}}));var dt,ut;!function(e){e.Approval="APPROVAL",e.TX="TX",e.TypedSign="TypedSign"}(dt||(dt={})),function(e){e.Normal="Normal",e.Privacy="Privacy",e.LimitOrder="LimitOrder",e.RFQ="RFQ"}(ut||(ut={}));const pt=new k.default(2).pow(256).minus(1),mt=e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_GLOBAL_PROPS",payload:e})}));function ht({onTxFail:e,onTxSubmit:t,onTxSuccess:n}={}){const{account:o,provider:s}=c.useWeb3React(),r=Ie(),[l,d]=a.useState(!1),[u,p]=a.useState(new Map),m=i.useDispatch(),[h,f]=a.useState(null),[x,g]=a.useState(""),[b,y]=a.useState(null),[v,C]=a.useState(!1),[w,j]=a.useState(),T=a.useCallback(((a,i,l,c=!1,u,h,x,b)=>G(this,void 0,void 0,(function*(){if(g(""),f(""),!o||!s)throw new Error("Submission: Cannot execute step when the wallet is disconnected");let v,w,T;j((()=>x)),d(!1);try{if(d(!0),i.opcode===dt.Approval)T=yield((e,t,n,o,s,a)=>G(void 0,void 0,void 0,(function*(){const i=fe(e,rt,s,a).interface.encodeFunctionData("approve",[n,o.toFixed()]),r={from:t,to:e,data:i,value:`0x${new k.default("0").toString(16)}`,gasLimit:void 0},l=yield lt(r,s);return l&&(r.gasLimit=l),yield ct(r,s)})))(i.token.address,o,i.contract,i.amt||pt,s,o),v=T.hash,g(v);else{if(i.opcode!==dt.TX)throw new Error(`Op ${i.opcode} not implemented!`);if(""===i.to)throw new Error("Submission: malformed to");if(0===i.data.length)throw new Error("Submission: malformed data");if(0===i.data.indexOf("0x")&&i.data.length<=2)throw new Error("Submission: malformed data");if(w={value:i.value,data:i.data,to:i.to,gasLimit:i.gasLimit,from:o,chainId:r},!w.gasLimit)try{const e=yield lt(w,s);e&&(w.gasLimit=e)}catch(e){console.debug(e)}if(T=yield ct(w,s),v=T.hash,g(v),!v)throw new Error(`Unexpected tx: ${v}`)}}catch(t){if(d(!1),y({spec:i,brief:a,subtitle:l}),console.error(t),t.message){m(mt({contractStatus:ee.Failed}));const n={error:t.message,brief:a};h&&Object.assign(n,h),e&&e(t,h),f(function(e,t){var n;const o=null===(n=z[e])||void 0===n?void 0:n.symbol,s=[{error:"insufficient",msg:E.i18n._("Insufficient funds - Please retry after depositing more {EtherTokenSymbol} into your wallet",{EtherTokenSymbol:o})},{error:["External Swap execution Failed","Return amount is not enough"],msg:E.i18n._("Price impact exceeds the slippage tolerance you set. Try increasing the slippage tolerance.")},{error:"SafeERC20: low-level call failed",msg:E.i18n._("SafeERC20: low-level call failed. Please log a Zendesk support ticket or contact the DODO team.")},{error:["User denied","cancel","User rejected","user rejected"],msg:E.i18n._("User denied transaction signature.")},{error:["Cannot set properties of undefined (setting 'loadingDefauIts'){\"originalError\":{",'[ethjs-query]while formatting outputs from RPC\'["value":["code":-32000,"message":"header not found"))'],msg:E.i18n._("RPC node data exception")},{error:['execution reverted:FORCESTOP ["originalError"'],msg:E.i18n._("ForceStop exception")},{error:["replacement transaction underpriced","Gasprice too low","transaction underprice"],msg:E.i18n._("Gas price is too low, please adjust in your wallet and try again")},{error:["MINT_INVALID"],msg:E.i18n._("No ForceStop access")},{error:["NOT_PHASE_EXE"],msg:E.i18n._("Unable to SETTLE during the cooling-off period")},{error:["params specify an EIP-1559transaction but the currentnetwork does not support"],msg:E.i18n._("Wallet incompatibility")},{error:["ALREADY_SETTLED"],msg:E.i18n._("This CP has been settled by other addrs")},{error:["create RFQ order failed]:LESS_THAN_FEE_LIMIT"],msg:E.i18n._("Service update, please wait and try again")}];let a="";return s.some((e=>Array.isArray(e.error)?e.error.some((n=>t.indexOf(n)>-1&&(a=e.msg,!0))):t.indexOf(e.error)>-1&&(a=e.msg,!0))),a||t}(r,t.message))}return st.Failed}y({spec:i,brief:a,subtitle:l}),C(!1),d(!1);const A=Object.assign(Object.assign(Object.assign(Object.assign({brief:a},i),w),{tx:v,subtitle:l}),h);m(mt({contractStatus:ee.Pending})),t&&t(v,A),u&&u();const O={brief:a,spec:i,tx:v,subtitle:l};if(p((e=>e.set(v,[O,ot.Running]))),c)return st.Submitted;if(u&&u(),null==T?void 0:T.wait){const e=yield T.wait(1);if(C(!0),e.status===at.Success)return"TX"===A.opcode&&m(mt({contractStatus:ee.TxSuccess})),"APPROVAL"===A.opcode&&m(mt({contractStatus:ee.ApproveSuccess})),b&&b(v),n&&n(v,A),p((e=>e.set(v,[O,ot.Success]))),st.Success}return C(!0),p((e=>e.set(v,[O,ot.Failed]))),st.Failed}))),[o,r,d,s]),A=a.useMemo((()=>({execute:T,requests:u,setShowing:y,waitingSubmit:l})),[T,u,y]),O=a.useCallback((()=>{y(null),w&&(w(),j(void 0))}),[w]);return{showing:b,showingDone:v,transactionTx:x,errorMessage:h,setErrorMessage:f,closeShowing:O,ctxVal:A,requests:u}}function ft(){const{requests:e}=gt(),t=[];return null==e||e.forEach((function([e,n]){n===ot.Running&&t.push(e)})),{runningRequests:t,isInflight:t.length>0}}const xt=a.createContext({execute:()=>Promise.resolve(st.Canceled),requests:void 0,waitingSubmit:!1});function gt(){return a.useContext(xt)}var bt;function yt(){return yt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},yt.apply(this,arguments)}var vt=function(e){return S.createElement("svg",yt({width:"33px",height:"33px",viewBox:"0 0 33 33",xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink"},e),bt||(bt=S.createElement("g",{stroke:"none",strokeWidth:1,fill:"none",fillRule:"evenodd",strokeLinecap:"round",strokeLinejoin:"round"},S.createElement("g",{transform:"translate(-186.000000, -375.000000)",stroke:"currentColor",strokeWidth:4},S.createElement("g",{transform:"translate(18.000000, 291.000000)"},S.createElement("g",{transform:"translate(40.000000, 83.000000)"},S.createElement("path",{d:"M159,32 C159,15.9837423 146.016258,3 130,3"})))))))};function Et({showingDone:e,errorMessage:t}){return t?v.jsx(o.Box,{component:r.ErrorWarn,sx:{width:64,height:64,color:"error.main"}}):e?v.jsx(o.Box,{component:r.DoneBorder,sx:{width:64,height:64,color:"success.main"}}):v.jsx(o.Box,{sx:{mx:"auto",border:e=>{var t;return`6px solid ${null===(t=e.palette)||void 0===t?void 0:t.background.input}`},borderRadius:"50%",width:"64px",height:"64px",position:"relative",animation:"loadingRotate 1.1s infinite linear","@keyframes loadingRotate":{"0%":{transform:"rotate(0deg)"},"100%":{transform:"rotate(359deg)"}}},children:v.jsx(o.Box,{component:vt,sx:{position:"absolute",top:"-6px",right:"-6px",color:"primary.main"}})})}function Ct({showingDone:e,showing:t}){return v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",flexDirection:"column"},children:[v.jsx(o.Box,{sx:{mt:60},children:e?E.i18n._("{0} confirmed",{0:null==t?void 0:t.brief}):E.i18n._("{0} pending",{0:null==t?void 0:t.brief})}),(null==t?void 0:t.subtitle)?v.jsx(o.Box,{sx:{mt:20,typography:"body2"},children:null==t?void 0:t.subtitle}):""]})}function wt({isStarted:t,isEnded:n,tx:s}){const[i,l]=a.useState(0),{chainId:d}=c.useWeb3React(),u=a.useMemo((()=>`https://${q[d||1]}/tx/${s}`),[s,d]),p=a.useMemo((()=>{const e=Math.floor(i/60),t=i%60;return e?`${e}m ${t}s`:`${t}s`}),[i]),m=a.useRef();return a.useEffect((()=>(l(0),m.current=setInterval((()=>{l((e=>e+1))}),1e3),()=>{clearInterval(m.current)})),[t]),a.useEffect((()=>{clearInterval(m.current)}),[n]),v.jsxs(o.Box,{sx:{mt:20,pt:20,display:"flex",justifyContent:"space-between",alignItems:"center",typography:"body2",color:"text.secondary",border:"solid 1px transparent",borderTopColor:"border.main"},children:[v.jsxs(o.Box,{children:[v.jsx(e.Trans,{id:"Transaction Time:"}),p]}),v.jsxs(o.HoverOpacity,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},component:"a",href:u,target:"_blank",rel:"noopener noreferrer",children:[v.jsx(e.Trans,{id:"Tx"}),v.jsx(o.Box,{component:r.ArrowTopRightBorder,sx:{width:16,height:16,ml:6}})]})]})}function jt(t){var{children:n}=t,s=K(t,["children"]);const{ctxVal:a,showing:r,closeShowing:l,showingDone:c,errorMessage:d,transactionTx:u}=ht(s),p=i.useDispatch();return v.jsxs(xt.Provider,{value:a,children:[n,v.jsx(Ge,{open:!!r,onClose:l,children:v.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",justifyContent:"space-between",px:20,pb:20,flex:1,overflowY:"auto"},children:[v.jsxs(o.Box,{children:[v.jsx(o.Box,{sx:{textAlign:"center",pt:60},children:v.jsx(Et,{showingDone:c,errorMessage:d})}),d?v.jsxs(o.Box,{sx:{textAlign:"center",mt:60},children:[v.jsx(o.Box,{children:v.jsx(e.Trans,{id:"Something went wrong."})}),v.jsx(o.Box,{sx:{color:"text.secondary",mt:12,typography:"body2",wordBreak:"break-all"},children:d})]}):v.jsxs(v.Fragment,{children:[v.jsx(Ct,{showingDone:c,showing:r}),v.jsx(wt,{isStarted:!!r,isEnded:c,tx:u})]})]}),v.jsx(o.Button,{fullWidth:!0,size:o.Button.Size.big,onClick:()=>{p(mt({contractStatus:ee.Initial})),l()},sx:{mt:20},children:d?v.jsx(e.Trans,{id:"Dismiss"}):v.jsx(e.Trans,{id:"Close"})})]})})]})}function Tt({token:e,fiatPrice:n}){return{marginAmount:a.useMemo((()=>{var o;const s=null!==(o=null==e?void 0:e.decimals)&&void 0!==o?o:6,a=((e,n,o)=>{const s=new t.BigNumber(e).times(new t.BigNumber(10).pow(n));return o?s:s.dp(0)})(null!=n?new k.default(500).div(n):new k.default(0),s);return(a.lt(new k.default(1).times(new k.default(10).pow(s-3)))?new k.default(0):a).toString(10)}),[null==e?void 0:e.decimals,n])}}function At({width:e,height:t,feeRate:n,rebateTo:o,colorMode:s,apikey:r,defaultChainId:l,defaultToToken:c,defaultFromToken:d}){const u=i.useDispatch();a.useEffect((()=>{s&&u((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_COLOR_MODE",payload:e})})))(s))}),[s]),a.useEffect((()=>{var e;l&&u((e=l,t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_CHAIN_ID",payload:e})}))))}),[l]),a.useEffect((()=>{u(mt({height:t}))}),[t]),a.useEffect((()=>{u(mt({width:e}))}),[e]),a.useEffect((()=>{r&&u(mt({apikey:r}))}),[r]),a.useEffect((()=>{n&&u(mt({feeRate:n}))}),[n]),a.useEffect((()=>{o&&u(mt({rebateTo:o}))}),[o]),a.useEffect((()=>{d&&u((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_DEFAULT_FROM_TOKEN",payload:e})})))(d))}),[d]),a.useEffect((()=>{c&&u((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_DEFAULT_TO_TOKEN",payload:e})})))(c))}),[c])}function Ot({refetch:e,interval:t}){let n;a.useEffect((()=>(e(),clearTimeout(n),n=setInterval((()=>{e()}),null!=t?t:15e3),()=>clearTimeout(n))),[e])}function Bt({fromToken:e,toToken:t,chainId:n}){const[o,s]=a.useState(!1),[i,r]=a.useState(""),[l,c]=a.useState(""),d=a.useCallback((()=>{if(!n||!e||!t)return;s(!0);const o=[e,t];I.default.post("https://api.dodoex.io/price-api/api/v1/price/current/batch",{networks:o.map((()=>(e=>V[e]||V[W.MAINNET])(n))),addresses:o.map((e=>e.address)),symbols:o.map((e=>e.symbol)),isCache:!0},{headers:{apikey:"dodofrontend777888ofopensource"}}).then((n=>{var o;s(!1);const a=null===(o=n.data)||void 0===o?void 0:o.data;a&&(r(a.find((t=>t.address===e.address)).price),c(a.find((e=>e.address===t.address)).price))})).catch((e=>{s(!1),console.error(e)}))}),[n,e,t]);return Ot({refetch:d}),{loading:o,refetch:d,toFiatPrice:l,fromFiatPrice:i}}const kt=e=>(null!=e?e:ie.getState()).settings.slippage,St=e=>(null!=e?e:ie.getState()).settings.ddl;var Rt;function It({toToken:e,fromToken:t,fromAmount:n,toAmount:o,marginAmount:s}){const{account:r,chainId:l,provider:d}=c.useWeb3React(),u=i.useSelector(re),p=a.useMemo((()=>l||u),[l,u]),m=i.useSelector(kt)||3,h=i.useSelector(St)||20,{feeRate:f,rebateTo:x,apikey:g,isReverseRouting:b}=i.useSelector(Ye),y=a.useMemo((()=>Math.floor(Date.now()/1e3)+60*h),[h]),[v,C]=a.useState(Rt.Initial),[w,j]=a.useState(null),[A,O]=a.useState(""),[B,k]=a.useState(null),[S,R]=a.useState(null),[D,L]=a.useState(null),[N,M]=a.useState(T.BigNumber.from(0)),[_,P]=a.useState(null),[F,U]=a.useState(null),[W,H]=a.useState(""),[$,z]=a.useState(""),[V,q]=a.useState(""),[K,Y]=a.useState(0),X=a.useCallback((()=>G(this,void 0,void 0,(function*(){if(!p||!t||!e)return;if(!b&&!n)return;if(b&&!o)return;C(Rt.Loading);const s={chainId:p,deadLine:y,apikey:g,slippage:m,source:"dodoV2AndMixWasm",toTokenAddress:e.address,toTokenDecimals:e.decimals,fromTokenAddress:t.address,fromTokenDecimals:t.decimals,userAddr:r||"0x0000000000000000000000000000000000000000"};b?s.toAmount=T.parseFixed(String(o||1),e.decimals).toString():s.fromAmount=T.parseFixed(String(n||1),t.decimals).toString(),x&&f&&(s.rebateTo=x,s.fee=f);try{const e=(yield I.default.get("https://api.dodoex.io/route-service/v2/widget/getdodoroute",{params:s})).data.data;if((null==e?void 0:e.resAmount)?(C(Rt.Success),j(e.resAmount),L(e.priceImpact),P(e.resPricePerFromToken),U(e.resPricePerToToken),k(e.baseFeeAmount),R(e.additionalFeeAmount),H(e.to),z(e.data),O(e.value),q(e.useSource),Y(e.duration)):C(Rt.Failed),!r||!d)return;const t=yield lt({from:r,to:e.to,value:e.value,data:e.data},d);t&&M(t)}catch(e){C(Rt.Failed),console.error(e)}}))),[y,r,p,e,f,m,x,t,d,n,o,g,b]);Ot({refetch:X});const Z=a.useMemo((()=>{const e=b?o:n;return v!==Rt.Loading&&e?w:null}),[v,b,o,n,w]),Q=function(){const{chainId:e,account:t}=c.useWeb3React(),n=gt();return a.useCallback((({to:e,data:o,useSource:s,duration:a,ddl:i,gasLimit:r,subtitle:l,value:c})=>{const d=60*i,u=c;s&&"weth"!==s.toLowerCase()&&r&&r.lt(3e4)&&console.debug("Warning: GasLimit less than the minimum!");const p={from:t,to:e,data:o,value:u,route:s,duration:a,ddlSecRel:d,gasLimit:r};n.execute(E.i18n._("Swap"),Object.assign({opcode:dt.TX},p),l)}),[t,e])}(),J=a.useCallback((e=>{t&&(b?w:n)&&Q({to:W,data:$,useSource:V,duration:K,ddl:h,value:A,subtitle:e})}),[W,h,$,K,V,t,n,N,w,A,b]);return{status:v,refetch:X,priceImpact:D,executeSwap:J,baseFeeAmount:B,resAmount:Z,additionalFeeAmount:S,resPricePerToToken:F,resPricePerFromToken:_}}!function(e){e.Initial="Initial",e.Loading="Loading",e.Failed="Failed",e.Success="Success"}(Rt||(Rt={}));function Dt(e){De(e),be(),ye();const{provider:t,connector:n}=c.useWeb3React();a.useEffect((()=>{const t=e.defaultChainId||1;(null==n?void 0:n.connectEagerly)?n.connectEagerly(t):n.activate(t)}),[n]),a.useEffect((()=>{const e=null==t?void 0:t.provider;e&&e.once&&e.once("chainChanged",(()=>{setTimeout((()=>{window.location.reload()}),200||100)}))}),[t]);const s=e.width||375,i=e.height||494;return At(Object.assign(Object.assign({},e),{width:s,height:i})),v.jsx(o.Box,{sx:{width:s,height:i,overflow:"hidden",position:"relative",display:"flex",flexDirection:"column",minWidth:335,minHeight:494,borderRadius:16,backgroundColor:"background.paper"},className:"dodo-widget-container",children:v.jsx(jt,{...e,children:e.children})})}function Lt(e){const t=o.createTheme({mode:e.colorMode,theme:e.theme,lang:e.locale||"en-US"}),n=a.useMemo((()=>e.defaultChainId||1),[e.defaultChainId]),s=Re({provider:e.provider,jsonRpcUrlMap:e.jsonRpcUrlMap,defaultChainId:n}),r=`${s.length}+${e.jsonRpcUrlMap?Object.entries(e.jsonRpcUrlMap):""}+${e.defaultChainId}+${n}`;return v.jsx(i.Provider,{store:ie,children:v.jsx(nt,{locale:e.locale,children:v.jsx(o.ThemeProvider,{theme:t,children:v.jsxs(c.Web3ReactProvider,{connectors:s,children:[v.jsx(o.CssBaseline,{container:".dodo-widget-container"}),v.jsx(Dt,{...e})]},r)})})})}function Nt(e){const{width:t}=i.useSelector(Ye),n=a.useMemo((()=>{let e="";return"number"==typeof t?e=`${t}px`:t&&(e=t),e?`calc(${e} - 40px)`:"auto"}),[t]);return v.jsx(o.QuestionTooltip,{container:document.querySelector(".dodo-widget-container"),maxWidth:n,...e})}function Mt({onClick:e}){const t=o.useTheme();return v.jsx(o.HoverOpacity,{sx:{width:"100%",position:"relative"},onClick:e,children:v.jsx(o.Box,{component:o.BaseButton,sx:{width:36,height:36,borderRadius:"50%",backgroundColor:t.palette.background.input,border:`4px solid ${t.palette.background.paper}`,display:"flex",alignItems:"center",justifyContent:"center",position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -50%) rotate(-90deg)"},children:v.jsx(o.Box,{component:r.ArrowBack,sx:{width:18,color:"text.secondary"}})})})}function _t({open:t,execute:n,onClose:s,toToken:l,fromToken:c,fromAmount:d,toAmount:u,priceImpact:p,clearFromAmt:m,clearToAmt:h,baseFeeAmount:f,curToFiatPrice:x,curFromFiatPrice:g,pricePerFromToken:b,additionalFeeAmount:y}){var E,C;const w=o.useTheme(),j=i.useSelector(kt),T=i.useDispatch(),{contractStatus:A}=i.useSelector(Ye),O=a.useMemo((()=>new k.default(p).gt(15)),[p]),[B,S]=a.useState(!1),[R,I]=a.useState(!1);return a.useEffect((()=>{A!==ee.Pending&&s(),A===ee.TxSuccess&&(h(),m())}),[A]),a.useEffect((()=>{S(!1)}),[x]),v.jsx(Ge,{open:t,onClose:()=>{T(mt({contractStatus:ee.Initial})),s()},title:v.jsx(e.Trans,{id:"Swap summary"}),children:v.jsxs(o.Box,{sx:{margin:20,display:"flex",height:"100%",flexDirection:"column",borderTop:`1px solid ${w.palette.border.main}`},children:[v.jsxs(o.Box,{sx:{py:20,display:"flex",typography:"body2",alignItems:"center",justifyContent:"center",flexDirection:"column",borderBottom:`1px solid ${w.palette.border.main}`},children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsxs(o.Box,{children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[v.jsx(ze,{width:16,height:16,url:null==c?void 0:c.logoURI,address:null!==(E=null==c?void 0:c.address)&&void 0!==E?E:"",marginRight:6}),v.jsx(o.Box,{children:`${L({input:d,decimals:null==c?void 0:c.decimals})} ${null==c?void 0:c.symbol}`})]}),v.jsx(o.Box,{sx:{mt:4,typography:"h6",color:w.palette.text.secondary},children:g?`$${D({input:g,showDecimals:1})}`:"-"})]}),v.jsx(o.Box,{sx:{width:16,mx:16},component:r.DoubleRight}),v.jsxs(o.Box,{children:[v.jsxs(o.Box,{sx:{display:"flex"},children:[v.jsx(ze,{width:16,height:16,marginRight:6,url:null==l?void 0:l.logoURI,address:null!==(C=null==l?void 0:l.address)&&void 0!==C?C:""}),v.jsx(o.Box,{children:`${L({input:u,decimals:null==l?void 0:l.decimals})} ${null==l?void 0:l.symbol}`})]}),v.jsx(o.Box,{sx:{typography:"h6",mt:4,color:w.palette.text.secondary},children:x?`$${D({input:x,showDecimals:1})}(${p}%)`:"-"})]})]}),v.jsx(o.Box,{sx:{mt:12,typography:"h6"},children:`1 ${null==c?void 0:c.symbol} = ${L({input:new k.default(u).dividedBy(new k.default(d)),decimals:null==l?void 0:l.decimals})} ${null==l?void 0:l.symbol}`})]}),v.jsxs(o.Box,{sx:{py:15,typography:"body2",borderBottom:`1px solid ${w.palette.border.main}`},children:[v.jsxs(o.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",color:w.palette.text.secondary},children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(o.Box,{sx:{width:16,mr:7},component:r.DetailBorder}),v.jsx(e.Trans,{id:"Swap Detail"})]}),v.jsx(o.Box,{component:o.BaseButton,children:v.jsx(o.Box,{onClick:()=>I(!R),sx:{width:10,color:"text.secondary",transform:R?"rotateX(0deg)":"rotateX(180deg)"},component:r.CaretUp})})]}),v.jsxs(o.Box,{sx:{mt:16,display:R?"initial":"none"},children:[v.jsxs(o.Box,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(e.Trans,{id:"Basic Fee"}),v.jsx(Nt,{title:v.jsx(e.Trans,{id:"Estimated service provider fees"}),ml:5})]}),v.jsx(o.Box,{children:`${L({input:f,decimals:null==l?void 0:l.decimals})} ${null==l?void 0:l.symbol}`})]}),v.jsxs(o.Box,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(e.Trans,{id:"Additional Fee"}),v.jsx(Nt,{title:v.jsx(e.Trans,{id:"Additional routing fees set by the Widget user"}),ml:5})]}),v.jsx(o.Box,{children:`${L({input:y,decimals:null==l?void 0:l.decimals})} ${null==l?void 0:l.symbol}`})]}),v.jsxs(o.Box,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(e.Trans,{id:"Price Impact"}),v.jsx(Nt,{title:v.jsx(e.Trans,{id:"Due to the market condition, market price and estimated price may have a slight difference"}),ml:5})]}),v.jsx(o.Box,{children:`${p}%`})]}),v.jsxs(o.Box,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(e.Trans,{id:"Slippage"}),v.jsx(Nt,{title:v.jsx(e.Trans,{id:"High slippage tolerance will increase the success rate of transaction, but might not get the best quote."}),ml:5})]}),v.jsx(o.Box,{children:j})]})]})]}),v.jsx(o.Box,{sx:{flex:1}}),O&&v.jsxs(o.Box,{sx:{mb:14,display:"flex",cursor:"pointer",justifyContent:"center",alignItems:"center",typography:"h6"},onClick:()=>S(!B),children:[v.jsx(o.Box,{sx:{mr:4,width:18,height:18,alignItems:"center"},children:B?v.jsx(o.Box,{sx:{width:"100%",height:"100%",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"secondary.main"},children:v.jsx(o.Box,{component:r.Done,sx:{width:14,color:"#1a1a1b"}})}):v.jsx(o.Box,{sx:{width:"100%",height:"100%",borderRadius:4,border:`1px solid ${w.palette.text.secondary}`}})}),v.jsx(o.Box,{children:v.jsx(e.Trans,{components:{0:v.jsx(o.Box,{component:"span",sx:{color:"error.main"}})},values:{priceImpact:p},id:"Price impact reaches <0>{priceImpact}</0>%, accept the quote"})})]}),v.jsx(o.Button,{isLoading:A==ee.Pending,disabled:O&&!B,fullWidth:!0,onClick:()=>{n(),T(mt({contractStatus:ee.Pending}))},children:A==ee.Pending?v.jsx(e.Trans,{id:"Confirming"}):v.jsx(e.Trans,{id:"Confirm swap"})})]})})}function Pt(e){var{sx:n,maxVal:s,decimals:a=2,onInputChange:i}=e,r=K(e,["sx","maxVal","decimals","onInputChange"]);return o.useTheme(),v.jsx(o.Input,{...r,onChange:e=>{const n=0===e.target.value.length?null:_(e.target.value,a),o=s&&n&&new t.BigNumber(n).gt(s)?s.toString():n;console.log("finalVal:",o),i&&i(o)}})}function Ft({open:t,onClose:n}){const s=o.useTheme(),r=i.useDispatch(),l=i.useSelector(kt),c=i.useSelector(St),d=a.useMemo((()=>Number(l)>=50),[l]);return v.jsx(Ge,{open:t,onClose:n,title:v.jsx(e.Trans,{id:"Settings"}),children:v.jsxs(o.Box,{sx:{mx:20},children:[v.jsxs(o.Box,{sx:{py:20,borderTop:`1px solid ${s.palette.border.main}`},children:[v.jsxs(o.Box,{sx:{mb:16,display:"flex",alignItems:"center"},children:[v.jsx(e.Trans,{id:"Slippage Tolerance"}),v.jsx(Nt,{title:v.jsx(e.Trans,{id:"Attention: High slippage tolerance will increase the success rate of transaction, but might not get the best quote."}),ml:7})]}),v.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column"},children:[v.jsx(Pt,{fullWidth:!0,maxVal:100,value:l,placeholder:3..toString(),onInputChange:e=>{r((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_SLIPPAGE",payload:e})})))(e))},suffix:v.jsx(o.Box,{sx:{color:"text.disabled"},children:"%"}),height:36}),d&&v.jsx(o.Box,{sx:{typography:"h6",mt:6,color:"error.main"},children:v.jsx(e.Trans,{id:"Maximum slippage do not exceed 50%"})})]})]}),v.jsxs(o.Box,{sx:{py:20,borderTop:`1px solid ${s.palette.border.main}`},children:[v.jsxs(o.Box,{sx:{mb:16,display:"flex",alignItems:"center"},children:[v.jsx(e.Trans,{id:"Transaction Deadline"}),v.jsx(Nt,{title:v.jsx(e.Trans,{id:"If your transaction time exceeds the deadline, your transaction will be rescinded."}),ml:7})]}),v.jsx(Pt,{value:c,fullWidth:!0,height:36,placeholder:E.i18n._("{DEFAULT_SWAP_DDL} minutes",{DEFAULT_SWAP_DDL:20}),onInputChange:e=>{r((e=>t=>G(void 0,void 0,void 0,(function*(){t({type:"SET_TRANSACTION_DDL",payload:e})})))(e?Math.max(Number(e),1):""))}})]})]})})}function Ut({toToken:t,fromToken:n,priceStatus:s,pricePerToToken:i,pricePerFromToken:l}){const[c,d]=a.useState("-"),[u,p]=a.useState(null),[m,h]=a.useState("-"),[f,x]=a.useState(null);a.useEffect((()=>{d(null==n?void 0:n.symbol),h(null==t?void 0:t.symbol),p(i),x(l)}),[n,t,i,l]);const g=a.useCallback((()=>{d(m),h(c),p(f),x(u)}),[c,u,m,f]);return v.jsx(o.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center"},children:{[Rt.Initial]:"-",[Rt.Loading]:v.jsxs(v.Fragment,{children:[v.jsx(o.RotatingIcon,{sx:{mr:5}}),v.jsx(e.Trans,{id:"Fetching best price..."})]}),[Rt.Failed]:v.jsxs(v.Fragment,{children:[v.jsx(o.Box,{component:r.Warn,sx:{width:15,mr:5,color:"warning.main"}}),v.jsx(e.Trans,{id:"Quote not available"})]}),[Rt.Success]:v.jsxs(v.Fragment,{children:[v.jsx(o.Box,{sx:{typography:"body2"},children:`1 ${c} = ${D({input:f,showDecimals:4})} ${m}`}),v.jsx(o.Box,{component:o.BaseButton,sx:{width:18,height:18,ml:6,borderRadius:"50%",backgroundColor:"border.main",display:"flex",justifyContent:"center",alignItems:"center"},children:v.jsx(o.Box,{sx:{width:16,color:"text.secondary"},onClick:g,component:r.Switch})})]})}[s]})}function Wt({open:t,onClose:n}){const s=i.useSelector(re);return v.jsx(Ge,{title:v.jsx(e.Trans,{id:"Connect to your wallet"}),open:t,onClose:n,children:v.jsx(o.Box,{sx:{mx:20,pb:20,border:"1px solid transparent",borderTopColor:"border.main"},children:Object.values(ke).map((t=>v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",flexDirection:"column",mt:20,p:20,backgroundColor:"background.tag",borderRadius:12,cursor:"pointer","&:hover":{backgroundColor:"hover.default"}},onClick:()=>{!function(e,t,n){var o;const s=Se[e];if(!s)throw new Error(`Unknown wallet type: ${e}`);const[a]=s;null===(o=a.activate(t))||void 0===o||o.catch((e=>{4001!==e.code?n(e):a.connectEagerly?a.connectEagerly(t):a.activate(t)}))}(t.type,s,(e=>{console.error(e)}))},children:[v.jsx(o.Box,{component:t.icon,sx:{width:32,height:32}}),v.jsx(o.Box,{sx:{mt:8,typography:"caption"},children:t.name}),v.jsx(o.Box,{sx:{mt:4,typography:"body2",color:"text.secondary"},children:v.jsx(e.Trans,{id:"Connect to your {0} Wallet",values:{0:t.name}})})]},t.type)))})})}function Ht(){const{connector:t}=c.useWeb3React(),[n,s]=a.useState(!1);return v.jsxs(v.Fragment,{children:[v.jsx(o.Button,{size:o.Button.Size.big,fullWidth:!0,onClick:()=>{t.deactivate?t.deactivate():t.resetState(),s(!0)},"data-testid":"connect-wallet-btn",children:v.jsx(e.Trans,{id:"Connect to a wallet"})}),v.jsx(Wt,{open:n,onClose:()=>s(!1)})]})}var $t;!function(e){e.Loading="Loading",e.Insufficient="ApprovalInsufficient",e.Approving="Approving",e.Sufficient="Sufficient",e.Unchecked="Unchecked"}($t||($t={}));const zt=({account:e,chainId:t,offset:n,contractAddress:o})=>{var s;const r=i.useSelector(re),l=a.useMemo((()=>{var e;return pe[null!==(e=t)&&void 0!==e?e:r]}),[t]),{isETH:d}=a.useMemo((()=>U(t)),[t]),{DODO_APPROVE:u}=l||{},p=null!==(s=null!=o?o:u)&&void 0!==s?s:null,m=function(e){const{account:t}=c.useWeb3React(),n=i.useSelector(re),o=i.useSelector(Ne),s=a.useMemo((()=>z[n]),[n]),r=a.useCallback((n=>{var a;if(!t||!e)return null;if(n.symbol===s.symbol&&P(n.address,s.address))return new k.default(pt);const i=null===(a=null==o?void 0:o[n.address.toLowerCase()])||void 0===a?void 0:a.tokenAllowances;return null!=i?i:null}),[t,e,s.symbol,s.address,o]);return r}(p),h=Ue(),{runningRequests:f}=ft(),x=i.useSelector(Fe),g=a.useMemo((()=>{var e;return null===(e=z[null!=t?t:r])||void 0===e?void 0:e.address}),[t]),b=a.useCallback(((t,o,s)=>{if(!t)return $t.Loading;const a=!!(null==f?void 0:f.find((e=>e.spec.opcode===dt.Approval&&e.spec.token.address===(null==t?void 0:t.address)))),i=null!=s?s:t?h(t):null,r=t?m(t):null,l=new k.default(null!=o?o:0);if(!e)return $t.Unchecked;if(!i||l.minus(null!=n?n:0).gt(i))return $t.Unchecked;if(l.isZero())return $t.Unchecked;return t.address===g?$t.Sufficient:a?$t.Approving:r&&l.minus(null!=n?n:0).gt(r)?$t.Insufficient:$t.Sufficient}),[h,m,e,n,p,t,x,f,g]),y=a.useCallback((e=>{const t=e?m(e):null;return("USDT"===(null==e?void 0:e.symbol)||(null==e?void 0:e.address.toLowerCase())==="0x6426e6017968377529487E0ef0aA4E7759724e05".toLowerCase())&&null!==t&&t.gt(0)}),[m]),v=gt(),C=i.useDispatch(),w=a.useCallback(((t,n)=>G(void 0,void 0,void 0,(function*(){if(!p||!e||!t)return;const o=(e=>{let t=e.symbol;return t.indexOf("DLP_")>-1&&(t=t.replace("DLP_","")),t.indexOf("DLP")>-1&&(t=t.replace("DLP","LP")),t})(t),s=n?new k.default(0):void 0,a=n?E.i18n._("Reset"):E.i18n._("Approve");var i;(yield v.execute(`${a} ${o}`,{opcode:dt.Approval,token:t,contract:p,amt:s}))===st.Success&&C((i=null!=s?s:pt,e=>G(void 0,void 0,void 0,(function*(){e({type:"SET_ACCOUNT_ALLOWANCES",payload:i})}))))}))),[p,e,t,v,C]),j=a.useCallback((e=>{const t=new k.default(0);if(!e)return t.toNumber();const n=h(e);if(!n)return t.toNumber();let o=n;const s=d?.1:.02;return g===(null==e?void 0:e.address)&&(o=n.gt(s)?n.minus(s):t),o.toNumber()}),[t,h,d]);return{getApprovalState:b,getPendingRest:y,getMaxBalance:j,submitApprove:w}};function Vt(){var t,s;const l=o.useTheme(),{isInflight:d}=ft(),{chainId:u,account:p}=c.useWeb3React(),m=i.useDispatch(),{isReverseRouting:h}=i.useSelector(Ye),f=i.useSelector(re),x=i.useSelector(Pe),g=i.useSelector(_e),{isETH:b}=a.useMemo((()=>U(u)),[u]),y=a.useMemo((()=>{var e;return null===(e=z[null!=u?u:f])||void 0===e?void 0:e.address}),[u]),[E,C]=a.useState(""),[w,j]=a.useState(""),[T,A]=a.useState(""),[O,B]=a.useState(""),S=a.useMemo((()=>n.debounce((e=>A(e)),1e3)),[]),R=a.useMemo((()=>n.debounce((e=>B(e)),1e3)),[]),[I,N]=a.useState(null),[M,_]=a.useState(null),[P,F]=a.useState(!1),[H,$]=a.useState(!1),{toFiatPrice:V,fromFiatPrice:q}=Bt({chainId:u,toToken:M,fromToken:I}),K=Ue(),G=a.useMemo((()=>I?K(I):null),[I,K]);a.useMemo((()=>M?K(M):null),[M,K]);const{getApprovalState:Y,submitApprove:X,getPendingRest:Z,getMaxBalance:Q}=zt({account:p,chainId:u}),J=a.useMemo((()=>Z(h?M:I)),[null==I?void 0:I.address,null==M?void 0:M.address,Z,h]),{marginAmount:ee}=Tt({token:h?M:I,fiatPrice:h?V:q}),{resAmount:te,priceImpact:ne,executeSwap:oe,baseFeeAmount:se,additionalFeeAmount:ae,resPricePerToToken:ie,resPricePerFromToken:le,status:ce}=It({toToken:M,fromToken:I,marginAmount:ee,fromAmount:T,toAmount:O}),de=a.useCallback((e=>{const t=e.toString();C(t),S(t)}),[C,S]),ue=a.useCallback((e=>{const t=e.toString();j(t),R(t)}),[j,R]);a.useEffect((()=>{u&&(_(null),N(null),h?ue(""):de("")),g&&g.chainId===u&&(N(g),g.amount&&(m(mt({isReverseRouting:!1})),de(g.amount))),x&&x.chainId===u&&(_(x),x.amount&&g&&!g.amount&&(m(mt({isReverseRouting:!0})),ue(x.amount)))}),[x,g,u,de,ue]);const pe=a.useCallback((()=>{de(""),ue(""),N(M),_(I)}),[N,M,_,I,de,ue]),me=a.useCallback((e=>h?ue(Q(M)):de(Q(I))),[de,ue,Q,I,M,h]),he=a.useMemo((()=>(100*Number(ne)).toFixed(2)),[ne]),fe=a.useMemo((()=>{const e=h?te:T;return e&&q?new k.default(q).multipliedBy(e):null}),[q,T,h,te]),xe=a.useMemo((()=>{const e=h?O:te;return e&&V?new k.default(V).multipliedBy(e):null}),[V,O,h,te]),ge=a.useMemo((()=>v.jsxs(o.Box,{sx:{display:"flex",fontWeight:600,typography:"body2",alignItems:"center",justifyContent:"center"},children:[v.jsx(Nt,{title:v.jsx(e.Trans,{id:"Due to the market condition, market price and estimated price may have a slight difference"}),mr:8}),v.jsxs(o.Box,{sx:{display:"flex"},children:[v.jsx(e.Trans,{id:"Current price impact"}),v.jsxs(o.Box,{sx:{color:l.palette.error.main,ml:4},children:[he,"%"]})]})]})),[he]),be=a.useMemo((()=>v.jsx(Ut,{toToken:M,fromToken:I,priceStatus:ce,pricePerToToken:ie,pricePerFromToken:le})),[M,I,ce,ie,le]),ye=a.useMemo((()=>!W[u||1]),[u]),ve=a.useMemo((()=>ce===Rt.Loading?v.jsx(o.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center"},children:v.jsxs(v.Fragment,{children:[v.jsx(o.RotatingIcon,{sx:{mr:5}}),v.jsx(e.Trans,{id:"Fetching best price..."})]})}):ye?v.jsxs(v.Fragment,{children:[v.jsx(o.Box,{component:r.Warn,sx:{mr:6,width:16,color:"warning.main"}}),v.jsx(e.Trans,{id:"Unsupported network - switch to trade"})]}):E&&new k.default(he).gt(15)?ge:be),[ce,be,E,ge,he,ye]),Ee=a.useMemo((()=>h?new k.default(w).gt(0)?L({input:te,decimals:null==I?void 0:I.decimals}):"-":E),[E,w,te,I,h]),Ce=a.useMemo((()=>h?w:new k.default(E).gt(0)?L({input:te,decimals:null==M?void 0:M.decimals}):"-"),[E,w,te,M,h]),we=a.useMemo((()=>{const t=Y(I,h?te||0:T),n=t===$t.Approving,s=t===$t.Insufficient&&!J,a=b?.1:.02,i=y===(null==I?void 0:I.address),r=new k.default(G||0);return p?d?v.jsx(o.Button,{fullWidth:!0,isLoading:!0,disabled:!0,children:v.jsx(e.Trans,{id:"Transaction Pending"})}):I&&M?s?v.jsx(o.Button,{fullWidth:!0,disabled:n,onClick:()=>X(I),children:n?v.jsx(e.Trans,{id:"Approving"}):v.jsx(e.Trans,{id:"Approve"})}):new k.default(h?O:T).gt(0)?ce===Rt.Loading?v.jsx(o.Button,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-fetch-price-btn",children:v.jsx(e.Trans,{id:"Fetching Price..."})}):te?r.lt(h?te:T)||i&&r.lte(a)?v.jsx(o.Button,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-insufficient-balance-btn",children:v.jsx(e.Trans,{id:"Insufficient balance"})}):v.jsx(o.Button,{fullWidth:!0,onClick:()=>F(!0),"data-testid":"swap-review-btn",children:v.jsx(e.Trans,{id:"Review Swap"})}):v.jsx(o.Button,{fullWidth:!0,disabled:!0,children:v.jsx(e.Trans,{id:"Quote not available"})}):v.jsx(o.Button,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-enter-amount-btn",children:v.jsx(e.Trans,{id:"Enter an amount"})}):v.jsx(o.Button,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-select-token-btn",children:v.jsx(e.Trans,{id:"Select Tokens"})}):v.jsx(Ht,{})}),[b,p,O,T,M,te,I,d,oe,J,X,ce,G,Y,y,h]),je=a.useMemo((()=>I&&M?v.jsxs(o.Box,{sx:{display:"flex",alignItems:"center"},children:[v.jsx(ze,{token:I,sx:{width:16,height:16,mr:6}}),`${L({input:h?te:T,decimals:null==I?void 0:I.decimals})} ${I.symbol}`,v.jsx(o.Box,{component:r.DoubleRight,sx:{width:12,height:12,mx:16}}),v.jsx(ze,{token:M,sx:{width:16,height:16,mr:6}}),`${L({input:h?O:te,decimals:null==M?void 0:M.decimals})} ${M.symbol}`]}):v.jsx(o.Box,{})),[I,M,T,O,te,h]);return v.jsxs(v.Fragment,{children:[v.jsxs(o.Box,{sx:{display:"flex",justifyContent:"space-between",typography:"caption",margin:20},children:[v.jsx(e.Trans,{id:"Swap"}),v.jsx(o.Box,{component:o.BaseButton,children:v.jsx(o.Box,{component:r.Setting,onClick:()=>$(!0),sx:{width:19,height:19,color:"text.primary",cursor:"pointer"}})})]}),v.jsxs(o.Box,{sx:{flex:1,padding:"0 20px 20px",overflowY:"auto"},children:[v.jsxs(o.Box,{children:[v.jsx(et,{sx:{mb:4},token:I,amt:Ee,onMaxClick:me,onInputChange:de,onInputFocus:()=>{h&&de(""),m(mt({isReverseRouting:!1}))},showMaxBtn:!h&&!E,occupiedAddrs:[null!==(t=null==M?void 0:M.address)&&void 0!==t?t:""],fiatPriceTxt:fe?`$${D({input:fe,showDecimals:1})}`:"-",onTokenChange:(e,t)=>{if(t)return pe();de(""),ue(""),N(e)},readOnly:h}),v.jsx(Mt,{onClick:pe}),v.jsx(et,{token:M,amt:Ce,onInputChange:ue,onInputFocus:()=>{h||ue(""),m(mt({isReverseRouting:!0}))},occupiedAddrs:[null!==(s=null==I?void 0:I.address)&&void 0!==s?s:""],fiatPriceTxt:xe?`$${D({input:xe,showDecimals:1})}(${he}%)`:"-",onTokenChange:(e,t)=>{if(t)return pe();de(""),ue(""),_(e)},readOnly:!h}),v.jsx(o.Box,{sx:{py:12,display:"flex",typography:"body2",alignItems:"center",justifyContent:"center",flexWrap:"wrap"},children:ve})]}),we,v.jsxs(o.Box,{sx:{mt:13,display:"flex",typography:"h6",cursor:"pointer",justifyContent:"center",alignItems:"center",color:l.palette.text.disabled},onClick:()=>window.open("https://app.dodoex.io"),children:[v.jsx(o.Box,{sx:{width:24,typography:"body2",transform:"translate(1px, 2px)","& path":{fill:l.palette.text.disabled}},component:r.Dodo}),v.jsx(e.Trans,{id:"Powered by DODO protocol"})]})]}),v.jsx(_t,{toToken:M,fromToken:I,fromAmount:h?te:T,toAmount:h?O:te,open:P,baseFeeAmount:se,priceImpact:he,additionalFeeAmount:ae,curToFiatPrice:xe,execute:()=>oe(je),clearFromAmt:()=>de(""),clearToAmt:()=>ue(""),curFromFiatPrice:fe,pricePerFromToken:le,onClose:()=>F(!1)}),v.jsx(Ft,{open:H,onClose:()=>$(!1)})]})}exports.InitSwapWidget=function(e){const t=document.getElementById("dodo-swap-widget");A.createRoot(t).render(v.jsx(Lt,{...e,children:v.jsx(Vt,{})}))},exports.SwapWidget=function(e){return v.jsx(Lt,{...e,children:v.jsx(Vt,{})})};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Trans as e,I18nProvider as t}from"@lingui/react";import n,{BigNumber as o}from"bignumber.js";import{chunk as i,debounce as r}from"lodash";import{Box as a,useTheme as s,BaseButton as l,Input as c,SearchInput as d,Button as u,HoverOpacity as p,createTheme as m,ThemeProvider as h,CssBaseline as f,QuestionTooltip as g,RotatingIcon as b}from"@dodoex/components";import{getAddress as y}from"@ethersproject/address";import*as v from"react";import{useState as x,useMemo as E,useCallback as w,useEffect as C,useRef as A,useContext as O,createContext as T}from"react";import{useDispatch as k,useSelector as I,Provider as R}from"react-redux";import{CaretUp as S,Error as L,ErrorWarn as D,DoneBorder as _,ArrowTopRightBorder as N,ArrowBack as B,DoubleRight as P,DetailBorder as F,Done as j,Warn as M,Switch as U,Setting as H,Dodo as W}from"@dodoex/icons";import $ from"identicon.js";import{useWeb3React as V,initializeConnector as z,Web3ReactProvider as K}from"@web3-react/core";import{configureStore as G}from"@reduxjs/toolkit";import{combineReducers as Y}from"redux";import{Contract as q}from"@ethersproject/contracts";import{AddressZero as X}from"@ethersproject/constants";import{defaultAbiCoder as Z,Interface as Q}from"@ethersproject/abi";import{EIP1193 as J}from"@web3-react/eip1193";import{WalletConnect as ee}from"@web3-react/walletconnect";import{MetaMask as te}from"@web3-react/metamask";import{JsonRpcProvider as ne}from"@ethersproject/providers";import{Connector as oe}from"@web3-react/types";import{jsxs as ie,jsx as re,Fragment as ae}from"react/jsx-runtime";import{i18n as se}from"@lingui/core";import{VariableSizeList as le}from"react-window";import{en as ce,zh as de}from"make-plural/plurals";import ue from"axios";import{BigNumber as pe,parseFixed as me}from"@ethersproject/bignumber";import{createRoot as he}from"react-dom/client";function fe({input:e,showDecimals:t=4,showPrecisionDecimals:n=2,showIntegerOnly:i=!1,showDecimalsOnly:r=!1,noGroupSeparator:a=!1}){const s=new o(e);if(s.isNaN())return"-";let l=s.dp(t,o.ROUND_DOWN);return l.eq(0)&&(s.gt(0)||s.lt(0))&&(l=s.sd(null!=n?n:t,o.ROUND_DOWN)),i&&(l=l.integerValue(o.ROUND_DOWN)),r&&(l=l.minus(l.integerValue(o.ROUND_DOWN))),a?l.toFormat({decimalSeparator:".",groupSeparator:"",groupSize:3,secondaryGroupSize:0,fractionGroupSeparator:"",fractionGroupSize:0}):l.toFormat()}function ge({input:e,decimals:t,showPrecisionDecimals:n=2,noGroupSeparator:i}){if(null==e)return"-";const r=new o(e);if(r.isNaN())return"-";return fe({input:r,showDecimals:void 0===t?0:t>6?6:t>4?4:t,showPrecisionDecimals:n,noGroupSeparator:i})}function be(e){if("number"==typeof e)return be(new o(e));if(e.isNaN())return"NaN";if(e.isNegative())return`-${be(e.negated())}`;if(e.isZero())return"0";let t=e.integerValue(o.ROUND_FLOOR),n=e.minus(t),i="";for(;!t.isZero();){i=t.modulo(10).toString().toString()+i,t=t.idiv(10)}if(""===i&&(i="0"),n.isZero())return i;i+=".";let r=0;for(;!n.isZero()&&r<100;){const e=n.times(10),t=e.integerValue(o.ROUND_FLOOR);i+=t.toString(),n=e.minus(t),r+=1}return i}const ye=(e,t)=>{if("string"==typeof e&&!e.match(/[-+]?\d+(.+d+)?/))return e;const n=new o(e);if(t){let e=n.toFixed(t,o.ROUND_DOWN);return new o(e).isZero()&&(e=be(n.precision(t,o.ROUND_DOWN))),e}return be(n)},ve=(e,t)=>{let n=e;const o=n.match("[0-9。.]+");n=o&&o.length>0?o[0]:"",n=n.replace("。",".");let i=0;if(n){const e=n.split("."),t=0===e[0].length?["0"]:[e[0]];e.length>1?t[1]=e.slice(1,e.length).join(""):t[0].length>1&&"0"===t[0][0]&&(t[0]=t[0].slice(1,t[0].length)),t.length>1&&(i=t[1].length),n=t.join(".")}return t>=0&&i>t?ye(n,t):n},xe=(e,t)=>{if(0===e.length||0===t.length)return!1;if(t.length===e.length)return e.toLowerCase()===t.toLowerCase();const n=e.substring(2,e.length).toLowerCase(),o=t.substring(2,t.length).toLowerCase();return n.length>o.length?n.endsWith(o):o.endsWith(n)};const Ee=e=>{const t={isMainnet:1===e,isRinkeby:4===e,isGor:5===e};return Object.assign(Object.assign({},t),{isETH:t.isMainnet||t.isRinkeby||t.isGor})};var we;!function(e){e[e.MAINNET=1]="MAINNET",e[e.RINKEBY=4]="RINKEBY",e[e.GOERLI=5]="GOERLI",e[e.BSC=56]="BSC",e[e.HECO=128]="HECO",e[e.POLYGON=137]="POLYGON",e[e.ARBITRUM_ONE=42161]="ARBITRUM_ONE",e[e.ARBITRUM_RINKEBY=421611]="ARBITRUM_RINKEBY",e[e.AURORA=1313161554]="AURORA",e[e.MOONRIVER=1285]="MOONRIVER",e[e.OKCHAIN=66]="OKCHAIN",e[e.OPTIMISM=10]="OPTIMISM",e[e.BOBA=288]="BOBA",e[e.AVALANCHE=43114]="AVALANCHE",e[e.CRONOS=25]="CRONOS"}(we||(we={}));const Ce={[we.MAINNET]:["https://rpc.ankr.com/eth","https://eth-mainnet.public.blastapi.io","https://eth-rpc.gateway.pokt.network","https://main-rpc.linkpool.io"],[we.RINKEBY]:["https://rinkeby-light.eth.linkpool.io/"],[we.GOERLI]:["https://goerli.optimism.io/"],[we.BSC]:["https://bsc-dataseed1.binance.org","https://bsc-dataseed2.binance.org","https://bsc-dataseed3.binance.org","https://bsc-dataseed4.binance.org","https://bsc-dataseed1.defibit.io","https://bsc-dataseed2.defibit.io","https://bsc-dataseed3.defibit.io","https://bsc-dataseed4.defibit.io","https://bsc-dataseed1.ninicoin.io","https://bsc-dataseed2.ninicoin.io","https://bsc-dataseed3.ninicoin.io","https://bsc-dataseed4.ninicoin.io","https://bsc-dataseed.binance.org","https://rpc.ankr.com/bsc","https://bscrpc.com","https://bsc.mytokenpocket.vip","https://binance.nodereal.io","https://rpc-bsc.bnb48.club"],[we.HECO]:["https://http-mainnet.hecochain.com","https://pub001.hg.network/rpc"],[we.POLYGON]:["https://polygon-rpc.com","https://rpc-mainnet.matic.network","https://matic-mainnet.chainstacklabs.com","https://rpc-mainnet.maticvigil.com","https://rpc-mainnet.matic.quiknode.pro","https://matic-mainnet-full-rpc.bwarelabs.com","https://matic-mainnet-archive-rpc.bwarelabs.com","https://poly-rpc.gateway.pokt.network","https://rpc.ankr.com/polygon","https://polygon-mainnet.public.blastapi.io"],[we.ARBITRUM_ONE]:["https://arb1.arbitrum.io/rpc","https://rpc.ankr.com/arbitrum"],[we.ARBITRUM_RINKEBY]:["https://rinkeby.arbitrum.io/rpc"],[we.AURORA]:["https://mainnet.aurora.dev/"],[we.MOONRIVER]:["https://rpc.api.moonriver.moonbeam.network","https://moonriver.api.onfinality.io/rpc?apikey=673e1fae-c9c9-4c7f-a3d5-2121e8274366","https://moonriver.api.onfinality.io/public","https://moonriver.public.blastapi.io"],[we.OKCHAIN]:["https://exchainrpc.okex.org","https://okc-mainnet.gateway.pokt.network/v1/lb/6275309bea1b320039c893ff"],[we.OPTIMISM]:["https://mainnet.optimism.io","https://optimism-mainnet.public.blastapi.io"],[we.BOBA]:["https://mainnet.boba.network","https://boba-mainnet.gateway.pokt.network/v1/lb/623ad21b20354900396fed7f","https://lightning-replica.boba.network"],[we.AVALANCHE]:["https://api.avax.network/ext/bc/C/rpc","https://rpc.ankr.com/avalanche","https://ava-mainnet.public.blastapi.io/ext/bc/C/rpc"],[we.CRONOS]:["https://evm.cronos.org","https://cronos-rpc.heavenswail.one","https://evm-cronos.crypto.org","https://cronosrpc-1.xstaking.sg","https://cronos-rpc.elk.finance"]},Ae={symbol:"ETH",address:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",name:"Ether",decimals:18,showDecimals:4,wrappedTokenSymbol:"WETH"},Oe={[we.MAINNET]:Object.assign(Object.assign({},Ae),{wrappedTokenAddress:"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}),[we.RINKEBY]:Object.assign(Object.assign({},Ae),{wrappedTokenAddress:"0xB26c0d8Be2960c70641A95A9195BE1f59Ac83aC0"}),[we.GOERLI]:Object.assign(Object.assign({},Ae),{wrappedTokenAddress:"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6"}),[we.OPTIMISM]:Object.assign(Object.assign({},Ae),{wrappedTokenAddress:"0x4200000000000000000000000000000000000006"}),[we.CRONOS]:Object.assign(Object.assign({},Ae),{symbol:"CRO",name:"Cronos",wrappedTokenSymbol:"WCRO",wrappedTokenAddress:"0x5C7F8A570d578ED84E63fdFA7b1eE72dEae1AE23"}),[we.BOBA]:Object.assign(Object.assign({},Ae),{wrappedTokenAddress:"0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000"}),[we.BSC]:Object.assign(Object.assign({},Ae),{symbol:"BNB",name:"BNB",wrappedTokenSymbol:"WBNB",wrappedTokenAddress:"0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}),[we.OKCHAIN]:Object.assign(Object.assign({},Ae),{symbol:"OKT",name:"OKT",wrappedTokenSymbol:"WOKT",wrappedTokenAddress:"0x8F8526dbfd6E38E3D8307702cA8469Bae6C56C15"}),[we.HECO]:Object.assign(Object.assign({},Ae),{symbol:"HT",name:"HT",showDecimals:6,wrappedTokenSymbol:"WHT",wrappedTokenAddress:"0x5545153ccfca01fbd7dd11c0b23ba694d9509a6f"}),[we.POLYGON]:Object.assign(Object.assign({},Ae),{symbol:"MATIC",name:"MATIC",showDecimals:6,wrappedTokenSymbol:"WMATIC",wrappedTokenAddress:"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270"}),[we.MOONRIVER]:Object.assign(Object.assign({},Ae),{symbol:"MOVR",name:"MOVR",showDecimals:6,wrappedTokenSymbol:"WMOVR",wrappedTokenAddress:"0x98878b06940ae243284ca214f92bb71a2b032b8a"}),[we.ARBITRUM_ONE]:Object.assign(Object.assign({},Ae),{name:"Ethereum",showDecimals:6,wrappedTokenAddress:"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"}),[we.ARBITRUM_RINKEBY]:Object.assign(Object.assign({},Ae),{name:"Ether",showDecimals:6,wrappedTokenAddress:"0xEBbc3452Cc911591e4F18f3b36727Df45d6bd1f9"}),[we.AURORA]:Object.assign(Object.assign({},Ae),{name:"Ethereum",showDecimals:6,wrappedTokenAddress:"0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB"}),[we.AVALANCHE]:Object.assign(Object.assign({},Ae),{symbol:"AVAX",name:"Avalanche",showDecimals:6,wrappedTokenSymbol:"WAVAX",wrappedTokenAddress:"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7"})},Te={[we.MAINNET]:"ethereum",[we.RINKEBY]:"rinkeby",[we.GOERLI]:"goerli",[we.OPTIMISM]:"optimism",[we.CRONOS]:"cronos",[we.BOBA]:"boba",[we.BSC]:"bsc",[we.OKCHAIN]:"okex-chain",[we.HECO]:"heco",[we.POLYGON]:"polygon",[we.MOONRIVER]:"moonriver",[we.ARBITRUM_ONE]:"arbitrum",[we.ARBITRUM_RINKEBY]:"arb-rinkeby",[we.AURORA]:"aurora",[we.AVALANCHE]:"avalanche"},ke={[we.MAINNET]:"etherscan.io",[we.RINKEBY]:"rinkeby.etherscan.io",[we.GOERLI]:"goerli.etherscan.io",[we.OPTIMISM]:"optimistic.etherscan.io",[we.CRONOS]:"cronoscan.com",[we.BOBA]:"blockexplorer.boba.network",[we.BSC]:"bscscan.com",[we.OKCHAIN]:"www.oklink.com/okexchain",[we.HECO]:"hecoinfo.com",[we.POLYGON]:"polygonscan.com",[we.MOONRIVER]:"moonriver.moonscan.io",[we.ARBITRUM_ONE]:"arbiscan.io",[we.ARBITRUM_RINKEBY]:"testnet.arbiscan.io",[we.AURORA]:"aurorascan.dev",[we.AVALANCHE]:"snowtrace.io"};function Ie(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]])}return n}function Re(e,t,n,o){return new(n||(n=Promise))((function(i,r){function a(e){try{l(o.next(e))}catch(e){r(e)}}function s(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}const Se={colorMode:"dark",slippage:3..toString(),ddl:20};var Le=(e=Se,t)=>{switch(t.type){case"SET_COLOR_MODE":return Object.assign(Object.assign({},e),{colorMode:t.payload});case"SET_SLIPPAGE":return Object.assign(Object.assign({},e),{slippage:t.payload});case"SET_TRANSACTION_DDL":return Object.assign(Object.assign({},e),{ddl:t.payload});default:return e}};const De={chainId:we.MAINNET,latestBlockNumber:0};var _e=(e=De,t)=>{switch(t.type){case"SET_CHAIN_ID":return Object.assign(Object.assign({},e),{chainId:t.payload});case"SET_BLOCK_NUMBER":return Object.assign(Object.assign({},e),{latestBlockNumber:t.payload});default:return e}};const Ne={tokenList:[],popularTokenList:[],ethBalance:void 0,accountBalances:{},balanceLoadings:{},slippageWithTokens:[]};var Be,Pe=(e=Ne,t)=>{switch(t.type){case"SET_TOKEN_LIST":return Object.assign(Object.assign({},e),{tokenList:t.payload});case"SET_POPULAR_TOKEN_LIST":return Object.assign(Object.assign({},e),{popularTokenList:t.payload});case"SET_SLIPPAGE_WITH_TOKENS":return Object.assign(Object.assign({},e),{slippageWithTokens:t.payload});case"SET_ETH_BALANCE":return Object.assign(Object.assign({},e),{ethBalance:t.payload});case"SET_DEFAULT_FROM_TOKEN":return Object.assign(Object.assign({},e),{defaultFromToken:t.payload});case"SET_DEFAULT_TO_TOKEN":return Object.assign(Object.assign({},e),{defaultToToken:t.payload});case"SET_ACCOUNT_BALANCES":return Object.assign(Object.assign({},e),{accountBalances:Object.assign(Object.assign({},e.accountBalances),t.payload)});case"SET_ACCOUNT_ALLOWANCES":const n=e.accountBalances;return Object.keys(n).map((e=>{n[e].tokenAllowances=t.payload})),Object.assign(Object.assign({},e),{accountBalances:n});case"SET_BALANCE_LOADINGS":return Object.assign(Object.assign({},e),{balanceLoadings:Object.assign(Object.assign({},e.balanceLoadings),t.payload)});default:return e}};!function(e){e.Initial="Initial",e.Pending="Pending",e.ApproveSuccess="ApproveSuccess",e.TxSuccess="TxSuccess",e.Failed="Failed"}(Be||(Be={}));const Fe={height:void 0,width:void 0,apikey:"",feeRate:0,rebateTo:"",isReverseRouting:!1,contractStatus:Be.Initial};const je={settings:Se,wallet:De,globals:Fe,token:Ne},Me=G({reducer:Y({settings:Le,wallet:_e,token:Pe,globals:(e=Fe,t)=>"SET_GLOBAL_PROPS"===t.type?Object.assign(Object.assign({},e),t.payload):e}),middleware:e=>e({serializableCheck:{ignoredActions:["SET_ACCOUNT_BALANCES","SET_ETH_BALANCE"],ignoredPaths:["token.accountBalances","token.ethBalance"]}}),preloadedState:je}),Ue=e=>(null!=e?e:Me.getState()).wallet.chainId,He=e=>(null!=e?e:Me.getState()).wallet.latestBlockNumber,We=e=>t=>Re(void 0,void 0,void 0,(function*(){t({type:"SET_ACCOUNT_BALANCES",payload:e})})),$e=e=>t=>Re(void 0,void 0,void 0,(function*(){t({type:"SET_BALANCE_LOADINGS",payload:e})}));var Ve=[{constant:!0,inputs:[],name:"getCurrentBlockTimestamp",outputs:[{name:"timestamp",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{components:[{name:"target",type:"address"},{name:"callData",type:"bytes"}],name:"calls",type:"tuple[]"}],name:"aggregate",outputs:[{name:"blockNumber",type:"uint256"},{name:"returnData",type:"bytes[]"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"getLastBlockHash",outputs:[{name:"blockHash",type:"bytes32"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"addr",type:"address"}],name:"getEthBalance",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"getCurrentBlockDifficulty",outputs:[{name:"difficulty",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"getCurrentBlockGasLimit",outputs:[{name:"gaslimit",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"getCurrentBlockCoinbase",outputs:[{name:"coinbase",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"blockNumber",type:"uint256"}],name:"getBlockHash",outputs:[{name:"blockHash",type:"bytes32"}],payable:!1,stateMutability:"view",type:"function"}],ze={[we.MAINNET]:{MULTI_CALL:"0xeefba1e63905ef1d7acba5a8513c70307c1ce441",DODO_APPROVE:"0xCB859eA579b28e02B87A1FDE08d087ab9dbE5149",ERC20_HELPER:"0xD9ef2d1583e8Aa196123e773BE38B539a4d149df"},[we.RINKEBY]:{MULTI_CALL:"0xb7E1C577f95959a3eD11f9281702850328b4e0e4",DODO_APPROVE:"0xcC8d87A7C747eeE4242045C47Ef25e0A81D56ae3",ERC20_HELPER:"0x6A42091d713A67E25a1D11aeE14E7AEB96E0331f"},[we.GOERLI]:{MULTI_CALL:"0x696E25A5e2AEd1C55E6d6Cfa0532Bbda9020165d",DODO_APPROVE:"0xC9143e54021f4a6d33b9b89DBB9F458AaEdd56FB",ERC20_HELPER:"0x24549FC74B3076A962624A26370ed556c467F74C"},[we.BSC]:{MULTI_CALL:"0x1Ee38d535d541c55C9dae27B12edf090C608E6Fb",DODO_APPROVE:"0xa128Ba44B2738A558A1fdC06d6303d52D3Cef8c1",ERC20_HELPER:"0x566651Ad34f6306872FaC5fB95bbF4C9beE8D8F2"},[we.HECO]:{MULTI_CALL:"0x76a328B3440B9276a31523e731B34082df7a6f1A",DODO_APPROVE:"0x68b6c06Ac8Aa359868393724d25D871921E97293",ERC20_HELPER:"0x270C2abC692Dd476B860CCbDfD6D8146BF61f8D8"},[we.POLYGON]:{MULTI_CALL:"0xc9eD9B18e447e600238fe50e944B9062B664DEa4",DODO_APPROVE:"0x292E6b2e054e1157df71C1C9510265CA8C0c7672",ERC20_HELPER:"0xfd24312Ec7871A6D1a31e454D5AbB16c6c25a9b3"},[we.ARBITRUM_ONE]:{MULTI_CALL:"0xF718F2bd590E5621e53f7b89398e52f7Acced8ca",DODO_APPROVE:"0xA867241cDC8d3b0C07C85cC06F25a0cD3b5474d8",ERC20_HELPER:"0x7C062B9C584fA6eC2504270790D38240A2c5fE72"},[we.ARBITRUM_RINKEBY]:{MULTI_CALL:"0x696E25A5e2AEd1C55E6d6Cfa0532Bbda9020165d",DODO_APPROVE:"0x5BaF16d57620Cb361F622232F3cb4090e35F3da2",ERC20_HELPER:"0x5B2fd46E6E3Ff1E479d651ec0b210882Aa9871dF"},[we.AURORA]:{MULTI_CALL:"0x989DcAA95801C527C5B73AA65d3962dF9aCe1b0C",DODO_APPROVE:"0x335aC99bb3E51BDbF22025f092Ebc1Cf2c5cC619",ERC20_HELPER:"0xE8C9A78725D0451FA19878D5f8A3dC0D55FECF25"},[we.MOONRIVER]:{MULTI_CALL:"0x2ff2CeE6E9359F9eA1cF2f51d18bF9F2045447E4",DODO_APPROVE:"0xE8C9A78725D0451FA19878D5f8A3dC0D55FECF25",ERC20_HELPER:"0x6373ceB657C83C91088d328622573FB766064Ac4"},[we.OKCHAIN]:{MULTI_CALL:"0x5e84190a270333aCe5B9202a3F4ceBf11b81bB01",DODO_APPROVE:"0x7737fd30535c69545deeEa54AB8Dd590ccaEBD3c",ERC20_HELPER:"0x4775b1858f1e417C9609D455C3Ad8751ec01daC4"},[we.OPTIMISM]:{MULTI_CALL:"0xb98Ac2fEFc8b73aeAE33D02BB00c26E12afCa9Df",DODO_APPROVE:"0xa492d6eABcdc3E204676f15B950bBdD448080364",ERC20_HELPER:"0x42E456ea0dd7538ea103fBb1d0388D14C97bB5b2"},[we.BOBA]:{MULTI_CALL:"0xD56281EF996B6B29874C77D2e1464216E8043127",DODO_APPROVE:"0x8F8Dd7DB1bDA5eD3da8C9daf3bfa471c12d58486",ERC20_HELPER:"0x9FCFD9ff955D36856F8EE480471B05488C0eB5cA"},[we.AVALANCHE]:{MULTI_CALL:"0x97f0153E7F5749640aDF3Ff9CFC518b79D6Fe53b",DODO_APPROVE:"0xCFea63e3DE31De53D68780Dd65675F169439e470",ERC20_HELPER:"0xC3528D128CC227fd60793007b5e3FdF7c2945282"},[we.CRONOS]:{MULTI_CALL:"0x4f4408D78F9E9e242c17C635FbD0f1952951c917",DODO_APPROVE:"0x9B736bB8f336f61E16454DCA4dE130703D151042",ERC20_HELPER:"0xbd2F5c60cf7d60daD2106ceD4D21b90722761f14"}};function Ke(e,t,...n){return Re(this,void 0,void 0,(function*(){const o=[];for(const e of n)for(const t of e)t.callData&&o.push(t.callData);const i=yield function(e,t,n){return Re(this,void 0,void 0,(function*(){const o=yield Ge(e,t,n),i=new Map;for(const{req:e,resp:t}of o)i.set(e,t);return e.map((e=>({req:e,resp:i.get(e)})))}))}(o,e,t),r=new Map;for(const{req:e,resp:t}of i)r.set(e,null==t?void 0:t.result);return n.map((e=>e.filter((e=>!e.callData||r.get(e.callData))).map(((e,t)=>e.processor(e.callData?r.get(e.callData):null,t)))))}))}function Ge(e,t,n){return Re(this,void 0,void 0,(function*(){let o=[e];e.length>800&&(o=i(e,800));let r=[];const a=o.map((e=>Re(this,void 0,void 0,(function*(){const o=e.map((e=>[e.to,e.data])),i={data:t.interface.encodeFunctionData("aggregate",[o]),to:n};let a;try{a=yield t.provider.call(i)}catch(o){const i=e.length;if(i>20){const o=Math.floor(i/2),[a,s]=yield Promise.all([Ge(e.slice(0,o),t,n),Ge(e.slice(o,i),t,n)]);r=[...r,...a,...s]}else{const e="[sendCallReqs] error";console.error(e,o)}}if(void 0===a)throw new Error("Unexpected batch result");const[s,l]=Z.decode(["uint256","bytes[]"],a);if(e.length!==l.length)throw new Error("Unexpected length mismatch");return l.map(((t,n)=>({resp:{result:t},req:e[n]})))}))));return(yield Promise.allSettled(a)).filter((e=>"fulfilled"===e.status)).forEach((({value:e})=>{r=[...r,...e]})),r}))}function Ye(e,t,n,o){if(!function(e){try{return y(e)}catch(e){return!1}}(e)||e===X)throw Error(`Invalid 'address' parameter '${e}'.`);return new q(e,t,function(e,t){return t?function(e,t){return e.getSigner(t).connectUnchecked()}(e,t):e}(n,o))}function qe(){const{provider:e,account:t,chainId:n}=V(),[o,i]=x(!1),r=E((()=>ze[n]),[n]),a=w(((n,o)=>{if(e)return Ye(n,o,e,t)}),[e,t]),s=w((e=>{if(!r)return;const{MULTI_CALL:t}=r,n=a(t,Ve);return(()=>Re(this,void 0,void 0,(function*(){if(n){i(!0);try{const[o]=yield Ke(n,t,e);return o}catch(e){console.error("Contract: useMultiContract is error",e)}i(!1)}})))()}),[r,a]);return{getContract:a,contractConfig:r,call:s,loading:o}}var Xe=[{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"isERC20",outputs:[{internalType:"bool",name:"isOk",type:"bool"},{internalType:"string",name:"symbol",type:"string"},{internalType:"string",name:"name",type:"string"},{internalType:"uint256",name:"decimals",type:"uint256"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"allownance",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"judgeERC20",outputs:[{internalType:"string",name:"symbol",type:"string"},{internalType:"string",name:"name",type:"string"},{internalType:"uint256",name:"decimals",type:"uint256"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"allownance",type:"uint256"}],stateMutability:"view",type:"function"}];function Ze(){const{provider:e,account:t}=V(),o=k(),i=I(He);C((()=>{(()=>{Re(this,void 0,void 0,(function*(){if(!e||!t)return;const i=yield e.getBalance(t);o((e=>t=>Re(void 0,void 0,void 0,(function*(){t({type:"SET_ETH_BALANCE",payload:e})})))(new n(i.toString()).div(1e18)))}))})()}),[e,t,o,i])}function Qe(){const{provider:e,chainId:t}=V(),n=k();C((()=>{const o=e=>{n((e=>t=>Re(void 0,void 0,void 0,(function*(){t({type:"SET_BLOCK_NUMBER",payload:e})})))(e))};return(()=>{Re(this,void 0,void 0,(function*(){if(!e||!t)return;const n=yield e.getBlockNumber();o(n),e.on("block",o)}))})(),()=>{null==e||e.off("block",o)}}),[e,n,t])}function Je(e){return Number.parseInt(e,16)}class et extends oe{constructor(e,t){super(e),this.customProvider=t,t.on("connect",(({chainId:e})=>{this.actions.update({chainId:Je(e)})})).on("disconnect",(e=>{var t;null===(t=this.onError)||void 0===t||t.call(this,e),this.actions.resetState()})).on("chainChanged",(e=>{this.actions.update({chainId:Je(e)})})).on("accountsChanged",(e=>{this.actions.update({accounts:e})}))}activate(){return Re(this,void 0,void 0,(function*(){this.actions.startActivation();const e=this.customProvider;try{const[{chainId:t},n]=yield Promise.all([e.getNetwork(),e.listAccounts()]);this.actions.update({chainId:t,accounts:n})}catch(e){throw this.actions.resetState(),e}}))}}function tt([e,t]){return[e,t]}var nt;function ot(){return ot=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},ot.apply(this,arguments)}var it,rt;function at(){return at=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},at.apply(this,arguments)}var st;!function(e){e.INTEGRATOR="integrator",e.METAMASK="metamask",e.WALLET_CONNECT="walletConnect"}(st||(st={}));const lt={[st.METAMASK]:{name:"MetaMask",type:st.METAMASK,icon:function(e){return v.createElement("svg",ot({height:355,viewBox:"0 0 397 355",width:397,xmlns:"http://www.w3.org/2000/svg"},e),nt||(nt=v.createElement("g",{fill:"none",fillRule:"evenodd",transform:"translate(-1 -1)"},v.createElement("path",{d:"m114.622644 327.195472 52.004717 13.810198v-18.05949l4.245283-4.249292h29.716982v21.246459 14.872523h-31.839624l-39.268868-16.997169z",fill:"#cdbdb2"}),v.createElement("path",{d:"m199.528305 327.195472 50.943397 13.810198v-18.05949l4.245283-4.249292h29.716981v21.246459 14.872523h-31.839623l-39.268868-16.997169z",fill:"#cdbdb2",transform:"matrix(-1 0 0 1 483.96227 0)"}),v.createElement("path",{d:"m170.872644 287.889523-4.245283 35.056657 5.306604-4.249292h55.18868l6.367925 4.249292-4.245284-35.056657-8.490565-5.311615-42.452832 1.062323z",fill:"#393939"}),v.createElement("path",{d:"m142.216984 50.9915022 25.471698 59.4900858 11.674528 173.158643h41.391511l12.735849-173.158643 23.349056-59.4900858z",fill:"#f89c35"}),v.createElement("path",{d:"m30.7783023 181.657226-29.71698153 86.048161 74.29245393-4.249293h47.7594343v-37.181303l-2.122641-76.487253-10.613208 8.498583z",fill:"#f89d35"}),v.createElement("path",{d:"m87.0283032 191.218134 87.0283028 2.124646-9.551886 44.617563-41.391511-10.623229z",fill:"#d87c30"}),v.createElement("path",{d:"m87.0283032 192.280457 36.0849058 33.994334v33.994334z",fill:"#ea8d3a"}),v.createElement("path",{d:"m123.113209 227.337114 42.452831 10.623229 13.79717 45.679888-9.551886 5.311615-46.698115-27.620398z",fill:"#f89d35"}),v.createElement("path",{d:"m123.113209 261.331448-8.490565 65.864024 56.25-39.305949z",fill:"#eb8f35"}),v.createElement("path",{d:"m174.056606 193.34278 5.306604 90.297451-15.919812-46.211049z",fill:"#ea8e3a"}),v.createElement("path",{d:"m74.2924539 262.393771 48.8207551-1.062323-8.490565 65.864024z",fill:"#d87c30"}),v.createElement("path",{d:"m24.4103777 355.878193 90.2122663-28.682721-40.3301901-64.801701-73.23113313 5.311616z",fill:"#eb8f35"}),v.createElement("path",{d:"m167.688682 110.481588-45.636793 38.243627-35.0235858 42.492919 87.0283028 3.186969z",fill:"#e8821e"}),v.createElement("path",{d:"m114.622644 327.195472 56.25-39.305949-4.245283 33.994334v19.121813l-38.207548-7.43626z",fill:"#dfcec3"}),v.createElement("path",{d:"m229.245286 327.195472 55.18868-39.305949-4.245283 33.994334v19.121813l-38.207548-7.43626z",fill:"#dfcec3",transform:"matrix(-1 0 0 1 513.679252 0)"}),v.createElement("path",{d:"m132.665096 212.464593-11.674528 24.433427 41.39151-10.623229z",fill:"#393939",transform:"matrix(-1 0 0 1 283.372646 0)"}),v.createElement("path",{d:"m23.349057 1.06232296 144.339625 109.41926504-24.410378-59.4900858z",fill:"#e88f35"}),v.createElement("path",{d:"m23.349057 1.06232296-19.10377392 58.42776294 10.61320772 63.7393781-7.42924541 4.249292 10.61320771 9.560906-8.49056617 7.436261 11.67452847 10.623229-7.4292454 6.373938 16.9811323 21.246459 79.5990577-24.433428c38.915096-31.161473 58.018869-47.096318 57.311322-47.804533-.707548-.708215-48.820756-37.1813036-144.339625-109.41926504z",fill:"#8e5a30"}),v.createElement("g",{transform:"matrix(-1 0 0 1 399.056611 0)"},v.createElement("path",{d:"m30.7783023 181.657226-29.71698153 86.048161 74.29245393-4.249293h47.7594343v-37.181303l-2.122641-76.487253-10.613208 8.498583z",fill:"#f89d35"}),v.createElement("path",{d:"m87.0283032 191.218134 87.0283028 2.124646-9.551886 44.617563-41.391511-10.623229z",fill:"#d87c30"}),v.createElement("path",{d:"m87.0283032 192.280457 36.0849058 33.994334v33.994334z",fill:"#ea8d3a"}),v.createElement("path",{d:"m123.113209 227.337114 42.452831 10.623229 13.79717 45.679888-9.551886 5.311615-46.698115-27.620398z",fill:"#f89d35"}),v.createElement("path",{d:"m123.113209 261.331448-8.490565 65.864024 55.18868-38.243626z",fill:"#eb8f35"}),v.createElement("path",{d:"m174.056606 193.34278 5.306604 90.297451-15.919812-46.211049z",fill:"#ea8e3a"}),v.createElement("path",{d:"m74.2924539 262.393771 48.8207551-1.062323-8.490565 65.864024z",fill:"#d87c30"}),v.createElement("path",{d:"m24.4103777 355.878193 90.2122663-28.682721-40.3301901-64.801701-73.23113313 5.311616z",fill:"#eb8f35"}),v.createElement("path",{d:"m167.688682 110.481588-45.636793 38.243627-35.0235858 42.492919 87.0283028 3.186969z",fill:"#e8821e"}),v.createElement("path",{d:"m132.665096 212.464593-11.674528 24.433427 41.39151-10.623229z",fill:"#393939",transform:"matrix(-1 0 0 1 283.372646 0)"}),v.createElement("path",{d:"m23.349057 1.06232296 144.339625 109.41926504-24.410378-59.4900858z",fill:"#e88f35"}),v.createElement("path",{d:"m23.349057 1.06232296-19.10377392 58.42776294 10.61320772 63.7393781-7.42924541 4.249292 10.61320771 9.560906-8.49056617 7.436261 11.67452847 10.623229-7.4292454 6.373938 16.9811323 21.246459 79.5990577-24.433428c38.915096-31.161473 58.018869-47.096318 57.311322-47.804533-.707548-.708215-48.820756-37.1813036-144.339625-109.41926504z",fill:"#8e5a30"})))))},link:"https://metamask.io"},[st.WALLET_CONNECT]:{name:"WalletConnect",type:st.WALLET_CONNECT,icon:function(e){return v.createElement("svg",at({height:512,viewBox:"0 0 512 512",width:512,xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink"},e),it||(it=v.createElement("radialGradient",{id:"a",cx:"0%",cy:"50%",r:"100%"},v.createElement("stop",{offset:0,stopColor:"#5d9df6"}),v.createElement("stop",{offset:1,stopColor:"#006fff"}))),rt||(rt=v.createElement("g",{fill:"none",fillRule:"evenodd"},v.createElement("path",{d:"m256 0c141.384896 0 256 114.615104 256 256s-114.615104 256-256 256-256-114.615104-256-256 114.615104-256 256-256z",fill:"url(#a)"}),v.createElement("path",{d:"m64.6917558 37.7088298c51.5328072-50.2784397 135.0839942-50.2784397 186.6167992 0l6.202057 6.0510906c2.57664 2.5139218 2.57664 6.5897948 0 9.1037177l-21.215998 20.6995759c-1.288321 1.2569619-3.3771 1.2569619-4.665421 0l-8.534766-8.3270205c-35.950573-35.0754962-94.237969-35.0754962-130.188544 0l-9.1400282 8.9175519c-1.2883217 1.2569609-3.3771016 1.2569609-4.6654208 0l-21.2159973-20.6995759c-2.5766403-2.5139229-2.5766403-6.5897958 0-9.1037177zm230.4934852 42.8089117 18.882279 18.4227262c2.576627 2.5139103 2.576642 6.5897593.000032 9.1036863l-85.141498 83.070358c-2.576623 2.513941-6.754182 2.513969-9.33084.000066-.00001-.00001-.000023-.000023-.000033-.000034l-60.428256-58.957451c-.64416-.628481-1.68855-.628481-2.33271 0-.000004.000004-.000008.000007-.000012.000011l-60.4269683 58.957408c-2.5766141 2.513947-6.7541746 2.51399-9.3308408.000092-.0000151-.000014-.0000309-.000029-.0000467-.000046l-85.14386774-83.071463c-2.57663928-2.513921-2.57663928-6.589795 0-9.1037163l18.88231264-18.4226955c2.5766393-2.5139222 6.7541993-2.5139222 9.3308397 0l60.4291347 58.9582758c.6441608.62848 1.6885495.62848 2.3327103 0 .0000095-.000009.0000182-.000018.0000277-.000025l60.4261065-58.9582508c2.576581-2.51398 6.754142-2.5140743 9.33084-.0002103.000037.0000354.000072.0000709.000107.0001063l60.429056 58.9583548c.644159.628479 1.688549.628479 2.332709 0l60.428079-58.9571925c2.57664-2.5139231 6.754199-2.5139231 9.330839 0z",fill:"#fff",fillRule:"nonzero",transform:"translate(98 160)"}))))}}},ct={};function dt({provider:e,jsonRpcUrlMap:t,defaultChainId:n}){const o=console.error,i=E((()=>function(e,t){if(t){if(ne.isProvider(t))return tt(z((e=>new et(e,t))));if(ne.isProvider(t.provider))throw new Error("Eip1193Bridge is experimental: pass your ethers Provider directly");return tt(z((n=>new J({actions:n,provider:t,onError:e}))))}}(o,e)),[o,e]),r=E((()=>function(e){return tt(z((t=>new te({actions:t,onError:e}))))}(o)),[o]),a=E((()=>t?Object.assign(Object.assign({},Ce),t):Ce),[t]),s=E((()=>function(e,t,n,o){return tt(z((i=>new ee({actions:i,options:{rpc:t,qrcode:e},onError:o,defaultChainId:n}))))}(!0,a,n,o)),[a,n,o]);return i&&(ct[st.INTEGRATOR]=i),ct[st.METAMASK]=r,ct[st.WALLET_CONNECT]=s,Object.values(ct)}function ut(){const{chainId:e}=V(),t=I(Ue);return E((()=>e||t||1),[e,t])}function pt({tokenList:e,popularTokenList:t}){const o=k(),[i,r]=x([]),{account:a}=V(),s=ut(),l=I(He),c=E((()=>(null==t?void 0:t.filter((e=>e.chainId===s)))||[]),[t,s]);!function({tokenList:e,addresses:t,blockNumber:o}){const{account:i}=V(),r=k(),a=E((()=>[...(null==e?void 0:e.map((e=>e.address)))||[],...t||[]].map((e=>e.toLocaleLowerCase()))),[e,t]),{getContract:s,contractConfig:l,call:c}=qe(),[d,u]=x(),p=E((()=>{if(!i||!a.length||!l)return;const{DODO_APPROVE:e,ERC20_HELPER:t}=l,o=s(t,Xe);if(!o)return;let c={};const d=a.map((r=>(c[r]=!0,{callData:{data:o.interface.encodeFunctionData("isERC20",[r,i,e]),to:t},processor:e=>{const t=new Q(Xe).decodeFunctionResult("isERC20",e),{balance:o,isOk:i}=t,a=parseInt(t.decimals),s=new n(10).pow(a),l=new n(t.allownance.toString()).div(s);return i?{address:r,decimals:a,symbol:t.symbol,name:t.name,balance:new n(o.toString()).div(s),allowance:l}:{address:r,balance:new n(0),allowance:new n(0)}}})));return r($e(c)),d}),[i,s,a]);C((()=>{(()=>{Re(this,void 0,void 0,(function*(){if(!p)return;const e=yield c(p),t={};e&&(e.forEach((e=>{t[e.address.toLocaleLowerCase()]={tokenBalances:e.balance,tokenAllowances:e.allowance}})),r(We(t))),u(e);let n={};a.forEach((e=>{n[e]=!1})),r($e(n))}))})()}),[p,o])}({addresses:E((()=>{const e=i.map((({address:e})=>e));return null==t||t.forEach((({address:t})=>{e.includes(t)||e.push(t)})),e}),[i,t]),blockNumber:l}),C((()=>{(()=>{Re(this,void 0,void 0,(function*(){let t=[];if(e)t=e;else{t=(yield import("./tokenList-4ef211de.js")).default}const n=s,i=t.filter((e=>e.chainId===n));r(i),o((e=>t=>Re(void 0,void 0,void 0,(function*(){t({type:"SET_TOKEN_LIST",payload:e})})))(i))}))})()}),[e,o,s]),C((()=>{o(We({}))}),[a,s]),C((()=>{o((e=>t=>Re(void 0,void 0,void 0,(function*(){t({type:"SET_POPULAR_TOKEN_LIST",payload:e})})))(c))}),[c,o])}const mt=e=>(null!=e?e:Me.getState()).token.tokenList,ht=e=>(null!=e?e:Me.getState()).token.accountBalances,ft=e=>(null!=e?e:Me.getState()).token.ethBalance||new n(NaN),gt=e=>(null!=e?e:Me.getState()).token.defaultFromToken,bt=e=>(null!=e?e:Me.getState()).token.defaultToToken,yt=e=>(null!=e?e:Me.getState()).token.balanceLoadings;function vt(){const{account:e,chainId:t}=V(),n=I(ht),o=I(ft),i=E((()=>Oe[t||1]),[t]),r=w((t=>{var r;if(!e)return null;if(t.symbol===i.symbol&&xe(t.address,i.address))return!o||(null==o?void 0:o.isNaN())?null:o;const a=null===(r=n[t.address.toLocaleLowerCase()])||void 0===r?void 0:r.tokenBalances;return!a||(null==a?void 0:a.isNaN())?null:a}),[n,o,e]);return r}var xt;function Et(e,t,n,o=0){if(n&&(e=e.toLocaleLowerCase(),t=t.toLocaleLowerCase()),e===t)return xt.fully+o;const i=e.indexOf(t);return 0===i?xt.prefix+o:i>0?xt.other+o:xt.none}!function(e){e[e.fully=1]="fully",e[e.prefix=2]="prefix",e[e.other=3]="other",e[e.none=0]="none"}(xt||(xt={}));function wt({value:e,onChange:t,occupiedAddrs:o,hiddenAddrs:i,showAddrs:r}){const[a,s]=x(""),l=I(mt),c=ut(),d=vt(),u=E((()=>new Set(i?i.map((e=>e.toLowerCase())):void 0)),[i]),p=E((()=>r?new Set(r.map((e=>e.toLowerCase()))):void 0),[r]),m=w((e=>e.filter((e=>{if(e.chainId!==c)return!1;let t=!0;return t=p?p.has(e.address.toLowerCase()):!u.has(e.address.toLowerCase()),t}))),[p,c,u]),h=w((t=>{if(null===t)return null;const i=[];a?t.forEach((e=>{const t=((e,t,{matchAddress:n}={})=>{if(!t)return 0;const o=t.toLocaleLowerCase();let i=0;n&&e.address.toLocaleLowerCase()===o&&(i=1),i||(i=Et(e.symbol.toLocaleLowerCase(),o,!1,1));if(i)e.name.toLocaleLowerCase()===o&&(i=xt.fully+1);else{let t=Et(e.name.toLocaleLowerCase(),o,!1,10);t=t===xt.fully+10?xt.fully+1:t,i=t}return i})(e,a,{matchAddress:!0});t&&i.push({sort:t,token:e})})):t.forEach((e=>{i.push({sort:0,token:e})}));const r=[];return i.sort(((t,i)=>{const r=t.token,a=i.token;if(e){if(r.address===e.address)return-1;if(a.address===e.address)return 1}if(null==o?void 0:o.includes(r.address))return-1;if(null==o?void 0:o.includes(a.address))return 1;const s=d&&d(r)||new n(0),l=d&&d(a)||new n(0);return s.eq(l)?t.sort!==i.sort?t.sort>i.sort?1:-1:r.symbol.localeCompare(a.symbol):s.gt(l)?-1:1})).some((e=>!!(a&&r.length>21)||(r.push(e.token),!1))),r}),[a,d,o,e]),f=w((e=>{const n=e.address.toLowerCase();t(e,!!(null==o?void 0:o.some((e=>e.toLowerCase()===n))))}),[t,o]),g=E((()=>{const e=m(l);return h(e)||[]}),[l,m,h]);return{filter:a,setFilter:s,showTokenList:g,onSelectToken:f}}function Ct({width:e=24,height:t=24,marginRight:n=8,url:o,zIndex:i,cross:r,address:s,token:l,sx:c}){const[d,u]=x(!1),[p,m]=x(""),[h,f]=x(""),[g,b]=x(!1),y=w((()=>u(!0)),[]);let v=function(e){const t=I(mt),{chainId:n}=V();return E((()=>{if(!e)return;let o=t.find((({address:t,chainId:o})=>o===n&&t===e));return o||(o=t.find((({address:t})=>t===e))),o}),[e,t,n])}(s);l&&(v=l);const A=s||(null==v?void 0:v.address),O=null==v?void 0:v.symbol,T=null==O?void 0:O.charAt(0).toUpperCase(),k=E((()=>{const e=null==v?void 0:v.logoURI;return o||e||""}),[o,v]);return C((()=>{b(!1)}),[A,k]),C((()=>{r&&(k?function(e,t){const n=new XMLHttpRequest;let o;n.onload=function(){const e=new FileReader;e.onloadend=function(){t(e.result)},e.readAsDataURL(n.response)},n.onerror=function(){t()};try{o=new URL(e)}catch(e){}finally{n.open("GET",o||e),n.responseType="blob",n.send()}}(k,(e=>{m(e)})):m(""))}),[k,r]),C((()=>{try{let t=A;if(t&&t.length<15&&(t=t.padEnd(15,"0")),t){const n=new $(t,{size:e,format:"svg",margin:.2,background:[255,234,4,255]}).toString();f(`data:image/svg+xml;base64,${n}`)}}catch(e){console.error("generate Identicon error: ",e)}}),[A,e]),ie(a,{sx:Object.assign({position:"relative",display:"flex",alignItems:"center",justifyContent:"center",minWidth:e,width:e,height:t,marginRight:n,zIndex:i},c||{}),style:{width:e,height:t},children:[!d&&re(a,{sx:{typography:"ht",height:"100%",width:"100%",borderRadius:"50%",border:"transparent 2px solid",borderColor:"text.primary",color:"text.primary",display:"flex",alignItems:"center",justifyContent:"center"},children:T}),re(a,{component:"img",src:!(r?p:k)||g?h:r?p:k,onLoad:y,onError:e=>{const t=e.target;A&&h&&b(!0),t.onerror=null},sx:{position:"absolute",top:"0",bottom:"0",left:"0",right:"0",borderRadius:"50%",overflow:"hidden",width:"100%",height:"100%"}})]})}function At({token:t,onClick:n}){var o,i;const r=s();return ie(a,{component:l,sx:{display:"flex",alignItems:"center",color:r.palette.text.primary,typography:"h5",fontWeight:600},onClick:e=>{n&&n(e)},"data-testid":"swap-select-token-btn",children:[(null==t?void 0:t.address)?ie(ae,{children:[re(Ct,{address:null!==(o=null==t?void 0:t.address)&&void 0!==o?o:"",marginRight:6}),re(a,{children:null!==(i=null==t?void 0:t.symbol)&&void 0!==i?i:"-"})]}):re(e,{id:"SELECT TOKEN"}),re(a,{sx:{ml:7,width:12,transform:"rotateX(180deg)"},component:S})]})}function Ot({onClick:t,balance:n,decimals:o,address:i,showMaxBtn:r}){const{palette:c}=s();return ie(a,{sx:{display:"flex",typography:"body2",color:c.text.secondary},children:[re(e,{id:"Balance:"})," ",i?ge({input:n,decimals:Math.min(o||4,4)}):"-",r&&n&&n.gt(0)&&re(a,{component:l,sx:{ml:6,color:(null==n?void 0:n.gt(0))?c.primary.main:c.text.disabled,cursor:i&&t?"pointer":"unset"},onClick:()=>t&&t(n?n.toString():""),children:re(e,{id:"Max"})})]})}function Tt({readOnly:e,sx:t,value:n,decimals:o,onChange:i,suffix:r,withClear:d,onFocus:u,placeholder:p}){const m=s(),h=E((()=>r||(d&&n&&i?re(a,{component:l,sx:{ml:5,width:18,height:18,borderRadius:"50%",backgroundColor:"border.main",display:"flex",justifyContent:"center",alignItems:"center"},onClick:()=>{i&&i("")},children:re(a,{component:L,sx:{width:12,color:"text.primary"}})}):void 0)),[i,r,m.palette.text.primary,n,d]);return ie(a,{sx:Object.assign({mt:12,display:"flex",justifyContent:"space-between",alignItems:"center"},t),"data-testid":"number-input-wrapper",children:[re(c,{fullWidth:!0,value:n,readOnly:e,placeholder:p||"0.00",onFocus:u,onChange:e=>{const t=e.target.value,n=0===t.length?"":ve(t,o);i&&i(n)},sx:{width:"inherit",border:"none","& .MuiInput-input":{fontSize:24,border:"none",outline:"none",height:24,padding:0,color:"text.primary","&::placeholder":{fontSize:24,color:"text.disabled"}}}}),!e&&n&&h]})}function kt({open:e,onClose:t,title:n,rightSlot:o,canBack:i=!0,children:r,height:s,testId:l}){return ie(a,{sx:{position:"absolute",top:e?0:"100%",transition:"top 300ms",zIndex:1,left:0,right:0,bottom:0,display:"flex",flexDirection:"column",backgroundColor:"background.paper",borderRadius:16,height:s},"data-testid":l,"data-active":e?"1":"0",children:[n?ie(a,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:20},children:[re(a,{sx:{display:"flex",alignItems:"center",typography:"caption"},children:n}),o,!o&&i&&re(a,{component:L,sx:{color:"text.secondary",cursor:"pointer"},onClick:t})]}):"",r]})}const It=e=>(null!=e?e:Me.getState()).globals;function Rt({token:e,disabled:t,onClick:n}){return ie(a,{sx:Object.assign({display:"inline-flex",alignItems:"center",p:8,border:"solid 1px",typography:"body2",borderRadius:8},t?{borderColor:"transparent",backgroundColor:"border.disabled",cursor:"auto"}:{borderColor:"border.main",cursor:"pointer","&:hover":{backgroundColor:"hover.default"}}),onClick:()=>{t||n()},children:[re(Ct,{token:e}),e.symbol]})}function St({token:e,disabled:t,style:n,onClick:o}){const i=vt()(e),r=i?fe({input:i}):"";return ie(a,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",typography:"body2",px:6,py:5,borderRadius:8,cursor:t?"auto":"pointer",opacity:t?.5:1,"&:hover":{backgroundColor:"hover.default"}},style:n,onClick:()=>{t||o()},"data-testid":"token-picker-item",children:[ie(a,{sx:{display:"flex",alignItems:"center"},children:[re(Ct,{token:e}),ie(a,{children:[re(a,{sx:{fontWeight:600,textAlign:"left"},children:e.symbol}),re(a,{sx:{mt:4,textAlign:"left"},children:r})]})]}),re(a,{sx:{color:"text.secondary"},children:e.name})]})}function Lt({value:e,onChange:t,occupiedAddrs:n,hiddenAddrs:o,showAddrs:i,visible:r}){var s;const l=ut(),c=I((e=>((e,t)=>(null!=t?t:Me.getState()).token.popularTokenList.filter((({chainId:t})=>e===t)))(l,e))),{showTokenList:u,filter:p,setFilter:m,onSelectToken:h}=wt({value:e,onChange:t,occupiedAddrs:n,hiddenAddrs:o,showAddrs:i}),f=A(null),g=A(null),[b,y]=x(0);C((()=>{r&&f.current&&y(f.current.offsetHeight-34)}),[f,r]);const v=w((({index:t,style:n})=>{const o=!!(null==c?void 0:c.length);if(0===t&&o)return re(a,{sx:{position:"relative",display:"flex",gap:8,flexWrap:"wrap",pb:32,"&::after":{content:'""',position:"absolute",bottom:16,left:0,right:0,height:"1px",backgroundColor:"border.main"}},ref:g,style:Object.assign(Object.assign({},n),{visibility:n.height?"visible":"hidden",height:n.height?n.height:"auto"}),children:c.map((t=>re(Rt,{token:t,disabled:(null==e?void 0:e.address)===t.address,onClick:()=>h(t)},t.address)))});const i=u[o?t-1:t];return re(St,{token:i,disabled:!!e&&e.address===i.address,style:n,onClick:()=>h(i)})}),[u,c,g,e]),E=w((e=>{var t;if(0===e&&(null==c?void 0:c.length)){const e=(null===(t=g.current)||void 0===t?void 0:t.offsetHeight)||0;return e<=52?0:e}return 52}),[g,c]);return ie(a,{sx:{display:"flex",flexDirection:"column",px:20,flex:1},children:[re(d,{fullWidth:!0,height:48,value:p,onChange:e=>m(e.target.value),clearValue:()=>m(""),placeholder:se._("Enter the token symbol or address")}),re(a,{sx:{mt:16,pb:16,flex:1,minHeight:64},ref:f,children:re(le,{height:b,itemCount:u.length+((null==c?void 0:c.length)?1:0),itemSize:E,width:"100%",className:"token-list",children:v},null===(s=g.current)||void 0===s?void 0:s.offsetHeight)})]})}function Dt({open:t,value:n,onClose:o,occupiedAddrs:i,onTokenChange:r}){const{height:a}=I(It);return re(kt,{height:a,open:t,onClose:o,title:re(e,{id:"Select a token"}),testId:"token-picker-wrapper",children:re(Lt,{value:n,visible:t,onChange:r,occupiedAddrs:i})})}function _t({sx:e,amt:t,token:n,readOnly:o,showMaxBtn:i,onMaxClick:r,fiatPriceTxt:l,occupiedAddrs:c,onInputFocus:d,onTokenClick:u,onInputChange:p,onTokenChange:m}){const h=s(),f=vt(),[g,b]=x(!1),y=n?f(n):null;return ie(a,{sx:Object.assign({width:"100%",minHeight:133,padding:20,borderRadius:12,overflow:"hidden",display:"flex",flexDirection:"column",justifyContent:"space-between",backgroundColor:h.palette.background.input},e),children:[ie(a,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[re(At,{token:n,onClick:()=>b(!0)}),re(Ot,{balance:y,onClick:r,showMaxBtn:i,address:null==n?void 0:n.address,decimals:null==n?void 0:n.decimals})]}),re(Tt,{value:t,onFocus:d,onChange:p,readOnly:o,withClear:!0}),re(a,{sx:{mt:4,typography:"body2",color:h.palette.text.secondary},children:l}),re(Dt,{value:n,open:g,occupiedAddrs:c,onClose:()=>{u&&u(),b(!1)},onTokenChange:(e,t)=>{m(e,t),b(!1)}})]})}const Nt={"en-US":ce,"zh-CN":de,pseudo:ce};function Bt({locale:e,children:n}){return C((()=>{(()=>{Re(this,void 0,void 0,(function*(){yield function(e="en-US"){return Re(this,void 0,void 0,(function*(){se.loadLocaleData(e,{plurals:()=>Nt[e]});try{const t=yield import(`./locales/${e}.js`);se.load(e,t.messages||t.default.messages)}catch(e){}se.activate(e)}))}(e)}))})()}),[e]),re(t,{i18n:se,children:n})}var Pt,Ft,jt;!function(e){e[e.Running=0]="Running",e[e.Success=1]="Success",e[e.Failed=2]="Failed",e[e.Warning=3]="Warning"}(Pt||(Pt={})),function(e){e.Canceled="canceled",e.Failed="failed",e.Success="success",e.Submitted="submitted"}(Ft||(Ft={})),function(e){e[e.Failed=0]="Failed",e[e.Success=1]="Success"}(jt||(jt={}));var Mt,Ut=[{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"guy",type:"address"},{name:"wad",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"}];!function(e){e[e.Failed=0]="Failed",e[e.Success=1]="Success",e[e.Warning=2]="Warning"}(Mt||(Mt={}));const Ht=(e,t)=>Re(void 0,void 0,void 0,(function*(){const{value:n,from:o,to:i,data:r}=e,a={from:o,to:i,value:n,data:r};n&&!/^0x0*$/.test(n)||delete a.value;try{return(yield t.estimateGas(a)).add(5e4)}catch(e){t.call(a).then((e=>{if("test"!==process.env.NODE_ENV)throw new Error("Unexpected issue with estimating the gas. Please try again.")})).catch((e=>{if("test"!==process.env.NODE_ENV)throw e}))}return null})),Wt=(e,t)=>Re(void 0,void 0,void 0,(function*(){try{return yield t.getSigner().sendTransaction(e)}catch(e){throw 4001===(null==e?void 0:e.code)?new Error(se._("Transaction rejected.")):e}}));var $t,Vt;!function(e){e.Approval="APPROVAL",e.TX="TX",e.TypedSign="TypedSign"}($t||($t={})),function(e){e.Normal="Normal",e.Privacy="Privacy",e.LimitOrder="LimitOrder",e.RFQ="RFQ"}(Vt||(Vt={}));const zt=new n(2).pow(256).minus(1),Kt=e=>t=>Re(void 0,void 0,void 0,(function*(){t({type:"SET_GLOBAL_PROPS",payload:e})}));function Gt({onTxFail:e,onTxSubmit:t,onTxSuccess:o}={}){const{account:i,provider:r}=V(),a=ut(),[s,l]=x(!1),[c,d]=x(new Map),u=k(),[p,m]=x(null),[h,f]=x(""),[g,b]=x(null),[y,v]=x(!1),[C,A]=x(),O=w(((s,c,p,h=!1,g,y,x,E)=>Re(this,void 0,void 0,(function*(){if(f(""),m(""),!i||!r)throw new Error("Submission: Cannot execute step when the wallet is disconnected");let w,C,O;A((()=>x)),l(!1);try{if(l(!0),c.opcode===$t.Approval)O=yield((e,t,o,i,r,a)=>Re(void 0,void 0,void 0,(function*(){const s=Ye(e,Ut,r,a).interface.encodeFunctionData("approve",[o,i.toFixed()]),l={from:t,to:e,data:s,value:`0x${new n("0").toString(16)}`,gasLimit:void 0},c=yield Ht(l,r);return c&&(l.gasLimit=c),yield Wt(l,r)})))(c.token.address,i,c.contract,c.amt||zt,r,i),w=O.hash,f(w);else{if(c.opcode!==$t.TX)throw new Error(`Op ${c.opcode} not implemented!`);if(""===c.to)throw new Error("Submission: malformed to");if(0===c.data.length)throw new Error("Submission: malformed data");if(0===c.data.indexOf("0x")&&c.data.length<=2)throw new Error("Submission: malformed data");if(C={value:c.value,data:c.data,to:c.to,gasLimit:c.gasLimit,from:i,chainId:a},!C.gasLimit)try{const e=yield Ht(C,r);e&&(C.gasLimit=e)}catch(e){console.debug(e)}if(O=yield Wt(C,r),w=O.hash,f(w),!w)throw new Error(`Unexpected tx: ${w}`)}}catch(t){if(l(!1),b({spec:c,brief:s,subtitle:p}),console.error(t),t.message){u(Kt({contractStatus:Be.Failed}));const n={error:t.message,brief:s};y&&Object.assign(n,y),e&&e(t,y),m(function(e,t){var n;const o=null===(n=Oe[e])||void 0===n?void 0:n.symbol,i=[{error:"insufficient",msg:se._("Insufficient funds - Please retry after depositing more {EtherTokenSymbol} into your wallet",{EtherTokenSymbol:o})},{error:["External Swap execution Failed","Return amount is not enough"],msg:se._("Price impact exceeds the slippage tolerance you set. Try increasing the slippage tolerance.")},{error:"SafeERC20: low-level call failed",msg:se._("SafeERC20: low-level call failed. Please log a Zendesk support ticket or contact the DODO team.")},{error:["User denied","cancel","User rejected","user rejected"],msg:se._("User denied transaction signature.")},{error:["Cannot set properties of undefined (setting 'loadingDefauIts'){\"originalError\":{",'[ethjs-query]while formatting outputs from RPC\'["value":["code":-32000,"message":"header not found"))'],msg:se._("RPC node data exception")},{error:['execution reverted:FORCESTOP ["originalError"'],msg:se._("ForceStop exception")},{error:["replacement transaction underpriced","Gasprice too low","transaction underprice"],msg:se._("Gas price is too low, please adjust in your wallet and try again")},{error:["MINT_INVALID"],msg:se._("No ForceStop access")},{error:["NOT_PHASE_EXE"],msg:se._("Unable to SETTLE during the cooling-off period")},{error:["params specify an EIP-1559transaction but the currentnetwork does not support"],msg:se._("Wallet incompatibility")},{error:["ALREADY_SETTLED"],msg:se._("This CP has been settled by other addrs")},{error:["create RFQ order failed]:LESS_THAN_FEE_LIMIT"],msg:se._("Service update, please wait and try again")}];let r="";return i.some((e=>Array.isArray(e.error)?e.error.some((n=>t.indexOf(n)>-1&&(r=e.msg,!0))):t.indexOf(e.error)>-1&&(r=e.msg,!0))),r||t}(a,t.message))}return Ft.Failed}b({spec:c,brief:s,subtitle:p}),v(!1),l(!1);const T=Object.assign(Object.assign(Object.assign(Object.assign({brief:s},c),C),{tx:w,subtitle:p}),y);u(Kt({contractStatus:Be.Pending})),t&&t(w,T),g&&g();const k={brief:s,spec:c,tx:w,subtitle:p};if(d((e=>e.set(w,[k,Pt.Running]))),h)return Ft.Submitted;if(g&&g(),null==O?void 0:O.wait){const e=yield O.wait(1);if(v(!0),e.status===jt.Success)return"TX"===T.opcode&&u(Kt({contractStatus:Be.TxSuccess})),"APPROVAL"===T.opcode&&u(Kt({contractStatus:Be.ApproveSuccess})),E&&E(w),o&&o(w,T),d((e=>e.set(w,[k,Pt.Success]))),Ft.Success}return v(!0),d((e=>e.set(w,[k,Pt.Failed]))),Ft.Failed}))),[i,a,l,r]),T=E((()=>({execute:O,requests:c,setShowing:b,waitingSubmit:s})),[O,c,b]),I=w((()=>{b(null),C&&(C(),A(void 0))}),[C]);return{showing:g,showingDone:y,transactionTx:h,errorMessage:p,setErrorMessage:m,closeShowing:I,ctxVal:T,requests:c}}function Yt(){const{requests:e}=Xt(),t=[];return null==e||e.forEach((function([e,n]){n===Pt.Running&&t.push(e)})),{runningRequests:t,isInflight:t.length>0}}const qt=T({execute:()=>Promise.resolve(Ft.Canceled),requests:void 0,waitingSubmit:!1});function Xt(){return O(qt)}var Zt;function Qt(){return Qt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},Qt.apply(this,arguments)}var Jt=function(e){return v.createElement("svg",Qt({width:"33px",height:"33px",viewBox:"0 0 33 33",xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink"},e),Zt||(Zt=v.createElement("g",{stroke:"none",strokeWidth:1,fill:"none",fillRule:"evenodd",strokeLinecap:"round",strokeLinejoin:"round"},v.createElement("g",{transform:"translate(-186.000000, -375.000000)",stroke:"currentColor",strokeWidth:4},v.createElement("g",{transform:"translate(18.000000, 291.000000)"},v.createElement("g",{transform:"translate(40.000000, 83.000000)"},v.createElement("path",{d:"M159,32 C159,15.9837423 146.016258,3 130,3"})))))))};function en({showingDone:e,errorMessage:t}){return re(a,t?{component:D,sx:{width:64,height:64,color:"error.main"}}:e?{component:_,sx:{width:64,height:64,color:"success.main"}}:{sx:{mx:"auto",border:e=>{var t;return`6px solid ${null===(t=e.palette)||void 0===t?void 0:t.background.input}`},borderRadius:"50%",width:"64px",height:"64px",position:"relative",animation:"loadingRotate 1.1s infinite linear","@keyframes loadingRotate":{"0%":{transform:"rotate(0deg)"},"100%":{transform:"rotate(359deg)"}}},children:re(a,{component:Jt,sx:{position:"absolute",top:"-6px",right:"-6px",color:"primary.main"}})})}function tn({showingDone:e,showing:t}){return ie(a,{sx:{display:"flex",alignItems:"center",flexDirection:"column"},children:[re(a,{sx:{mt:60},children:e?se._("{0} confirmed",{0:null==t?void 0:t.brief}):se._("{0} pending",{0:null==t?void 0:t.brief})}),(null==t?void 0:t.subtitle)?re(a,{sx:{mt:20,typography:"body2"},children:null==t?void 0:t.subtitle}):""]})}function nn({isStarted:t,isEnded:n,tx:o}){const[i,r]=x(0),{chainId:s}=V(),l=E((()=>`https://${ke[s||1]}/tx/${o}`),[o,s]),c=E((()=>{const e=Math.floor(i/60),t=i%60;return e?`${e}m ${t}s`:`${t}s`}),[i]),d=A();return C((()=>(r(0),d.current=setInterval((()=>{r((e=>e+1))}),1e3),()=>{clearInterval(d.current)})),[t]),C((()=>{clearInterval(d.current)}),[n]),ie(a,{sx:{mt:20,pt:20,display:"flex",justifyContent:"space-between",alignItems:"center",typography:"body2",color:"text.secondary",border:"solid 1px transparent",borderTopColor:"border.main"},children:[ie(a,{children:[re(e,{id:"Transaction Time:"}),c]}),ie(p,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},component:"a",href:l,target:"_blank",rel:"noopener noreferrer",children:[re(e,{id:"Tx"}),re(a,{component:N,sx:{width:16,height:16,ml:6}})]})]})}function on(t){var{children:n}=t,o=Ie(t,["children"]);const{ctxVal:i,showing:r,closeShowing:s,showingDone:l,errorMessage:c,transactionTx:d}=Gt(o),p=k();return ie(qt.Provider,{value:i,children:[n,re(kt,{open:!!r,onClose:s,children:ie(a,{sx:{display:"flex",flexDirection:"column",justifyContent:"space-between",px:20,pb:20,flex:1,overflowY:"auto"},children:[ie(a,{children:[re(a,{sx:{textAlign:"center",pt:60},children:re(en,{showingDone:l,errorMessage:c})}),c?ie(a,{sx:{textAlign:"center",mt:60},children:[re(a,{children:re(e,{id:"Something went wrong."})}),re(a,{sx:{color:"text.secondary",mt:12,typography:"body2",wordBreak:"break-all"},children:c})]}):ie(ae,{children:[re(tn,{showingDone:l,showing:r}),re(nn,{isStarted:!!r,isEnded:l,tx:d})]})]}),re(u,{fullWidth:!0,size:u.Size.big,onClick:()=>{p(Kt({contractStatus:Be.Initial})),s()},sx:{mt:20},children:re(e,c?{id:"Dismiss"}:{id:"Close"})})]})})]})}function rn({token:e,fiatPrice:t}){return{marginAmount:E((()=>{var i;const r=null!==(i=null==e?void 0:e.decimals)&&void 0!==i?i:6,a=((e,t,n)=>{const i=new o(e).times(new o(10).pow(t));return n?i:i.dp(0)})(null!=t?new n(500).div(t):new n(0),r);return(a.lt(new n(1).times(new n(10).pow(r-3)))?new n(0):a).toString(10)}),[null==e?void 0:e.decimals,t])}}function an({width:e,height:t,feeRate:n,rebateTo:o,colorMode:i,apikey:r,defaultChainId:a,defaultToToken:s,defaultFromToken:l}){const c=k();C((()=>{i&&c((e=>t=>Re(void 0,void 0,void 0,(function*(){t({type:"SET_COLOR_MODE",payload:e})})))(i))}),[i]),C((()=>{var e;a&&c((e=a,t=>Re(void 0,void 0,void 0,(function*(){t({type:"SET_CHAIN_ID",payload:e})}))))}),[a]),C((()=>{c(Kt({height:t}))}),[t]),C((()=>{c(Kt({width:e}))}),[e]),C((()=>{r&&c(Kt({apikey:r}))}),[r]),C((()=>{n&&c(Kt({feeRate:n}))}),[n]),C((()=>{o&&c(Kt({rebateTo:o}))}),[o]),C((()=>{l&&c((e=>t=>Re(void 0,void 0,void 0,(function*(){t({type:"SET_DEFAULT_FROM_TOKEN",payload:e})})))(l))}),[l]),C((()=>{s&&c((e=>t=>Re(void 0,void 0,void 0,(function*(){t({type:"SET_DEFAULT_TO_TOKEN",payload:e})})))(s))}),[s])}function sn({refetch:e,interval:t}){let n;C((()=>(e(),clearTimeout(n),n=setInterval((()=>{e()}),null!=t?t:15e3),()=>clearTimeout(n))),[e])}function ln({fromToken:e,toToken:t,chainId:n}){const[o,i]=x(!1),[r,a]=x(""),[s,l]=x(""),c=w((()=>{if(!n||!e||!t)return;i(!0);const o=[e,t];ue.post("https://api.dodoex.io/price-api/api/v1/price/current/batch",{networks:o.map((()=>(e=>Te[e]||Te[we.MAINNET])(n))),addresses:o.map((e=>e.address)),symbols:o.map((e=>e.symbol)),isCache:!0},{headers:{apikey:"dodofrontend777888ofopensource"}}).then((n=>{var o;i(!1);const r=null===(o=n.data)||void 0===o?void 0:o.data;r&&(a(r.find((t=>t.address===e.address)).price),l(r.find((e=>e.address===t.address)).price))})).catch((e=>{i(!1),console.error(e)}))}),[n,e,t]);return sn({refetch:c}),{loading:o,refetch:c,toFiatPrice:s,fromFiatPrice:r}}const cn=e=>(null!=e?e:Me.getState()).settings.slippage,dn=e=>(null!=e?e:Me.getState()).settings.ddl;var un;function pn({toToken:e,fromToken:t,fromAmount:n,toAmount:o,marginAmount:i}){const{account:r,chainId:a,provider:s}=V(),l=I(Ue),c=E((()=>a||l),[a,l]),d=I(cn)||3,u=I(dn)||20,{feeRate:p,rebateTo:m,apikey:h,isReverseRouting:f}=I(It),g=E((()=>Math.floor(Date.now()/1e3)+60*u),[u]),[b,y]=x(un.Initial),[v,C]=x(null),[A,O]=x(""),[T,k]=x(null),[R,S]=x(null),[L,D]=x(null),[_,N]=x(pe.from(0)),[B,P]=x(null),[F,j]=x(null),[M,U]=x(""),[H,W]=x(""),[$,z]=x(""),[K,G]=x(0),Y=w((()=>Re(this,void 0,void 0,(function*(){if(!c||!t||!e)return;if(!f&&!n)return;if(f&&!o)return;y(un.Loading);const i={chainId:c,deadLine:g,apikey:h,slippage:d,source:"dodoV2AndMixWasm",toTokenAddress:e.address,toTokenDecimals:e.decimals,fromTokenAddress:t.address,fromTokenDecimals:t.decimals,userAddr:r||"0x0000000000000000000000000000000000000000"};f?i.toAmount=me(String(o||1),e.decimals).toString():i.fromAmount=me(String(n||1),t.decimals).toString(),m&&p&&(i.rebateTo=m,i.fee=p);try{const e=(yield ue.get("https://api.dodoex.io/route-service/v2/widget/getdodoroute",{params:i})).data.data;if((null==e?void 0:e.resAmount)?(y(un.Success),C(e.resAmount),D(e.priceImpact),P(e.resPricePerFromToken),j(e.resPricePerToToken),k(e.baseFeeAmount),S(e.additionalFeeAmount),U(e.to),W(e.data),O(e.value),z(e.useSource),G(e.duration)):y(un.Failed),!r||!s)return;const t=yield Ht({from:r,to:e.to,value:e.value,data:e.data},s);t&&N(t)}catch(e){y(un.Failed),console.error(e)}}))),[g,r,c,e,p,d,m,t,s,n,o,h,f]);sn({refetch:Y});const q=E((()=>{const e=f?o:n;return b!==un.Loading&&e?v:null}),[b,f,o,n,v]),X=function(){const{chainId:e,account:t}=V(),n=Xt();return w((({to:e,data:o,useSource:i,duration:r,ddl:a,gasLimit:s,subtitle:l,value:c})=>{const d=60*a,u=c;i&&"weth"!==i.toLowerCase()&&s&&s.lt(3e4)&&console.debug("Warning: GasLimit less than the minimum!");const p={from:t,to:e,data:o,value:u,route:i,duration:r,ddlSecRel:d,gasLimit:s};n.execute(se._("Swap"),Object.assign({opcode:$t.TX},p),l)}),[t,e])}(),Z=w((e=>{t&&(f?v:n)&&X({to:M,data:H,useSource:$,duration:K,ddl:u,value:A,subtitle:e})}),[M,u,H,K,$,t,n,_,v,A,f]);return{status:b,refetch:Y,priceImpact:L,executeSwap:Z,baseFeeAmount:T,resAmount:q,additionalFeeAmount:R,resPricePerToToken:F,resPricePerFromToken:B}}!function(e){e.Initial="Initial",e.Loading="Loading",e.Failed="Failed",e.Success="Success"}(un||(un={}));function mn(e){pt(e),Ze(),Qe();const{provider:t,connector:n}=V();C((()=>{const t=e.defaultChainId||1;(null==n?void 0:n.connectEagerly)?n.connectEagerly(t):n.activate(t)}),[n]),C((()=>{const e=null==t?void 0:t.provider;e&&e.once&&e.once("chainChanged",(()=>{setTimeout((()=>{window.location.reload()}),200||100)}))}),[t]);const o=e.width||375,i=e.height||494;return an(Object.assign(Object.assign({},e),{width:o,height:i})),re(a,{sx:{width:o,height:i,overflow:"hidden",position:"relative",display:"flex",flexDirection:"column",minWidth:335,minHeight:494,borderRadius:16,backgroundColor:"background.paper"},className:"dodo-widget-container",children:re(on,{...e,children:e.children})})}function hn(e){const t=m({mode:e.colorMode,theme:e.theme,lang:e.locale||"en-US"}),n=E((()=>e.defaultChainId||1),[e.defaultChainId]),o=dt({provider:e.provider,jsonRpcUrlMap:e.jsonRpcUrlMap,defaultChainId:n}),i=`${o.length}+${e.jsonRpcUrlMap?Object.entries(e.jsonRpcUrlMap):""}+${e.defaultChainId}+${n}`;return re(R,{store:Me,children:re(Bt,{locale:e.locale,children:re(h,{theme:t,children:ie(K,{connectors:o,children:[re(f,{container:".dodo-widget-container"}),re(mn,{...e})]},i)})})})}function fn(e){const{width:t}=I(It),n=E((()=>{let e="";return"number"==typeof t?e=`${t}px`:t&&(e=t),e?`calc(${e} - 40px)`:"auto"}),[t]);return re(g,{container:document.querySelector(".dodo-widget-container"),maxWidth:n,...e})}function gn({onClick:e}){const t=s();return re(p,{sx:{width:"100%",position:"relative"},onClick:e,children:re(a,{component:l,sx:{width:36,height:36,borderRadius:"50%",backgroundColor:t.palette.background.input,border:`4px solid ${t.palette.background.paper}`,display:"flex",alignItems:"center",justifyContent:"center",position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -50%) rotate(-90deg)"},children:re(a,{component:B,sx:{width:18,color:"text.secondary"}})})})}function bn({open:t,execute:o,onClose:i,toToken:r,fromToken:c,fromAmount:d,toAmount:p,priceImpact:m,clearFromAmt:h,clearToAmt:f,baseFeeAmount:g,curToFiatPrice:b,curFromFiatPrice:y,pricePerFromToken:v,additionalFeeAmount:w}){var A,O;const T=s(),R=I(cn),L=k(),{contractStatus:D}=I(It),_=E((()=>new n(m).gt(15)),[m]),[N,B]=x(!1),[M,U]=x(!1);return C((()=>{D!==Be.Pending&&i(),D===Be.TxSuccess&&(f(),h())}),[D]),C((()=>{B(!1)}),[b]),re(kt,{open:t,onClose:()=>{L(Kt({contractStatus:Be.Initial})),i()},title:re(e,{id:"Swap summary"}),children:ie(a,{sx:{margin:20,display:"flex",height:"100%",flexDirection:"column",borderTop:`1px solid ${T.palette.border.main}`},children:[ie(a,{sx:{py:20,display:"flex",typography:"body2",alignItems:"center",justifyContent:"center",flexDirection:"column",borderBottom:`1px solid ${T.palette.border.main}`},children:[ie(a,{sx:{display:"flex",alignItems:"center"},children:[ie(a,{children:[ie(a,{sx:{display:"flex"},children:[re(Ct,{width:16,height:16,address:null!==(A=null==c?void 0:c.address)&&void 0!==A?A:"",marginRight:6}),re(a,{children:`${ge({input:d,decimals:null==c?void 0:c.decimals})} ${null==c?void 0:c.symbol}`})]}),re(a,{sx:{mt:4,typography:"h6",color:T.palette.text.secondary},children:y?`$${fe({input:y,showDecimals:1})}`:"-"})]}),re(a,{sx:{width:16,mx:16},component:P}),ie(a,{children:[ie(a,{sx:{display:"flex"},children:[re(Ct,{width:16,height:16,marginRight:6,address:null!==(O=null==r?void 0:r.address)&&void 0!==O?O:""}),re(a,{children:`${ge({input:p,decimals:null==r?void 0:r.decimals})} ${null==r?void 0:r.symbol}`})]}),re(a,{sx:{typography:"h6",mt:4,color:T.palette.text.secondary},children:b?`$${fe({input:b,showDecimals:1})}(${m}%)`:"-"})]})]}),re(a,{sx:{mt:12,typography:"h6"},children:`1 ${null==c?void 0:c.symbol} = ${ge({input:new n(p).dividedBy(new n(d)),decimals:null==r?void 0:r.decimals})} ${null==r?void 0:r.symbol}`})]}),ie(a,{sx:{py:15,typography:"body2",borderBottom:`1px solid ${T.palette.border.main}`},children:[ie(a,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",color:T.palette.text.secondary},children:[ie(a,{sx:{display:"flex",alignItems:"center"},children:[re(a,{sx:{width:16,mr:7},component:F}),re(e,{id:"Swap Detail"})]}),re(a,{component:l,children:re(a,{onClick:()=>U(!M),sx:{width:10,color:"text.secondary",transform:M?"rotateX(0deg)":"rotateX(180deg)"},component:S})})]}),ie(a,{sx:{mt:16,display:M?"initial":"none"},children:[ie(a,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[ie(a,{sx:{display:"flex",alignItems:"center"},children:[re(e,{id:"Basic Fee"}),re(fn,{title:re(e,{id:"Estimated service provider fees"}),ml:5})]}),re(a,{children:`${ge({input:g,decimals:null==r?void 0:r.decimals})} ${null==r?void 0:r.symbol}`})]}),ie(a,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[ie(a,{sx:{display:"flex",alignItems:"center"},children:[re(e,{id:"Additional Fee"}),re(fn,{title:re(e,{id:"Additional routing fees set by the Widget user"}),ml:5})]}),re(a,{children:`${ge({input:w,decimals:null==r?void 0:r.decimals})} ${null==r?void 0:r.symbol}`})]}),ie(a,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[ie(a,{sx:{display:"flex",alignItems:"center"},children:[re(e,{id:"Price Impact"}),re(fn,{title:re(e,{id:"Due to the market condition, market price and estimated price may have a slight difference"}),ml:5})]}),re(a,{children:`${m}%`})]}),ie(a,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[ie(a,{sx:{display:"flex",alignItems:"center"},children:[re(e,{id:"Slippage"}),re(fn,{title:re(e,{id:"High slippage tolerance will increase the success rate of transaction, but might not get the best quote."}),ml:5})]}),re(a,{children:R})]})]})]}),re(a,{sx:{flex:1}}),_&&ie(a,{sx:{mb:14,display:"flex",cursor:"pointer",justifyContent:"center",alignItems:"center",typography:"h6"},onClick:()=>B(!N),children:[re(a,{sx:{mr:4,width:18,height:18,alignItems:"center"},children:re(a,N?{sx:{width:"100%",height:"100%",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"secondary.main"},children:re(a,{component:j,sx:{width:14,color:"#1a1a1b"}})}:{sx:{width:"100%",height:"100%",borderRadius:4,border:`1px solid ${T.palette.text.secondary}`}})}),re(a,{children:re(e,{components:{0:re(a,{component:"span",sx:{color:"error.main"}})},values:{priceImpact:m},id:"Price impact reaches <0>{priceImpact}</0>%, accept the quote"})})]}),re(u,{isLoading:D==Be.Pending,disabled:_&&!N,fullWidth:!0,onClick:()=>{o(),L(Kt({contractStatus:Be.Pending}))},children:D==Be.Pending?re(e,{id:"Confirming"}):re(e,{id:"Confirm swap"})})]})})}function yn(e){var{sx:t,maxVal:n,decimals:i=2,onInputChange:r}=e,a=Ie(e,["sx","maxVal","decimals","onInputChange"]);return s(),re(c,{...a,onChange:e=>{const t=0===e.target.value.length?null:ve(e.target.value,i),a=n&&t&&new o(t).gt(n)?n.toString():t;console.log("finalVal:",a),r&&r(a)}})}function vn({open:t,onClose:n}){const o=s(),i=k(),r=I(cn),l=I(dn),c=E((()=>Number(r)>=50),[r]);return re(kt,{open:t,onClose:n,title:re(e,{id:"Settings"}),children:ie(a,{sx:{mx:20},children:[ie(a,{sx:{py:20,borderTop:`1px solid ${o.palette.border.main}`},children:[ie(a,{sx:{mb:16,display:"flex",alignItems:"center"},children:[re(e,{id:"Slippage Tolerance"}),re(fn,{title:re(e,{id:"Attention: High slippage tolerance will increase the success rate of transaction, but might not get the best quote."}),ml:7})]}),ie(a,{sx:{display:"flex",flexDirection:"column"},children:[re(yn,{fullWidth:!0,maxVal:100,value:r,placeholder:3..toString(),onInputChange:e=>{i((e=>t=>Re(void 0,void 0,void 0,(function*(){t({type:"SET_SLIPPAGE",payload:e})})))(e))},suffix:re(a,{sx:{color:"text.disabled"},children:"%"}),height:36}),c&&re(a,{sx:{typography:"h6",mt:6,color:"error.main"},children:re(e,{id:"Maximum slippage do not exceed 50%"})})]})]}),ie(a,{sx:{py:20,borderTop:`1px solid ${o.palette.border.main}`},children:[ie(a,{sx:{mb:16,display:"flex",alignItems:"center"},children:[re(e,{id:"Transaction Deadline"}),re(fn,{title:re(e,{id:"If your transaction time exceeds the deadline, your transaction will be rescinded."}),ml:7})]}),re(yn,{value:l,fullWidth:!0,height:36,placeholder:se._("{DEFAULT_SWAP_DDL} minutes",{DEFAULT_SWAP_DDL:20}),onInputChange:e=>{i((e=>t=>Re(void 0,void 0,void 0,(function*(){t({type:"SET_TRANSACTION_DDL",payload:e})})))(e?Math.max(Number(e),1):""))}})]})]})})}function xn({toToken:t,fromToken:n,priceStatus:o,pricePerToToken:i,pricePerFromToken:r}){const[s,c]=x("-"),[d,u]=x(null),[p,m]=x("-"),[h,f]=x(null);C((()=>{c(null==n?void 0:n.symbol),m(null==t?void 0:t.symbol),u(i),f(r)}),[n,t,i,r]);const g=w((()=>{c(p),m(s),u(h),f(d)}),[s,d,p,h]);return re(a,{sx:{display:"flex",justifyContent:"center",alignItems:"center"},children:{[un.Initial]:"-",[un.Loading]:ie(ae,{children:[re(b,{sx:{mr:5}}),re(e,{id:"Fetching best price..."})]}),[un.Failed]:ie(ae,{children:[re(a,{component:M,sx:{width:15,mr:5,color:"warning.main"}}),re(e,{id:"Quote not available"})]}),[un.Success]:ie(ae,{children:[re(a,{sx:{typography:"body2"},children:`1 ${s} = ${fe({input:h,showDecimals:4})} ${p}`}),re(a,{component:l,sx:{width:18,height:18,ml:6,borderRadius:"50%",backgroundColor:"border.main",display:"flex",justifyContent:"center",alignItems:"center"},children:re(a,{sx:{width:16,color:"text.secondary"},onClick:g,component:U})})]})}[o]})}function En({open:t,onClose:n}){const o=I(Ue);return re(kt,{title:re(e,{id:"Connect to your wallet"}),open:t,onClose:n,children:re(a,{sx:{mx:20,pb:20,border:"1px solid transparent",borderTopColor:"border.main"},children:Object.values(lt).map((t=>ie(a,{sx:{display:"flex",alignItems:"center",flexDirection:"column",mt:20,p:20,backgroundColor:"background.tag",borderRadius:12,cursor:"pointer","&:hover":{backgroundColor:"hover.default"}},onClick:()=>{!function(e,t,n){var o;const i=ct[e];if(!i)throw new Error(`Unknown wallet type: ${e}`);const[r]=i;null===(o=r.activate(t))||void 0===o||o.catch((e=>{4001!==e.code?n(e):r.connectEagerly?r.connectEagerly(t):r.activate(t)}))}(t.type,o,(e=>{console.error(e)}))},children:[re(a,{component:t.icon,sx:{width:32,height:32}}),re(a,{sx:{mt:8,typography:"caption"},children:t.name}),re(a,{sx:{mt:4,typography:"body2",color:"text.secondary"},children:re(e,{id:"Connect to your {0} Wallet",values:{0:t.name}})})]},t.type)))})})}function wn(){const{connector:t}=V(),[n,o]=x(!1);return ie(ae,{children:[re(u,{size:u.Size.big,fullWidth:!0,onClick:()=>{t.deactivate?t.deactivate():t.resetState(),o(!0)},"data-testid":"connect-wallet-btn",children:re(e,{id:"Connect to a wallet"})}),re(En,{open:n,onClose:()=>o(!1)})]})}var Cn;!function(e){e.Loading="Loading",e.Insufficient="ApprovalInsufficient",e.Approving="Approving",e.Sufficient="Sufficient",e.Unchecked="Unchecked"}(Cn||(Cn={}));const An=({account:e,chainId:t,offset:o,contractAddress:i})=>{var r;const a=I(Ue),s=E((()=>{var e;return ze[null!==(e=t)&&void 0!==e?e:a]}),[t]),{isETH:l}=E((()=>Ee(t)),[t]),{DODO_APPROVE:c}=s||{},d=null!==(r=null!=i?i:c)&&void 0!==r?r:null,u=function(e){const{account:t}=V(),o=I(Ue),i=I(ht),r=E((()=>Oe[o]),[o]),a=w((o=>{var a;if(!t||!e)return null;if(o.symbol===r.symbol&&xe(o.address,r.address))return new n(zt);const s=null===(a=null==i?void 0:i[o.address.toLowerCase()])||void 0===a?void 0:a.tokenAllowances;return null!=s?s:null}),[t,e,r.symbol,r.address,i]);return a}(d),p=vt(),{runningRequests:m}=Yt(),h=I(yt),f=E((()=>{var e;return null===(e=Oe[null!=t?t:a])||void 0===e?void 0:e.address}),[t]),g=w(((t,i,r)=>{if(!t)return Cn.Loading;const a=!!(null==m?void 0:m.find((e=>e.spec.opcode===$t.Approval&&e.spec.token.address===(null==t?void 0:t.address)))),s=null!=r?r:t?p(t):null,l=t?u(t):null,c=new n(null!=i?i:0);if(!e)return Cn.Unchecked;if(!s||c.minus(null!=o?o:0).gt(s))return Cn.Unchecked;if(c.isZero())return Cn.Unchecked;return t.address===f?Cn.Sufficient:a?Cn.Approving:l&&c.minus(null!=o?o:0).gt(l)?Cn.Insufficient:Cn.Sufficient}),[p,u,e,o,d,t,h,m,f]),b=w((e=>{const t=e?u(e):null;return("USDT"===(null==e?void 0:e.symbol)||(null==e?void 0:e.address.toLowerCase())==="0x6426e6017968377529487E0ef0aA4E7759724e05".toLowerCase())&&null!==t&&t.gt(0)}),[u]),y=Xt(),v=k(),x=w(((t,o)=>Re(void 0,void 0,void 0,(function*(){if(!d||!e||!t)return;const i=(e=>{let t=e.symbol;return t.indexOf("DLP_")>-1&&(t=t.replace("DLP_","")),t.indexOf("DLP")>-1&&(t=t.replace("DLP","LP")),t})(t),r=o?new n(0):void 0,a=o?se._("Reset"):se._("Approve");var s;(yield y.execute(`${a} ${i}`,{opcode:$t.Approval,token:t,contract:d,amt:r}))===Ft.Success&&v((s=null!=r?r:zt,e=>Re(void 0,void 0,void 0,(function*(){e({type:"SET_ACCOUNT_ALLOWANCES",payload:s})}))))}))),[d,e,t,y,v]),C=w((e=>{const t=new n(0);if(!e)return t.toNumber();const o=p(e);if(!o)return t.toNumber();let i=o;const r=l?.1:.02;return f===(null==e?void 0:e.address)&&(i=o.gt(r)?o.minus(r):t),i.toNumber()}),[t,p,l]);return{getApprovalState:g,getPendingRest:b,getMaxBalance:C,submitApprove:x}};function On(){var t,o;const i=s(),{isInflight:c}=Yt(),{chainId:d,account:p}=V(),m=k(),{isReverseRouting:h}=I(It),f=I(Ue),g=I(bt),y=I(gt),{isETH:v}=E((()=>Ee(d)),[d]),A=E((()=>{var e;return null===(e=Oe[null!=d?d:f])||void 0===e?void 0:e.address}),[d]),[O,T]=x(""),[R,S]=x(""),[L,D]=x(""),[_,N]=x(""),B=E((()=>r((e=>D(e)),1e3)),[]),F=E((()=>r((e=>N(e)),1e3)),[]),[j,U]=x(null),[$,z]=x(null),[K,G]=x(!1),[Y,q]=x(!1),{toFiatPrice:X,fromFiatPrice:Z}=ln({chainId:d,toToken:$,fromToken:j}),Q=vt(),J=E((()=>j?Q(j):null),[j,Q]);E((()=>$?Q($):null),[$,Q]);const{getApprovalState:ee,submitApprove:te,getPendingRest:ne,getMaxBalance:oe}=An({account:p,chainId:d}),se=E((()=>ne(h?$:j)),[null==j?void 0:j.address,null==$?void 0:$.address,ne,h]),{marginAmount:le}=rn({token:h?$:j,fiatPrice:h?X:Z}),{resAmount:ce,priceImpact:de,executeSwap:ue,baseFeeAmount:pe,additionalFeeAmount:me,resPricePerToToken:he,resPricePerFromToken:be,status:ye}=pn({toToken:$,fromToken:j,marginAmount:le,fromAmount:L,toAmount:_}),ve=w((e=>{const t=e.toString();T(t),B(t)}),[T,B]),xe=w((e=>{const t=e.toString();S(t),F(t)}),[S,F]);C((()=>{d&&(z(null),U(null),h?xe(""):ve("")),y&&y.chainId===d&&(U(y),y.amount&&(m(Kt({isReverseRouting:!1})),ve(y.amount))),g&&g.chainId===d&&(z(g),g.amount&&y&&!y.amount&&(m(Kt({isReverseRouting:!0})),xe(g.amount)))}),[g,y,d,ve,xe]);const Ce=w((()=>{ve(""),xe(""),U($),z(j)}),[U,$,z,j,ve,xe]),Ae=w((e=>h?xe(oe($)):ve(oe(j))),[ve,xe,oe,j,$,h]),Te=E((()=>(100*Number(de)).toFixed(2)),[de]),ke=E((()=>{const e=h?ce:L;return e&&Z?new n(Z).multipliedBy(e):null}),[Z,L,h,ce]),Ie=E((()=>{const e=h?_:ce;return e&&X?new n(X).multipliedBy(e):null}),[X,_,h,ce]),Re=E((()=>ie(a,{sx:{display:"flex",fontWeight:600,typography:"body2",alignItems:"center",justifyContent:"center"},children:[re(fn,{title:re(e,{id:"Due to the market condition, market price and estimated price may have a slight difference"}),mr:8}),ie(a,{sx:{display:"flex"},children:[re(e,{id:"Current price impact"}),ie(a,{sx:{color:i.palette.error.main,ml:4},children:[Te,"%"]})]})]})),[Te]),Se=E((()=>re(xn,{toToken:$,fromToken:j,priceStatus:ye,pricePerToToken:he,pricePerFromToken:be})),[$,j,ye,he,be]),Le=E((()=>!we[d||1]),[d]),De=E((()=>ye===un.Loading?re(a,{sx:{display:"flex",justifyContent:"center",alignItems:"center"},children:ie(ae,{children:[re(b,{sx:{mr:5}}),re(e,{id:"Fetching best price..."})]})}):Le?ie(ae,{children:[re(a,{component:M,sx:{mr:6,width:16,color:"warning.main"}}),re(e,{id:"Unsupported network - switch to trade"})]}):O&&new n(Te).gt(15)?Re:Se),[ye,Se,O,Re,Te,Le]),_e=E((()=>h?new n(R).gt(0)?ge({input:ce,decimals:null==j?void 0:j.decimals}):"-":O),[O,R,ce,j,h]),Ne=E((()=>h?R:new n(O).gt(0)?ge({input:ce,decimals:null==$?void 0:$.decimals}):"-"),[O,R,ce,$,h]),Be=E((()=>{const t=ee(j,L),o=t===Cn.Approving,i=t===Cn.Insufficient&&!se,r=v?.1:.02,a=A===(null==j?void 0:j.address),s=new n(J||0);return p?c?re(u,{fullWidth:!0,isLoading:!0,disabled:!0,children:re(e,{id:"Transaction Pending"})}):j&&$?i?re(u,{fullWidth:!0,disabled:o,onClick:()=>te(j),children:re(e,o?{id:"Approving"}:{id:"Approve"})}):new n(h?_:L).gt(0)?ye===un.Loading?re(u,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-fetch-price-btn",children:re(e,{id:"Fetching Price..."})}):ce?s.lt(h?ce:L)||a&&s.lte(r)?re(u,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-insufficient-balance-btn",children:re(e,{id:"Insufficient balance"})}):re(u,{fullWidth:!0,onClick:()=>G(!0),"data-testid":"swap-review-btn",children:re(e,{id:"Review Swap"})}):re(u,{fullWidth:!0,disabled:!0,children:re(e,{id:"Quote not available"})}):re(u,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-enter-amount-btn",children:re(e,{id:"Enter an amount"})}):re(u,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-select-token-btn",children:re(e,{id:"Select Tokens"})}):re(wn,{})}),[v,p,_,L,$,ce,j,c,ue,se,te,ye,J,ee,A,h]),Pe=E((()=>j&&$?ie(a,{sx:{display:"flex",alignItems:"center"},children:[re(Ct,{token:j,sx:{width:16,height:16,mr:6}}),`${ge({input:h?ce:L,decimals:null==j?void 0:j.decimals})} ${j.symbol}`,re(a,{component:P,sx:{width:12,height:12,mx:16}}),re(Ct,{token:$,sx:{width:16,height:16,mr:6}}),`${ge({input:h?_:ce,decimals:null==$?void 0:$.decimals})} ${$.symbol}`]}):re(a,{})),[j,$,L,_,ce,h]);return ie(ae,{children:[ie(a,{sx:{display:"flex",justifyContent:"space-between",typography:"caption",margin:20},children:[re(e,{id:"Swap"}),re(a,{component:l,children:re(a,{component:H,onClick:()=>q(!0),sx:{width:19,height:19,color:"text.primary",cursor:"pointer"}})})]}),ie(a,{sx:{flex:1,padding:"0 20px 20px",overflowY:"auto"},children:[ie(a,{children:[re(_t,{sx:{mb:4},token:j,amt:_e,onMaxClick:Ae,onInputChange:ve,onInputFocus:()=>{h&&ve(""),m(Kt({isReverseRouting:!1}))},showMaxBtn:!h&&!O,occupiedAddrs:[null!==(t=null==$?void 0:$.address)&&void 0!==t?t:""],fiatPriceTxt:ke?`$${fe({input:ke,showDecimals:1})}`:"-",onTokenChange:(e,t)=>{if(t)return Ce();ve(""),xe(""),U(e)},readOnly:h}),re(gn,{onClick:Ce}),re(_t,{token:$,amt:Ne,onInputChange:xe,onInputFocus:()=>{h||xe(""),m(Kt({isReverseRouting:!0}))},occupiedAddrs:[null!==(o=null==j?void 0:j.address)&&void 0!==o?o:""],fiatPriceTxt:Ie?`$${fe({input:Ie,showDecimals:1})}(${Te}%)`:"-",onTokenChange:(e,t)=>{if(t)return Ce();ve(""),xe(""),z(e)},readOnly:!h}),re(a,{sx:{py:12,display:"flex",typography:"body2",alignItems:"center",justifyContent:"center",flexWrap:"wrap"},children:De})]}),Be,ie(a,{sx:{mt:13,display:"flex",typography:"h6",cursor:"pointer",justifyContent:"center",alignItems:"center",color:i.palette.text.disabled},onClick:()=>window.open("https://app.dodoex.io"),children:[re(a,{sx:{width:24,typography:"body2",transform:"translate(1px, 2px)","& path":{fill:i.palette.text.disabled}},component:W}),re(e,{id:"Powered by DODO protocol"})]})]}),re(bn,{toToken:$,fromToken:j,fromAmount:h?ce:L,toAmount:h?_:ce,open:K,baseFeeAmount:pe,priceImpact:Te,additionalFeeAmount:me,curToFiatPrice:Ie,execute:()=>ue(Pe),clearFromAmt:()=>ve(""),clearToAmt:()=>xe(""),curFromFiatPrice:ke,pricePerFromToken:be,onClose:()=>G(!1)}),re(vn,{open:Y,onClose:()=>q(!1)})]})}function Tn(e){return re(hn,{...e,children:re(On,{})})}function kn(e){const t=document.getElementById("dodo-swap-widget");he(t).render(re(hn,{...e,children:re(On,{})}))}export{kn as InitSwapWidget,Tn as SwapWidget};
|
|
1
|
+
import{Trans as e,I18nProvider as t}from"@lingui/react";import n,{BigNumber as o}from"bignumber.js";import{chunk as i,unionBy as r,debounce as a}from"lodash";import{Box as s,useTheme as l,BaseButton as c,Input as d,SearchInput as u,Button as p,HoverOpacity as m,createTheme as h,ThemeProvider as f,CssBaseline as g,QuestionTooltip as b,RotatingIcon as y}from"@dodoex/components";import{getAddress as v}from"@ethersproject/address";import*as x from"react";import{useState as E,useMemo as w,useCallback as C,useEffect as A,useRef as O,useContext as T,createContext as k}from"react";import{useDispatch as I,useSelector as R,Provider as S}from"react-redux";import{CaretUp as L,Error as D,ErrorWarn as N,DoneBorder as _,ArrowTopRightBorder as B,ArrowBack as P,DoubleRight as F,DetailBorder as j,Done as M,Warn as U,Switch as H,Setting as W,Dodo as $}from"@dodoex/icons";import V from"identicon.js";import{useWeb3React as z,initializeConnector as K,Web3ReactProvider as G}from"@web3-react/core";import{configureStore as Y}from"@reduxjs/toolkit";import{combineReducers as q}from"redux";import{Contract as X}from"@ethersproject/contracts";import{AddressZero as Z}from"@ethersproject/constants";import{defaultAbiCoder as Q,Interface as J}from"@ethersproject/abi";import{EIP1193 as ee}from"@web3-react/eip1193";import{WalletConnect as te}from"@web3-react/walletconnect";import{MetaMask as ne}from"@web3-react/metamask";import{JsonRpcProvider as oe}from"@ethersproject/providers";import{Connector as ie}from"@web3-react/types";import{jsxs as re,jsx as ae,Fragment as se}from"react/jsx-runtime";import{i18n as le}from"@lingui/core";import{VariableSizeList as ce}from"react-window";import{en as de,zh as ue}from"make-plural/plurals";import pe from"axios";import{BigNumber as me,parseFixed as he}from"@ethersproject/bignumber";import{createRoot as fe}from"react-dom/client";function ge({input:e,showDecimals:t=4,showPrecisionDecimals:n=2,showIntegerOnly:i=!1,showDecimalsOnly:r=!1,noGroupSeparator:a=!1}){const s=new o(e);if(s.isNaN())return"-";let l=s.dp(t,o.ROUND_DOWN);return l.eq(0)&&(s.gt(0)||s.lt(0))&&(l=s.sd(null!=n?n:t,o.ROUND_DOWN)),i&&(l=l.integerValue(o.ROUND_DOWN)),r&&(l=l.minus(l.integerValue(o.ROUND_DOWN))),a?l.toFormat({decimalSeparator:".",groupSeparator:"",groupSize:3,secondaryGroupSize:0,fractionGroupSeparator:"",fractionGroupSize:0}):l.toFormat()}function be({input:e,decimals:t,showPrecisionDecimals:n=2,noGroupSeparator:i}){if(null==e)return"-";const r=new o(e);if(r.isNaN())return"-";return ge({input:r,showDecimals:void 0===t?0:t>6?6:t>4?4:t,showPrecisionDecimals:n,noGroupSeparator:i})}function ye(e){if("number"==typeof e)return ye(new o(e));if(e.isNaN())return"NaN";if(e.isNegative())return`-${ye(e.negated())}`;if(e.isZero())return"0";let t=e.integerValue(o.ROUND_FLOOR),n=e.minus(t),i="";for(;!t.isZero();){i=t.modulo(10).toString().toString()+i,t=t.idiv(10)}if(""===i&&(i="0"),n.isZero())return i;i+=".";let r=0;for(;!n.isZero()&&r<100;){const e=n.times(10),t=e.integerValue(o.ROUND_FLOOR);i+=t.toString(),n=e.minus(t),r+=1}return i}const ve=(e,t)=>{if("string"==typeof e&&!e.match(/[-+]?\d+(.+d+)?/))return e;const n=new o(e);if(t){let e=n.toFixed(t,o.ROUND_DOWN);return new o(e).isZero()&&(e=ye(n.precision(t,o.ROUND_DOWN))),e}return ye(n)},xe=(e,t)=>{let n=e;const o=n.match("[0-9。.]+");n=o&&o.length>0?o[0]:"",n=n.replace("。",".");let i=0;if(n){const e=n.split("."),t=0===e[0].length?["0"]:[e[0]];e.length>1?t[1]=e.slice(1,e.length).join(""):t[0].length>1&&"0"===t[0][0]&&(t[0]=t[0].slice(1,t[0].length)),t.length>1&&(i=t[1].length),n=t.join(".")}return t>=0&&i>t?ve(n,t):n},Ee=(e,t)=>{if(0===e.length||0===t.length)return!1;if(t.length===e.length)return e.toLowerCase()===t.toLowerCase();const n=e.substring(2,e.length).toLowerCase(),o=t.substring(2,t.length).toLowerCase();return n.length>o.length?n.endsWith(o):o.endsWith(n)};const we=e=>{const t={isMainnet:1===e,isRinkeby:4===e,isGor:5===e};return Object.assign(Object.assign({},t),{isETH:t.isMainnet||t.isRinkeby||t.isGor})};var Ce;!function(e){e[e.MAINNET=1]="MAINNET",e[e.RINKEBY=4]="RINKEBY",e[e.GOERLI=5]="GOERLI",e[e.BSC=56]="BSC",e[e.HECO=128]="HECO",e[e.POLYGON=137]="POLYGON",e[e.ARBITRUM_ONE=42161]="ARBITRUM_ONE",e[e.ARBITRUM_RINKEBY=421611]="ARBITRUM_RINKEBY",e[e.AURORA=1313161554]="AURORA",e[e.MOONRIVER=1285]="MOONRIVER",e[e.OKCHAIN=66]="OKCHAIN",e[e.OPTIMISM=10]="OPTIMISM",e[e.BOBA=288]="BOBA",e[e.AVALANCHE=43114]="AVALANCHE",e[e.CRONOS=25]="CRONOS"}(Ce||(Ce={}));const Ae={[Ce.MAINNET]:["https://rpc.ankr.com/eth","https://eth-mainnet.public.blastapi.io","https://eth-rpc.gateway.pokt.network","https://main-rpc.linkpool.io"],[Ce.RINKEBY]:["https://rinkeby-light.eth.linkpool.io/"],[Ce.GOERLI]:["https://goerli.optimism.io/"],[Ce.BSC]:["https://bsc-dataseed1.binance.org","https://bsc-dataseed2.binance.org","https://bsc-dataseed3.binance.org","https://bsc-dataseed4.binance.org","https://bsc-dataseed1.defibit.io","https://bsc-dataseed2.defibit.io","https://bsc-dataseed3.defibit.io","https://bsc-dataseed4.defibit.io","https://bsc-dataseed1.ninicoin.io","https://bsc-dataseed2.ninicoin.io","https://bsc-dataseed3.ninicoin.io","https://bsc-dataseed4.ninicoin.io","https://bsc-dataseed.binance.org","https://rpc.ankr.com/bsc","https://bscrpc.com","https://bsc.mytokenpocket.vip","https://binance.nodereal.io","https://rpc-bsc.bnb48.club"],[Ce.HECO]:["https://http-mainnet.hecochain.com","https://pub001.hg.network/rpc"],[Ce.POLYGON]:["https://polygon-rpc.com","https://rpc-mainnet.matic.network","https://matic-mainnet.chainstacklabs.com","https://rpc-mainnet.maticvigil.com","https://rpc-mainnet.matic.quiknode.pro","https://matic-mainnet-full-rpc.bwarelabs.com","https://matic-mainnet-archive-rpc.bwarelabs.com","https://poly-rpc.gateway.pokt.network","https://rpc.ankr.com/polygon","https://polygon-mainnet.public.blastapi.io"],[Ce.ARBITRUM_ONE]:["https://arb1.arbitrum.io/rpc","https://rpc.ankr.com/arbitrum"],[Ce.ARBITRUM_RINKEBY]:["https://rinkeby.arbitrum.io/rpc"],[Ce.AURORA]:["https://mainnet.aurora.dev/"],[Ce.MOONRIVER]:["https://rpc.api.moonriver.moonbeam.network","https://moonriver.api.onfinality.io/rpc?apikey=673e1fae-c9c9-4c7f-a3d5-2121e8274366","https://moonriver.api.onfinality.io/public","https://moonriver.public.blastapi.io"],[Ce.OKCHAIN]:["https://exchainrpc.okex.org","https://okc-mainnet.gateway.pokt.network/v1/lb/6275309bea1b320039c893ff"],[Ce.OPTIMISM]:["https://mainnet.optimism.io","https://optimism-mainnet.public.blastapi.io"],[Ce.BOBA]:["https://mainnet.boba.network","https://boba-mainnet.gateway.pokt.network/v1/lb/623ad21b20354900396fed7f","https://lightning-replica.boba.network"],[Ce.AVALANCHE]:["https://api.avax.network/ext/bc/C/rpc","https://rpc.ankr.com/avalanche","https://ava-mainnet.public.blastapi.io/ext/bc/C/rpc"],[Ce.CRONOS]:["https://evm.cronos.org","https://cronos-rpc.heavenswail.one","https://evm-cronos.crypto.org","https://cronosrpc-1.xstaking.sg","https://cronos-rpc.elk.finance"]},Oe={symbol:"ETH",address:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",name:"Ether",decimals:18,showDecimals:4,wrappedTokenSymbol:"WETH"},Te={[Ce.MAINNET]:Object.assign(Object.assign({},Oe),{wrappedTokenAddress:"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}),[Ce.RINKEBY]:Object.assign(Object.assign({},Oe),{wrappedTokenAddress:"0xB26c0d8Be2960c70641A95A9195BE1f59Ac83aC0"}),[Ce.GOERLI]:Object.assign(Object.assign({},Oe),{wrappedTokenAddress:"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6"}),[Ce.OPTIMISM]:Object.assign(Object.assign({},Oe),{wrappedTokenAddress:"0x4200000000000000000000000000000000000006"}),[Ce.CRONOS]:Object.assign(Object.assign({},Oe),{symbol:"CRO",name:"Cronos",wrappedTokenSymbol:"WCRO",wrappedTokenAddress:"0x5C7F8A570d578ED84E63fdFA7b1eE72dEae1AE23"}),[Ce.BOBA]:Object.assign(Object.assign({},Oe),{wrappedTokenAddress:"0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000"}),[Ce.BSC]:Object.assign(Object.assign({},Oe),{symbol:"BNB",name:"BNB",wrappedTokenSymbol:"WBNB",wrappedTokenAddress:"0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}),[Ce.OKCHAIN]:Object.assign(Object.assign({},Oe),{symbol:"OKT",name:"OKT",wrappedTokenSymbol:"WOKT",wrappedTokenAddress:"0x8F8526dbfd6E38E3D8307702cA8469Bae6C56C15"}),[Ce.HECO]:Object.assign(Object.assign({},Oe),{symbol:"HT",name:"HT",showDecimals:6,wrappedTokenSymbol:"WHT",wrappedTokenAddress:"0x5545153ccfca01fbd7dd11c0b23ba694d9509a6f"}),[Ce.POLYGON]:Object.assign(Object.assign({},Oe),{symbol:"MATIC",name:"MATIC",showDecimals:6,wrappedTokenSymbol:"WMATIC",wrappedTokenAddress:"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270"}),[Ce.MOONRIVER]:Object.assign(Object.assign({},Oe),{symbol:"MOVR",name:"MOVR",showDecimals:6,wrappedTokenSymbol:"WMOVR",wrappedTokenAddress:"0x98878b06940ae243284ca214f92bb71a2b032b8a"}),[Ce.ARBITRUM_ONE]:Object.assign(Object.assign({},Oe),{name:"Ethereum",showDecimals:6,wrappedTokenAddress:"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"}),[Ce.ARBITRUM_RINKEBY]:Object.assign(Object.assign({},Oe),{name:"Ether",showDecimals:6,wrappedTokenAddress:"0xEBbc3452Cc911591e4F18f3b36727Df45d6bd1f9"}),[Ce.AURORA]:Object.assign(Object.assign({},Oe),{name:"Ethereum",showDecimals:6,wrappedTokenAddress:"0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB"}),[Ce.AVALANCHE]:Object.assign(Object.assign({},Oe),{symbol:"AVAX",name:"Avalanche",showDecimals:6,wrappedTokenSymbol:"WAVAX",wrappedTokenAddress:"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7"})},ke={[Ce.MAINNET]:"ethereum",[Ce.RINKEBY]:"rinkeby",[Ce.GOERLI]:"goerli",[Ce.OPTIMISM]:"optimism",[Ce.CRONOS]:"cronos",[Ce.BOBA]:"boba",[Ce.BSC]:"bsc",[Ce.OKCHAIN]:"okex-chain",[Ce.HECO]:"heco",[Ce.POLYGON]:"polygon",[Ce.MOONRIVER]:"moonriver",[Ce.ARBITRUM_ONE]:"arbitrum",[Ce.ARBITRUM_RINKEBY]:"arb-rinkeby",[Ce.AURORA]:"aurora",[Ce.AVALANCHE]:"avalanche"},Ie={[Ce.MAINNET]:"etherscan.io",[Ce.RINKEBY]:"rinkeby.etherscan.io",[Ce.GOERLI]:"goerli.etherscan.io",[Ce.OPTIMISM]:"optimistic.etherscan.io",[Ce.CRONOS]:"cronoscan.com",[Ce.BOBA]:"blockexplorer.boba.network",[Ce.BSC]:"bscscan.com",[Ce.OKCHAIN]:"www.oklink.com/okexchain",[Ce.HECO]:"hecoinfo.com",[Ce.POLYGON]:"polygonscan.com",[Ce.MOONRIVER]:"moonriver.moonscan.io",[Ce.ARBITRUM_ONE]:"arbiscan.io",[Ce.ARBITRUM_RINKEBY]:"testnet.arbiscan.io",[Ce.AURORA]:"aurorascan.dev",[Ce.AVALANCHE]:"snowtrace.io"};function Re(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]])}return n}function Se(e,t,n,o){return new(n||(n=Promise))((function(i,r){function a(e){try{l(o.next(e))}catch(e){r(e)}}function s(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}const Le={colorMode:"dark",slippage:3..toString(),ddl:20};var De=(e=Le,t)=>{switch(t.type){case"SET_COLOR_MODE":return Object.assign(Object.assign({},e),{colorMode:t.payload});case"SET_SLIPPAGE":return Object.assign(Object.assign({},e),{slippage:t.payload});case"SET_TRANSACTION_DDL":return Object.assign(Object.assign({},e),{ddl:t.payload});default:return e}};const Ne={chainId:Ce.MAINNET,latestBlockNumber:0};var _e=(e=Ne,t)=>{switch(t.type){case"SET_CHAIN_ID":return Object.assign(Object.assign({},e),{chainId:t.payload});case"SET_BLOCK_NUMBER":return Object.assign(Object.assign({},e),{latestBlockNumber:t.payload});default:return e}};const Be={tokenList:[],popularTokenList:[],ethBalance:void 0,accountBalances:{},balanceLoadings:{},slippageWithTokens:[]};var Pe,Fe=(e=Be,t)=>{switch(t.type){case"SET_TOKEN_LIST":return Object.assign(Object.assign({},e),{tokenList:t.payload});case"SET_POPULAR_TOKEN_LIST":return Object.assign(Object.assign({},e),{popularTokenList:t.payload});case"SET_SLIPPAGE_WITH_TOKENS":return Object.assign(Object.assign({},e),{slippageWithTokens:t.payload});case"SET_ETH_BALANCE":return Object.assign(Object.assign({},e),{ethBalance:t.payload});case"SET_DEFAULT_FROM_TOKEN":return Object.assign(Object.assign({},e),{defaultFromToken:t.payload});case"SET_DEFAULT_TO_TOKEN":return Object.assign(Object.assign({},e),{defaultToToken:t.payload});case"SET_ACCOUNT_BALANCES":return Object.assign(Object.assign({},e),{accountBalances:Object.assign(Object.assign({},e.accountBalances),t.payload)});case"SET_ACCOUNT_ALLOWANCES":const n=e.accountBalances;return Object.keys(n).map((e=>{n[e].tokenAllowances=t.payload})),Object.assign(Object.assign({},e),{accountBalances:n});case"SET_BALANCE_LOADINGS":return Object.assign(Object.assign({},e),{balanceLoadings:Object.assign(Object.assign({},e.balanceLoadings),t.payload)});default:return e}};!function(e){e.Initial="Initial",e.Pending="Pending",e.ApproveSuccess="ApproveSuccess",e.TxSuccess="TxSuccess",e.Failed="Failed"}(Pe||(Pe={}));const je={height:void 0,width:void 0,apikey:"",feeRate:0,rebateTo:"",isReverseRouting:!1,contractStatus:Pe.Initial};const Me={settings:Le,wallet:Ne,globals:je,token:Be},Ue=Y({reducer:q({settings:De,wallet:_e,token:Fe,globals:(e=je,t)=>"SET_GLOBAL_PROPS"===t.type?Object.assign(Object.assign({},e),t.payload):e}),middleware:e=>e({serializableCheck:{ignoredActions:["SET_ACCOUNT_BALANCES","SET_ETH_BALANCE"],ignoredPaths:["token.accountBalances","token.ethBalance"]}}),preloadedState:Me}),He=e=>(null!=e?e:Ue.getState()).wallet.chainId,We=e=>(null!=e?e:Ue.getState()).wallet.latestBlockNumber,$e=e=>t=>Se(void 0,void 0,void 0,(function*(){t({type:"SET_ACCOUNT_BALANCES",payload:e})})),Ve=e=>t=>Se(void 0,void 0,void 0,(function*(){t({type:"SET_BALANCE_LOADINGS",payload:e})}));var ze=[{constant:!0,inputs:[],name:"getCurrentBlockTimestamp",outputs:[{name:"timestamp",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{components:[{name:"target",type:"address"},{name:"callData",type:"bytes"}],name:"calls",type:"tuple[]"}],name:"aggregate",outputs:[{name:"blockNumber",type:"uint256"},{name:"returnData",type:"bytes[]"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"getLastBlockHash",outputs:[{name:"blockHash",type:"bytes32"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"addr",type:"address"}],name:"getEthBalance",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"getCurrentBlockDifficulty",outputs:[{name:"difficulty",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"getCurrentBlockGasLimit",outputs:[{name:"gaslimit",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"getCurrentBlockCoinbase",outputs:[{name:"coinbase",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"blockNumber",type:"uint256"}],name:"getBlockHash",outputs:[{name:"blockHash",type:"bytes32"}],payable:!1,stateMutability:"view",type:"function"}],Ke={[Ce.MAINNET]:{MULTI_CALL:"0xeefba1e63905ef1d7acba5a8513c70307c1ce441",DODO_APPROVE:"0xCB859eA579b28e02B87A1FDE08d087ab9dbE5149",ERC20_HELPER:"0xD9ef2d1583e8Aa196123e773BE38B539a4d149df"},[Ce.RINKEBY]:{MULTI_CALL:"0xb7E1C577f95959a3eD11f9281702850328b4e0e4",DODO_APPROVE:"0xcC8d87A7C747eeE4242045C47Ef25e0A81D56ae3",ERC20_HELPER:"0x6A42091d713A67E25a1D11aeE14E7AEB96E0331f"},[Ce.GOERLI]:{MULTI_CALL:"0x696E25A5e2AEd1C55E6d6Cfa0532Bbda9020165d",DODO_APPROVE:"0xC9143e54021f4a6d33b9b89DBB9F458AaEdd56FB",ERC20_HELPER:"0x24549FC74B3076A962624A26370ed556c467F74C"},[Ce.BSC]:{MULTI_CALL:"0x1Ee38d535d541c55C9dae27B12edf090C608E6Fb",DODO_APPROVE:"0xa128Ba44B2738A558A1fdC06d6303d52D3Cef8c1",ERC20_HELPER:"0x566651Ad34f6306872FaC5fB95bbF4C9beE8D8F2"},[Ce.HECO]:{MULTI_CALL:"0x76a328B3440B9276a31523e731B34082df7a6f1A",DODO_APPROVE:"0x68b6c06Ac8Aa359868393724d25D871921E97293",ERC20_HELPER:"0x270C2abC692Dd476B860CCbDfD6D8146BF61f8D8"},[Ce.POLYGON]:{MULTI_CALL:"0xc9eD9B18e447e600238fe50e944B9062B664DEa4",DODO_APPROVE:"0x292E6b2e054e1157df71C1C9510265CA8C0c7672",ERC20_HELPER:"0xfd24312Ec7871A6D1a31e454D5AbB16c6c25a9b3"},[Ce.ARBITRUM_ONE]:{MULTI_CALL:"0xF718F2bd590E5621e53f7b89398e52f7Acced8ca",DODO_APPROVE:"0xA867241cDC8d3b0C07C85cC06F25a0cD3b5474d8",ERC20_HELPER:"0x7C062B9C584fA6eC2504270790D38240A2c5fE72"},[Ce.ARBITRUM_RINKEBY]:{MULTI_CALL:"0x696E25A5e2AEd1C55E6d6Cfa0532Bbda9020165d",DODO_APPROVE:"0x5BaF16d57620Cb361F622232F3cb4090e35F3da2",ERC20_HELPER:"0x5B2fd46E6E3Ff1E479d651ec0b210882Aa9871dF"},[Ce.AURORA]:{MULTI_CALL:"0x989DcAA95801C527C5B73AA65d3962dF9aCe1b0C",DODO_APPROVE:"0x335aC99bb3E51BDbF22025f092Ebc1Cf2c5cC619",ERC20_HELPER:"0xE8C9A78725D0451FA19878D5f8A3dC0D55FECF25"},[Ce.MOONRIVER]:{MULTI_CALL:"0x2ff2CeE6E9359F9eA1cF2f51d18bF9F2045447E4",DODO_APPROVE:"0xE8C9A78725D0451FA19878D5f8A3dC0D55FECF25",ERC20_HELPER:"0x6373ceB657C83C91088d328622573FB766064Ac4"},[Ce.OKCHAIN]:{MULTI_CALL:"0x5e84190a270333aCe5B9202a3F4ceBf11b81bB01",DODO_APPROVE:"0x7737fd30535c69545deeEa54AB8Dd590ccaEBD3c",ERC20_HELPER:"0x4775b1858f1e417C9609D455C3Ad8751ec01daC4"},[Ce.OPTIMISM]:{MULTI_CALL:"0xb98Ac2fEFc8b73aeAE33D02BB00c26E12afCa9Df",DODO_APPROVE:"0xa492d6eABcdc3E204676f15B950bBdD448080364",ERC20_HELPER:"0x42E456ea0dd7538ea103fBb1d0388D14C97bB5b2"},[Ce.BOBA]:{MULTI_CALL:"0xD56281EF996B6B29874C77D2e1464216E8043127",DODO_APPROVE:"0x8F8Dd7DB1bDA5eD3da8C9daf3bfa471c12d58486",ERC20_HELPER:"0x9FCFD9ff955D36856F8EE480471B05488C0eB5cA"},[Ce.AVALANCHE]:{MULTI_CALL:"0x97f0153E7F5749640aDF3Ff9CFC518b79D6Fe53b",DODO_APPROVE:"0xCFea63e3DE31De53D68780Dd65675F169439e470",ERC20_HELPER:"0xC3528D128CC227fd60793007b5e3FdF7c2945282"},[Ce.CRONOS]:{MULTI_CALL:"0x4f4408D78F9E9e242c17C635FbD0f1952951c917",DODO_APPROVE:"0x9B736bB8f336f61E16454DCA4dE130703D151042",ERC20_HELPER:"0xbd2F5c60cf7d60daD2106ceD4D21b90722761f14"}};function Ge(e,t,...n){return Se(this,void 0,void 0,(function*(){const o=[];for(const e of n)for(const t of e)t.callData&&o.push(t.callData);const i=yield function(e,t,n){return Se(this,void 0,void 0,(function*(){const o=yield Ye(e,t,n),i=new Map;for(const{req:e,resp:t}of o)i.set(e,t);return e.map((e=>({req:e,resp:i.get(e)})))}))}(o,e,t),r=new Map;for(const{req:e,resp:t}of i)r.set(e,null==t?void 0:t.result);return n.map((e=>e.filter((e=>!e.callData||r.get(e.callData))).map(((e,t)=>e.processor(e.callData?r.get(e.callData):null,t)))))}))}function Ye(e,t,n){return Se(this,void 0,void 0,(function*(){let o=[e];e.length>800&&(o=i(e,800));let r=[];const a=o.map((e=>Se(this,void 0,void 0,(function*(){const o=e.map((e=>[e.to,e.data])),i={data:t.interface.encodeFunctionData("aggregate",[o]),to:n};let a;try{a=yield t.provider.call(i)}catch(o){const i=e.length;if(i>20){const o=Math.floor(i/2),[a,s]=yield Promise.all([Ye(e.slice(0,o),t,n),Ye(e.slice(o,i),t,n)]);r=[...r,...a,...s]}else{const e="[sendCallReqs] error";console.error(e,o)}}if(void 0===a)throw new Error("Unexpected batch result");const[s,l]=Q.decode(["uint256","bytes[]"],a);if(e.length!==l.length)throw new Error("Unexpected length mismatch");return l.map(((t,n)=>({resp:{result:t},req:e[n]})))}))));return(yield Promise.allSettled(a)).filter((e=>"fulfilled"===e.status)).forEach((({value:e})=>{r=[...r,...e]})),r}))}function qe(e,t,n,o){if(!function(e){try{return v(e)}catch(e){return!1}}(e)||e===Z)throw Error(`Invalid 'address' parameter '${e}'.`);return new X(e,t,function(e,t){return t?function(e,t){return e.getSigner(t).connectUnchecked()}(e,t):e}(n,o))}function Xe(){const{provider:e,account:t,chainId:n}=z(),[o,i]=E(!1),r=w((()=>Ke[n]),[n]),a=C(((n,o)=>{if(e)return qe(n,o,e,t)}),[e,t]),s=C((e=>{if(!r)return;const{MULTI_CALL:t}=r,n=a(t,ze);return(()=>Se(this,void 0,void 0,(function*(){if(n){i(!0);try{const[o]=yield Ge(n,t,e);return o}catch(e){console.error("Contract: useMultiContract is error",e)}i(!1)}})))()}),[r,a]);return{getContract:a,contractConfig:r,call:s,loading:o}}var Ze=[{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"isERC20",outputs:[{internalType:"bool",name:"isOk",type:"bool"},{internalType:"string",name:"symbol",type:"string"},{internalType:"string",name:"name",type:"string"},{internalType:"uint256",name:"decimals",type:"uint256"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"allownance",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"address",name:"user",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"judgeERC20",outputs:[{internalType:"string",name:"symbol",type:"string"},{internalType:"string",name:"name",type:"string"},{internalType:"uint256",name:"decimals",type:"uint256"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"allownance",type:"uint256"}],stateMutability:"view",type:"function"}];function Qe(){const{provider:e,account:t}=z(),o=I(),i=R(We);A((()=>{(()=>{Se(this,void 0,void 0,(function*(){if(!e||!t)return;const i=yield e.getBalance(t);o((e=>t=>Se(void 0,void 0,void 0,(function*(){t({type:"SET_ETH_BALANCE",payload:e})})))(new n(i.toString()).div(1e18)))}))})()}),[e,t,o,i])}function Je(){const{provider:e,chainId:t}=z(),n=I();A((()=>{const o=e=>{n((e=>t=>Se(void 0,void 0,void 0,(function*(){t({type:"SET_BLOCK_NUMBER",payload:e})})))(e))};return(()=>{Se(this,void 0,void 0,(function*(){if(!e||!t)return;const n=yield e.getBlockNumber();o(n),e.on("block",o)}))})(),()=>{null==e||e.off("block",o)}}),[e,n,t])}function et(e){return Number.parseInt(e,16)}class tt extends ie{constructor(e,t){super(e),this.customProvider=t,t.on("connect",(({chainId:e})=>{this.actions.update({chainId:et(e)})})).on("disconnect",(e=>{var t;null===(t=this.onError)||void 0===t||t.call(this,e),this.actions.resetState()})).on("chainChanged",(e=>{this.actions.update({chainId:et(e)})})).on("accountsChanged",(e=>{this.actions.update({accounts:e})}))}activate(){return Se(this,void 0,void 0,(function*(){this.actions.startActivation();const e=this.customProvider;try{const[{chainId:t},n]=yield Promise.all([e.getNetwork(),e.listAccounts()]);this.actions.update({chainId:t,accounts:n})}catch(e){throw this.actions.resetState(),e}}))}}function nt([e,t]){return[e,t]}var ot;function it(){return it=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},it.apply(this,arguments)}var rt,at;function st(){return st=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},st.apply(this,arguments)}var lt;!function(e){e.INTEGRATOR="integrator",e.METAMASK="metamask",e.WALLET_CONNECT="walletConnect"}(lt||(lt={}));const ct={[lt.METAMASK]:{name:"MetaMask",type:lt.METAMASK,icon:function(e){return x.createElement("svg",it({height:355,viewBox:"0 0 397 355",width:397,xmlns:"http://www.w3.org/2000/svg"},e),ot||(ot=x.createElement("g",{fill:"none",fillRule:"evenodd",transform:"translate(-1 -1)"},x.createElement("path",{d:"m114.622644 327.195472 52.004717 13.810198v-18.05949l4.245283-4.249292h29.716982v21.246459 14.872523h-31.839624l-39.268868-16.997169z",fill:"#cdbdb2"}),x.createElement("path",{d:"m199.528305 327.195472 50.943397 13.810198v-18.05949l4.245283-4.249292h29.716981v21.246459 14.872523h-31.839623l-39.268868-16.997169z",fill:"#cdbdb2",transform:"matrix(-1 0 0 1 483.96227 0)"}),x.createElement("path",{d:"m170.872644 287.889523-4.245283 35.056657 5.306604-4.249292h55.18868l6.367925 4.249292-4.245284-35.056657-8.490565-5.311615-42.452832 1.062323z",fill:"#393939"}),x.createElement("path",{d:"m142.216984 50.9915022 25.471698 59.4900858 11.674528 173.158643h41.391511l12.735849-173.158643 23.349056-59.4900858z",fill:"#f89c35"}),x.createElement("path",{d:"m30.7783023 181.657226-29.71698153 86.048161 74.29245393-4.249293h47.7594343v-37.181303l-2.122641-76.487253-10.613208 8.498583z",fill:"#f89d35"}),x.createElement("path",{d:"m87.0283032 191.218134 87.0283028 2.124646-9.551886 44.617563-41.391511-10.623229z",fill:"#d87c30"}),x.createElement("path",{d:"m87.0283032 192.280457 36.0849058 33.994334v33.994334z",fill:"#ea8d3a"}),x.createElement("path",{d:"m123.113209 227.337114 42.452831 10.623229 13.79717 45.679888-9.551886 5.311615-46.698115-27.620398z",fill:"#f89d35"}),x.createElement("path",{d:"m123.113209 261.331448-8.490565 65.864024 56.25-39.305949z",fill:"#eb8f35"}),x.createElement("path",{d:"m174.056606 193.34278 5.306604 90.297451-15.919812-46.211049z",fill:"#ea8e3a"}),x.createElement("path",{d:"m74.2924539 262.393771 48.8207551-1.062323-8.490565 65.864024z",fill:"#d87c30"}),x.createElement("path",{d:"m24.4103777 355.878193 90.2122663-28.682721-40.3301901-64.801701-73.23113313 5.311616z",fill:"#eb8f35"}),x.createElement("path",{d:"m167.688682 110.481588-45.636793 38.243627-35.0235858 42.492919 87.0283028 3.186969z",fill:"#e8821e"}),x.createElement("path",{d:"m114.622644 327.195472 56.25-39.305949-4.245283 33.994334v19.121813l-38.207548-7.43626z",fill:"#dfcec3"}),x.createElement("path",{d:"m229.245286 327.195472 55.18868-39.305949-4.245283 33.994334v19.121813l-38.207548-7.43626z",fill:"#dfcec3",transform:"matrix(-1 0 0 1 513.679252 0)"}),x.createElement("path",{d:"m132.665096 212.464593-11.674528 24.433427 41.39151-10.623229z",fill:"#393939",transform:"matrix(-1 0 0 1 283.372646 0)"}),x.createElement("path",{d:"m23.349057 1.06232296 144.339625 109.41926504-24.410378-59.4900858z",fill:"#e88f35"}),x.createElement("path",{d:"m23.349057 1.06232296-19.10377392 58.42776294 10.61320772 63.7393781-7.42924541 4.249292 10.61320771 9.560906-8.49056617 7.436261 11.67452847 10.623229-7.4292454 6.373938 16.9811323 21.246459 79.5990577-24.433428c38.915096-31.161473 58.018869-47.096318 57.311322-47.804533-.707548-.708215-48.820756-37.1813036-144.339625-109.41926504z",fill:"#8e5a30"}),x.createElement("g",{transform:"matrix(-1 0 0 1 399.056611 0)"},x.createElement("path",{d:"m30.7783023 181.657226-29.71698153 86.048161 74.29245393-4.249293h47.7594343v-37.181303l-2.122641-76.487253-10.613208 8.498583z",fill:"#f89d35"}),x.createElement("path",{d:"m87.0283032 191.218134 87.0283028 2.124646-9.551886 44.617563-41.391511-10.623229z",fill:"#d87c30"}),x.createElement("path",{d:"m87.0283032 192.280457 36.0849058 33.994334v33.994334z",fill:"#ea8d3a"}),x.createElement("path",{d:"m123.113209 227.337114 42.452831 10.623229 13.79717 45.679888-9.551886 5.311615-46.698115-27.620398z",fill:"#f89d35"}),x.createElement("path",{d:"m123.113209 261.331448-8.490565 65.864024 55.18868-38.243626z",fill:"#eb8f35"}),x.createElement("path",{d:"m174.056606 193.34278 5.306604 90.297451-15.919812-46.211049z",fill:"#ea8e3a"}),x.createElement("path",{d:"m74.2924539 262.393771 48.8207551-1.062323-8.490565 65.864024z",fill:"#d87c30"}),x.createElement("path",{d:"m24.4103777 355.878193 90.2122663-28.682721-40.3301901-64.801701-73.23113313 5.311616z",fill:"#eb8f35"}),x.createElement("path",{d:"m167.688682 110.481588-45.636793 38.243627-35.0235858 42.492919 87.0283028 3.186969z",fill:"#e8821e"}),x.createElement("path",{d:"m132.665096 212.464593-11.674528 24.433427 41.39151-10.623229z",fill:"#393939",transform:"matrix(-1 0 0 1 283.372646 0)"}),x.createElement("path",{d:"m23.349057 1.06232296 144.339625 109.41926504-24.410378-59.4900858z",fill:"#e88f35"}),x.createElement("path",{d:"m23.349057 1.06232296-19.10377392 58.42776294 10.61320772 63.7393781-7.42924541 4.249292 10.61320771 9.560906-8.49056617 7.436261 11.67452847 10.623229-7.4292454 6.373938 16.9811323 21.246459 79.5990577-24.433428c38.915096-31.161473 58.018869-47.096318 57.311322-47.804533-.707548-.708215-48.820756-37.1813036-144.339625-109.41926504z",fill:"#8e5a30"})))))},link:"https://metamask.io"},[lt.WALLET_CONNECT]:{name:"WalletConnect",type:lt.WALLET_CONNECT,icon:function(e){return x.createElement("svg",st({height:512,viewBox:"0 0 512 512",width:512,xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink"},e),rt||(rt=x.createElement("radialGradient",{id:"a",cx:"0%",cy:"50%",r:"100%"},x.createElement("stop",{offset:0,stopColor:"#5d9df6"}),x.createElement("stop",{offset:1,stopColor:"#006fff"}))),at||(at=x.createElement("g",{fill:"none",fillRule:"evenodd"},x.createElement("path",{d:"m256 0c141.384896 0 256 114.615104 256 256s-114.615104 256-256 256-256-114.615104-256-256 114.615104-256 256-256z",fill:"url(#a)"}),x.createElement("path",{d:"m64.6917558 37.7088298c51.5328072-50.2784397 135.0839942-50.2784397 186.6167992 0l6.202057 6.0510906c2.57664 2.5139218 2.57664 6.5897948 0 9.1037177l-21.215998 20.6995759c-1.288321 1.2569619-3.3771 1.2569619-4.665421 0l-8.534766-8.3270205c-35.950573-35.0754962-94.237969-35.0754962-130.188544 0l-9.1400282 8.9175519c-1.2883217 1.2569609-3.3771016 1.2569609-4.6654208 0l-21.2159973-20.6995759c-2.5766403-2.5139229-2.5766403-6.5897958 0-9.1037177zm230.4934852 42.8089117 18.882279 18.4227262c2.576627 2.5139103 2.576642 6.5897593.000032 9.1036863l-85.141498 83.070358c-2.576623 2.513941-6.754182 2.513969-9.33084.000066-.00001-.00001-.000023-.000023-.000033-.000034l-60.428256-58.957451c-.64416-.628481-1.68855-.628481-2.33271 0-.000004.000004-.000008.000007-.000012.000011l-60.4269683 58.957408c-2.5766141 2.513947-6.7541746 2.51399-9.3308408.000092-.0000151-.000014-.0000309-.000029-.0000467-.000046l-85.14386774-83.071463c-2.57663928-2.513921-2.57663928-6.589795 0-9.1037163l18.88231264-18.4226955c2.5766393-2.5139222 6.7541993-2.5139222 9.3308397 0l60.4291347 58.9582758c.6441608.62848 1.6885495.62848 2.3327103 0 .0000095-.000009.0000182-.000018.0000277-.000025l60.4261065-58.9582508c2.576581-2.51398 6.754142-2.5140743 9.33084-.0002103.000037.0000354.000072.0000709.000107.0001063l60.429056 58.9583548c.644159.628479 1.688549.628479 2.332709 0l60.428079-58.9571925c2.57664-2.5139231 6.754199-2.5139231 9.330839 0z",fill:"#fff",fillRule:"nonzero",transform:"translate(98 160)"}))))}}},dt={};function ut({provider:e,jsonRpcUrlMap:t,defaultChainId:n}){const o=console.error,i=w((()=>function(e,t){if(t){if(oe.isProvider(t))return nt(K((e=>new tt(e,t))));if(oe.isProvider(t.provider))throw new Error("Eip1193Bridge is experimental: pass your ethers Provider directly");return nt(K((n=>new ee({actions:n,provider:t,onError:e}))))}}(o,e)),[o,e]),r=w((()=>function(e){return nt(K((t=>new ne({actions:t,onError:e}))))}(o)),[o]),a=w((()=>t?Object.assign(Object.assign({},Ae),t):Ae),[t]),s=w((()=>function(e,t,n,o){return nt(K((i=>new te({actions:i,options:{rpc:t,qrcode:e},onError:o,defaultChainId:n}))))}(!0,a,n,o)),[a,n,o]);return i&&(dt[lt.INTEGRATOR]=i),dt[lt.METAMASK]=r,dt[lt.WALLET_CONNECT]=s,Object.values(dt)}function pt(){const{chainId:e}=z(),t=R(He);return w((()=>e||t||1),[e,t])}function mt({tokenList:e,popularTokenList:t}){const o=I(),[i,a]=E([]),{account:s}=z(),l=pt(),c=R(We),d=w((()=>(null==t?void 0:t.filter((e=>e.chainId===l)))||[]),[t,l]);!function({tokenList:e,addresses:t,blockNumber:o}){const{account:i}=z(),r=I(),a=w((()=>[...(null==e?void 0:e.map((e=>e.address)))||[],...t||[]].map((e=>e.toLocaleLowerCase()))),[e,t]),{getContract:s,contractConfig:l,call:c}=Xe(),[d,u]=E(),p=w((()=>{if(!i||!a.length||!l)return;const{DODO_APPROVE:e,ERC20_HELPER:t}=l,o=s(t,Ze);if(!o)return;let c={};const d=a.map((r=>(c[r]=!0,{callData:{data:o.interface.encodeFunctionData("isERC20",[r,i,e]),to:t},processor:e=>{const t=new J(Ze).decodeFunctionResult("isERC20",e),{balance:o,isOk:i}=t,a=parseInt(t.decimals),s=new n(10).pow(a),l=new n(t.allownance.toString()).div(s);return i?{address:r,decimals:a,symbol:t.symbol,name:t.name,balance:new n(o.toString()).div(s),allowance:l}:{address:r,balance:new n(0),allowance:new n(0)}}})));return r(Ve(c)),d}),[i,s,JSON.stringify(a)]);A((()=>{(()=>{Se(this,void 0,void 0,(function*(){if(!p)return;const e=yield c(p),t={};e&&(e.forEach((e=>{t[e.address.toLocaleLowerCase()]={tokenBalances:e.balance,tokenAllowances:e.allowance}})),r($e(t))),u(e);let n={};a.forEach((e=>{n[e]=!1})),r(Ve(n))}))})()}),[p,o])}({addresses:w((()=>{const e=i.map((({address:e})=>e));return null==t||t.forEach((({address:t})=>{e.includes(t)||e.push(t)})),e}),[i,t]),blockNumber:c}),A((()=>{(()=>{Se(this,void 0,void 0,(function*(){let t=[];if(e)t=e;else{const e=yield import("./tokenList-4ef211de.js");t=r(e.default,d,"address")}const n=l,i=t.filter((e=>e.chainId===n));a(i),o((e=>t=>Se(void 0,void 0,void 0,(function*(){t({type:"SET_TOKEN_LIST",payload:e})})))(i))}))})()}),[e,o,l,d]),A((()=>{o($e({}))}),[s,l]),A((()=>{o((e=>t=>Se(void 0,void 0,void 0,(function*(){t({type:"SET_POPULAR_TOKEN_LIST",payload:e})})))(d))}),[d,o])}const ht=e=>(null!=e?e:Ue.getState()).token.tokenList,ft=e=>(null!=e?e:Ue.getState()).token.accountBalances,gt=e=>(null!=e?e:Ue.getState()).token.ethBalance||new n(NaN),bt=e=>(null!=e?e:Ue.getState()).token.defaultFromToken,yt=e=>(null!=e?e:Ue.getState()).token.defaultToToken,vt=e=>(null!=e?e:Ue.getState()).token.balanceLoadings;function xt(){const{account:e,chainId:t}=z(),n=R(ft),o=R(gt),i=w((()=>Te[t||1]),[t]),r=C((t=>{var r;if(!e)return null;if(t.symbol===i.symbol&&Ee(t.address,i.address))return!o||(null==o?void 0:o.isNaN())?null:o;const a=null===(r=n[t.address.toLocaleLowerCase()])||void 0===r?void 0:r.tokenBalances;return!a||(null==a?void 0:a.isNaN())?null:a}),[n,o,e]);return r}var Et;function wt(e,t,n,o=0){if(n&&(e=e.toLocaleLowerCase(),t=t.toLocaleLowerCase()),e===t)return Et.fully+o;const i=e.indexOf(t);return 0===i?Et.prefix+o:i>0?Et.other+o:Et.none}!function(e){e[e.fully=1]="fully",e[e.prefix=2]="prefix",e[e.other=3]="other",e[e.none=0]="none"}(Et||(Et={}));function Ct({value:e,onChange:t,occupiedAddrs:o,hiddenAddrs:i,showAddrs:r}){const[a,s]=E(""),l=R(ht),c=pt(),d=xt(),u=w((()=>new Set(i?i.map((e=>e.toLowerCase())):void 0)),[i]),p=w((()=>r?new Set(r.map((e=>e.toLowerCase()))):void 0),[r]),m=C((e=>e.filter((e=>{if(e.chainId!==c)return!1;let t=!0;return t=p?p.has(e.address.toLowerCase()):!u.has(e.address.toLowerCase()),t}))),[p,c,u]),h=C((t=>{if(null===t)return null;const i=[];a?t.forEach((e=>{const t=((e,t,{matchAddress:n}={})=>{if(!t)return 0;const o=t.toLocaleLowerCase();let i=0;n&&e.address.toLocaleLowerCase()===o&&(i=1),i||(i=wt(e.symbol.toLocaleLowerCase(),o,!1,1));if(i)e.name.toLocaleLowerCase()===o&&(i=Et.fully+1);else{let t=wt(e.name.toLocaleLowerCase(),o,!1,10);t=t===Et.fully+10?Et.fully+1:t,i=t}return i})(e,a,{matchAddress:!0});t&&i.push({sort:t,token:e})})):t.forEach((e=>{i.push({sort:0,token:e})}));const r=[];return i.sort(((t,i)=>{const r=t.token,a=i.token;if(e){if(r.address===e.address)return-1;if(a.address===e.address)return 1}if(null==o?void 0:o.includes(r.address))return-1;if(null==o?void 0:o.includes(a.address))return 1;const s=d&&d(r)||new n(0),l=d&&d(a)||new n(0);return s.eq(l)?t.sort!==i.sort?t.sort>i.sort?1:-1:r.symbol.localeCompare(a.symbol):s.gt(l)?-1:1})).some((e=>!!(a&&r.length>21)||(r.push(e.token),!1))),r}),[a,d,o,e]),f=C((e=>{const n=e.address.toLowerCase();t(e,!!(null==o?void 0:o.some((e=>e.toLowerCase()===n))))}),[t,o]),g=w((()=>{const e=m(l);return h(e)||[]}),[l,m,h]);return{filter:a,setFilter:s,showTokenList:g,onSelectToken:f}}function At({width:e=24,height:t=24,marginRight:n=8,url:o,zIndex:i,cross:r,address:a,token:l,sx:c}){const[d,u]=E(!1),[p,m]=E(""),[h,f]=E(""),[g,b]=E(!1),y=C((()=>u(!0)),[]);let v=function(e){const t=R(ht),{chainId:n}=z();return w((()=>{if(!e)return;let o=t.find((({address:t,chainId:o})=>o===n&&t===e));return o||(o=t.find((({address:t})=>t===e))),o}),[e,t,n])}(a);l&&(v=l);const x=a||(null==v?void 0:v.address),O=null==v?void 0:v.symbol,T=null==O?void 0:O.charAt(0).toUpperCase(),k=w((()=>{const e=null==v?void 0:v.logoURI;return o||e||""}),[o,v]);return A((()=>{b(!1)}),[x,k]),A((()=>{r&&(k?function(e,t){const n=new XMLHttpRequest;let o;n.onload=function(){const e=new FileReader;e.onloadend=function(){t(e.result)},e.readAsDataURL(n.response)},n.onerror=function(){t()};try{o=new URL(e)}catch(e){}finally{n.open("GET",o||e),n.responseType="blob",n.send()}}(k,(e=>{m(e)})):m(""))}),[k,r]),A((()=>{try{let t=x;if(t&&t.length<15&&(t=t.padEnd(15,"0")),t){const n=new V(t,{size:e,format:"svg",margin:.2,background:[255,234,4,255]}).toString();f(`data:image/svg+xml;base64,${n}`)}}catch(e){console.error("generate Identicon error: ",e)}}),[x,e]),re(s,{sx:Object.assign({position:"relative",display:"flex",alignItems:"center",justifyContent:"center",minWidth:e,width:e,height:t,marginRight:n,zIndex:i},c||{}),style:{width:e,height:t},children:[!d&&ae(s,{sx:{typography:"ht",height:"100%",width:"100%",borderRadius:"50%",border:"transparent 2px solid",borderColor:"text.primary",color:"text.primary",display:"flex",alignItems:"center",justifyContent:"center"},children:T}),ae(s,{component:"img",src:!(r?p:k)||g?h:r?p:k,onLoad:y,onError:e=>{const t=e.target;x&&h&&b(!0),t.onerror=null},sx:{position:"absolute",top:"0",bottom:"0",left:"0",right:"0",borderRadius:"50%",overflow:"hidden",width:"100%",height:"100%"}})]})}function Ot({token:t,onClick:n}){var o,i;const r=l();return re(s,{component:c,sx:{display:"flex",alignItems:"center",color:r.palette.text.primary,typography:"h5",fontWeight:600},onClick:e=>{n&&n(e)},"data-testid":"swap-select-token-btn",children:[(null==t?void 0:t.address)?re(se,{children:[ae(At,{url:null==t?void 0:t.logoURI,address:null!==(o=null==t?void 0:t.address)&&void 0!==o?o:"",marginRight:6}),ae(s,{children:null!==(i=null==t?void 0:t.symbol)&&void 0!==i?i:"-"})]}):ae(e,{id:"SELECT TOKEN"}),ae(s,{sx:{ml:7,width:12,transform:"rotateX(180deg)"},component:L})]})}function Tt({onClick:t,balance:n,decimals:o,address:i,showMaxBtn:r}){const{palette:a}=l();return re(s,{sx:{display:"flex",typography:"body2",color:a.text.secondary},children:[ae(e,{id:"Balance:"})," ",i?be({input:n,decimals:Math.min(o||4,4)}):"-",r&&n&&n.gt(0)&&ae(s,{component:c,sx:{ml:6,color:(null==n?void 0:n.gt(0))?a.primary.main:a.text.disabled,cursor:i&&t?"pointer":"unset"},onClick:()=>t&&t(n?n.toString():""),children:ae(e,{id:"Max"})})]})}function kt({readOnly:e,sx:t,value:n,decimals:o,onChange:i,suffix:r,withClear:a,onFocus:u,placeholder:p}){const m=l(),h=w((()=>r||(a&&n&&i?ae(s,{component:c,sx:{ml:5,width:18,height:18,borderRadius:"50%",backgroundColor:"border.main",display:"flex",justifyContent:"center",alignItems:"center"},onClick:()=>{i&&i("")},children:ae(s,{component:D,sx:{width:12,color:"text.primary"}})}):void 0)),[i,r,m.palette.text.primary,n,a]);return re(s,{sx:Object.assign({mt:12,display:"flex",justifyContent:"space-between",alignItems:"center"},t),"data-testid":"number-input-wrapper",children:[ae(d,{fullWidth:!0,value:n,readOnly:e,placeholder:p||"0.00",onFocus:u,onChange:e=>{const t=e.target.value,n=0===t.length?"":xe(t,o);i&&i(n)},sx:{width:"inherit",border:"none","& .MuiInput-input":{fontSize:24,border:"none",outline:"none",height:24,padding:0,color:"text.primary","&::placeholder":{fontSize:24,color:"text.disabled"}}}}),!e&&n&&h]})}function It({open:e,onClose:t,title:n,rightSlot:o,canBack:i=!0,children:r,height:a,testId:l}){return re(s,{sx:{position:"absolute",top:e?0:"100%",transition:"top 300ms",zIndex:1,left:0,right:0,bottom:0,display:"flex",flexDirection:"column",backgroundColor:"background.paper",borderRadius:16,height:a},"data-testid":l,"data-active":e?"1":"0",children:[n?re(s,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:20},children:[ae(s,{sx:{display:"flex",alignItems:"center",typography:"caption"},children:n}),o,!o&&i&&ae(s,{component:D,sx:{color:"text.secondary",cursor:"pointer"},onClick:t})]}):"",r]})}const Rt=e=>(null!=e?e:Ue.getState()).globals;function St({token:e,disabled:t,onClick:n}){return re(s,{sx:Object.assign({display:"inline-flex",alignItems:"center",p:8,border:"solid 1px",typography:"body2",borderRadius:8},t?{borderColor:"transparent",backgroundColor:"border.disabled",cursor:"auto"}:{borderColor:"border.main",cursor:"pointer","&:hover":{backgroundColor:"hover.default"}}),onClick:()=>{t||n()},children:[ae(At,{token:e}),e.symbol]})}function Lt({token:e,disabled:t,style:n,onClick:o}){const i=xt()(e),r=i?ge({input:i}):"";return re(s,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",typography:"body2",px:6,py:5,borderRadius:8,cursor:t?"auto":"pointer",opacity:t?.5:1,"&:hover":{backgroundColor:"hover.default"}},style:n,onClick:()=>{t||o()},"data-testid":"token-picker-item",children:[re(s,{sx:{display:"flex",alignItems:"center"},children:[ae(At,{token:e}),re(s,{children:[ae(s,{sx:{fontWeight:600,textAlign:"left"},children:e.symbol}),ae(s,{sx:{mt:4,textAlign:"left"},children:r})]})]}),ae(s,{sx:{color:"text.secondary"},children:e.name})]})}function Dt({value:e,onChange:t,occupiedAddrs:n,hiddenAddrs:o,showAddrs:i,visible:r}){var a;const l=pt(),c=R((e=>((e,t)=>(null!=t?t:Ue.getState()).token.popularTokenList.filter((({chainId:t})=>e===t)))(l,e))),{showTokenList:d,filter:p,setFilter:m,onSelectToken:h}=Ct({value:e,onChange:t,occupiedAddrs:n,hiddenAddrs:o,showAddrs:i}),f=O(null),g=O(null),[b,y]=E(0);A((()=>{r&&f.current&&y(f.current.offsetHeight-34)}),[f,r]);const v=C((({index:t,style:n})=>{const o=!!(null==c?void 0:c.length);if(0===t&&o)return ae(s,{sx:{position:"relative",display:"flex",gap:8,flexWrap:"wrap",pb:32,"&::after":{content:'""',position:"absolute",bottom:16,left:0,right:0,height:"1px",backgroundColor:"border.main"}},ref:g,style:Object.assign(Object.assign({},n),{visibility:n.height?"visible":"hidden",height:n.height?n.height:"auto"}),children:c.map((t=>ae(St,{token:t,disabled:(null==e?void 0:e.address)===t.address,onClick:()=>h(t)},t.address)))});const i=d[o?t-1:t];return ae(Lt,{token:i,disabled:!!e&&e.address===i.address,style:n,onClick:()=>h(i)})}),[d,c,g,e]),x=C((e=>{var t;if(0===e&&(null==c?void 0:c.length)){const e=(null===(t=g.current)||void 0===t?void 0:t.offsetHeight)||0;return e<=52?0:e}return 52}),[g,c]);return re(s,{sx:{display:"flex",flexDirection:"column",px:20,flex:1},children:[ae(u,{fullWidth:!0,height:48,value:p,onChange:e=>m(e.target.value),clearValue:()=>m(""),placeholder:le._("Enter the token symbol or address")}),ae(s,{sx:{mt:16,pb:16,flex:1,minHeight:64},ref:f,children:ae(ce,{height:b,itemCount:d.length+((null==c?void 0:c.length)?1:0),itemSize:x,width:"100%",className:"token-list",children:v},null===(a=g.current)||void 0===a?void 0:a.offsetHeight)})]})}function Nt({open:t,value:n,onClose:o,occupiedAddrs:i,onTokenChange:r}){const{height:a}=R(Rt);return ae(It,{height:a,open:t,onClose:o,title:ae(e,{id:"Select a token"}),testId:"token-picker-wrapper",children:ae(Dt,{value:n,visible:t,onChange:r,occupiedAddrs:i})})}function _t({sx:e,amt:t,token:n,readOnly:o,showMaxBtn:i,onMaxClick:r,fiatPriceTxt:a,occupiedAddrs:c,onInputFocus:d,onTokenClick:u,onInputChange:p,onTokenChange:m}){const h=l(),f=xt(),[g,b]=E(!1),y=n?f(n):null;return re(s,{sx:Object.assign({width:"100%",minHeight:133,padding:20,borderRadius:12,overflow:"hidden",display:"flex",flexDirection:"column",justifyContent:"space-between",backgroundColor:h.palette.background.input},e),children:[re(s,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[ae(Ot,{token:n,onClick:()=>b(!0)}),ae(Tt,{balance:y,onClick:r,showMaxBtn:i,address:null==n?void 0:n.address,decimals:null==n?void 0:n.decimals})]}),ae(kt,{value:t,onFocus:d,onChange:p,readOnly:o,withClear:!0}),ae(s,{sx:{mt:4,typography:"body2",color:h.palette.text.secondary},children:a}),ae(Nt,{value:n,open:g,occupiedAddrs:c,onClose:()=>{u&&u(),b(!1)},onTokenChange:(e,t)=>{m(e,t),b(!1)}})]})}const Bt={"en-US":de,"zh-CN":ue,pseudo:de};function Pt({locale:e,children:n}){return A((()=>{(()=>{Se(this,void 0,void 0,(function*(){yield function(e="en-US"){return Se(this,void 0,void 0,(function*(){le.loadLocaleData(e,{plurals:()=>Bt[e]});try{const t=yield import(`./locales/${e}.js`);le.load(e,t.messages||t.default.messages)}catch(e){}le.activate(e)}))}(e)}))})()}),[e]),ae(t,{i18n:le,children:n})}var Ft,jt,Mt;!function(e){e[e.Running=0]="Running",e[e.Success=1]="Success",e[e.Failed=2]="Failed",e[e.Warning=3]="Warning"}(Ft||(Ft={})),function(e){e.Canceled="canceled",e.Failed="failed",e.Success="success",e.Submitted="submitted"}(jt||(jt={})),function(e){e[e.Failed=0]="Failed",e[e.Success=1]="Success"}(Mt||(Mt={}));var Ut,Ht=[{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"guy",type:"address"},{name:"wad",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"}];!function(e){e[e.Failed=0]="Failed",e[e.Success=1]="Success",e[e.Warning=2]="Warning"}(Ut||(Ut={}));const Wt=(e,t)=>Se(void 0,void 0,void 0,(function*(){const{value:n,from:o,to:i,data:r}=e,a={from:o,to:i,value:n,data:r};n&&!/^0x0*$/.test(n)||delete a.value;try{return(yield t.estimateGas(a)).add(5e4)}catch(e){t.call(a).then((e=>{if("test"!==process.env.NODE_ENV)throw new Error("Unexpected issue with estimating the gas. Please try again.")})).catch((e=>{if("test"!==process.env.NODE_ENV)throw e}))}return null})),$t=(e,t)=>Se(void 0,void 0,void 0,(function*(){try{return yield t.getSigner().sendTransaction(e)}catch(e){throw 4001===(null==e?void 0:e.code)?new Error(le._("Transaction rejected.")):e}}));var Vt,zt;!function(e){e.Approval="APPROVAL",e.TX="TX",e.TypedSign="TypedSign"}(Vt||(Vt={})),function(e){e.Normal="Normal",e.Privacy="Privacy",e.LimitOrder="LimitOrder",e.RFQ="RFQ"}(zt||(zt={}));const Kt=new n(2).pow(256).minus(1),Gt=e=>t=>Se(void 0,void 0,void 0,(function*(){t({type:"SET_GLOBAL_PROPS",payload:e})}));function Yt({onTxFail:e,onTxSubmit:t,onTxSuccess:o}={}){const{account:i,provider:r}=z(),a=pt(),[s,l]=E(!1),[c,d]=E(new Map),u=I(),[p,m]=E(null),[h,f]=E(""),[g,b]=E(null),[y,v]=E(!1),[x,A]=E(),O=C(((s,c,p,h=!1,g,y,x,E)=>Se(this,void 0,void 0,(function*(){if(f(""),m(""),!i||!r)throw new Error("Submission: Cannot execute step when the wallet is disconnected");let w,C,O;A((()=>x)),l(!1);try{if(l(!0),c.opcode===Vt.Approval)O=yield((e,t,o,i,r,a)=>Se(void 0,void 0,void 0,(function*(){const s=qe(e,Ht,r,a).interface.encodeFunctionData("approve",[o,i.toFixed()]),l={from:t,to:e,data:s,value:`0x${new n("0").toString(16)}`,gasLimit:void 0},c=yield Wt(l,r);return c&&(l.gasLimit=c),yield $t(l,r)})))(c.token.address,i,c.contract,c.amt||Kt,r,i),w=O.hash,f(w);else{if(c.opcode!==Vt.TX)throw new Error(`Op ${c.opcode} not implemented!`);if(""===c.to)throw new Error("Submission: malformed to");if(0===c.data.length)throw new Error("Submission: malformed data");if(0===c.data.indexOf("0x")&&c.data.length<=2)throw new Error("Submission: malformed data");if(C={value:c.value,data:c.data,to:c.to,gasLimit:c.gasLimit,from:i,chainId:a},!C.gasLimit)try{const e=yield Wt(C,r);e&&(C.gasLimit=e)}catch(e){console.debug(e)}if(O=yield $t(C,r),w=O.hash,f(w),!w)throw new Error(`Unexpected tx: ${w}`)}}catch(t){if(l(!1),b({spec:c,brief:s,subtitle:p}),console.error(t),t.message){u(Gt({contractStatus:Pe.Failed}));const n={error:t.message,brief:s};y&&Object.assign(n,y),e&&e(t,y),m(function(e,t){var n;const o=null===(n=Te[e])||void 0===n?void 0:n.symbol,i=[{error:"insufficient",msg:le._("Insufficient funds - Please retry after depositing more {EtherTokenSymbol} into your wallet",{EtherTokenSymbol:o})},{error:["External Swap execution Failed","Return amount is not enough"],msg:le._("Price impact exceeds the slippage tolerance you set. Try increasing the slippage tolerance.")},{error:"SafeERC20: low-level call failed",msg:le._("SafeERC20: low-level call failed. Please log a Zendesk support ticket or contact the DODO team.")},{error:["User denied","cancel","User rejected","user rejected"],msg:le._("User denied transaction signature.")},{error:["Cannot set properties of undefined (setting 'loadingDefauIts'){\"originalError\":{",'[ethjs-query]while formatting outputs from RPC\'["value":["code":-32000,"message":"header not found"))'],msg:le._("RPC node data exception")},{error:['execution reverted:FORCESTOP ["originalError"'],msg:le._("ForceStop exception")},{error:["replacement transaction underpriced","Gasprice too low","transaction underprice"],msg:le._("Gas price is too low, please adjust in your wallet and try again")},{error:["MINT_INVALID"],msg:le._("No ForceStop access")},{error:["NOT_PHASE_EXE"],msg:le._("Unable to SETTLE during the cooling-off period")},{error:["params specify an EIP-1559transaction but the currentnetwork does not support"],msg:le._("Wallet incompatibility")},{error:["ALREADY_SETTLED"],msg:le._("This CP has been settled by other addrs")},{error:["create RFQ order failed]:LESS_THAN_FEE_LIMIT"],msg:le._("Service update, please wait and try again")}];let r="";return i.some((e=>Array.isArray(e.error)?e.error.some((n=>t.indexOf(n)>-1&&(r=e.msg,!0))):t.indexOf(e.error)>-1&&(r=e.msg,!0))),r||t}(a,t.message))}return jt.Failed}b({spec:c,brief:s,subtitle:p}),v(!1),l(!1);const T=Object.assign(Object.assign(Object.assign(Object.assign({brief:s},c),C),{tx:w,subtitle:p}),y);u(Gt({contractStatus:Pe.Pending})),t&&t(w,T),g&&g();const k={brief:s,spec:c,tx:w,subtitle:p};if(d((e=>e.set(w,[k,Ft.Running]))),h)return jt.Submitted;if(g&&g(),null==O?void 0:O.wait){const e=yield O.wait(1);if(v(!0),e.status===Mt.Success)return"TX"===T.opcode&&u(Gt({contractStatus:Pe.TxSuccess})),"APPROVAL"===T.opcode&&u(Gt({contractStatus:Pe.ApproveSuccess})),E&&E(w),o&&o(w,T),d((e=>e.set(w,[k,Ft.Success]))),jt.Success}return v(!0),d((e=>e.set(w,[k,Ft.Failed]))),jt.Failed}))),[i,a,l,r]),T=w((()=>({execute:O,requests:c,setShowing:b,waitingSubmit:s})),[O,c,b]),k=C((()=>{b(null),x&&(x(),A(void 0))}),[x]);return{showing:g,showingDone:y,transactionTx:h,errorMessage:p,setErrorMessage:m,closeShowing:k,ctxVal:T,requests:c}}function qt(){const{requests:e}=Zt(),t=[];return null==e||e.forEach((function([e,n]){n===Ft.Running&&t.push(e)})),{runningRequests:t,isInflight:t.length>0}}const Xt=k({execute:()=>Promise.resolve(jt.Canceled),requests:void 0,waitingSubmit:!1});function Zt(){return T(Xt)}var Qt;function Jt(){return Jt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},Jt.apply(this,arguments)}var en=function(e){return x.createElement("svg",Jt({width:"33px",height:"33px",viewBox:"0 0 33 33",xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink"},e),Qt||(Qt=x.createElement("g",{stroke:"none",strokeWidth:1,fill:"none",fillRule:"evenodd",strokeLinecap:"round",strokeLinejoin:"round"},x.createElement("g",{transform:"translate(-186.000000, -375.000000)",stroke:"currentColor",strokeWidth:4},x.createElement("g",{transform:"translate(18.000000, 291.000000)"},x.createElement("g",{transform:"translate(40.000000, 83.000000)"},x.createElement("path",{d:"M159,32 C159,15.9837423 146.016258,3 130,3"})))))))};function tn({showingDone:e,errorMessage:t}){return ae(s,t?{component:N,sx:{width:64,height:64,color:"error.main"}}:e?{component:_,sx:{width:64,height:64,color:"success.main"}}:{sx:{mx:"auto",border:e=>{var t;return`6px solid ${null===(t=e.palette)||void 0===t?void 0:t.background.input}`},borderRadius:"50%",width:"64px",height:"64px",position:"relative",animation:"loadingRotate 1.1s infinite linear","@keyframes loadingRotate":{"0%":{transform:"rotate(0deg)"},"100%":{transform:"rotate(359deg)"}}},children:ae(s,{component:en,sx:{position:"absolute",top:"-6px",right:"-6px",color:"primary.main"}})})}function nn({showingDone:e,showing:t}){return re(s,{sx:{display:"flex",alignItems:"center",flexDirection:"column"},children:[ae(s,{sx:{mt:60},children:e?le._("{0} confirmed",{0:null==t?void 0:t.brief}):le._("{0} pending",{0:null==t?void 0:t.brief})}),(null==t?void 0:t.subtitle)?ae(s,{sx:{mt:20,typography:"body2"},children:null==t?void 0:t.subtitle}):""]})}function on({isStarted:t,isEnded:n,tx:o}){const[i,r]=E(0),{chainId:a}=z(),l=w((()=>`https://${Ie[a||1]}/tx/${o}`),[o,a]),c=w((()=>{const e=Math.floor(i/60),t=i%60;return e?`${e}m ${t}s`:`${t}s`}),[i]),d=O();return A((()=>(r(0),d.current=setInterval((()=>{r((e=>e+1))}),1e3),()=>{clearInterval(d.current)})),[t]),A((()=>{clearInterval(d.current)}),[n]),re(s,{sx:{mt:20,pt:20,display:"flex",justifyContent:"space-between",alignItems:"center",typography:"body2",color:"text.secondary",border:"solid 1px transparent",borderTopColor:"border.main"},children:[re(s,{children:[ae(e,{id:"Transaction Time:"}),c]}),re(m,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},component:"a",href:l,target:"_blank",rel:"noopener noreferrer",children:[ae(e,{id:"Tx"}),ae(s,{component:B,sx:{width:16,height:16,ml:6}})]})]})}function rn(t){var{children:n}=t,o=Re(t,["children"]);const{ctxVal:i,showing:r,closeShowing:a,showingDone:l,errorMessage:c,transactionTx:d}=Yt(o),u=I();return re(Xt.Provider,{value:i,children:[n,ae(It,{open:!!r,onClose:a,children:re(s,{sx:{display:"flex",flexDirection:"column",justifyContent:"space-between",px:20,pb:20,flex:1,overflowY:"auto"},children:[re(s,{children:[ae(s,{sx:{textAlign:"center",pt:60},children:ae(tn,{showingDone:l,errorMessage:c})}),c?re(s,{sx:{textAlign:"center",mt:60},children:[ae(s,{children:ae(e,{id:"Something went wrong."})}),ae(s,{sx:{color:"text.secondary",mt:12,typography:"body2",wordBreak:"break-all"},children:c})]}):re(se,{children:[ae(nn,{showingDone:l,showing:r}),ae(on,{isStarted:!!r,isEnded:l,tx:d})]})]}),ae(p,{fullWidth:!0,size:p.Size.big,onClick:()=>{u(Gt({contractStatus:Pe.Initial})),a()},sx:{mt:20},children:ae(e,c?{id:"Dismiss"}:{id:"Close"})})]})})]})}function an({token:e,fiatPrice:t}){return{marginAmount:w((()=>{var i;const r=null!==(i=null==e?void 0:e.decimals)&&void 0!==i?i:6,a=((e,t,n)=>{const i=new o(e).times(new o(10).pow(t));return n?i:i.dp(0)})(null!=t?new n(500).div(t):new n(0),r);return(a.lt(new n(1).times(new n(10).pow(r-3)))?new n(0):a).toString(10)}),[null==e?void 0:e.decimals,t])}}function sn({width:e,height:t,feeRate:n,rebateTo:o,colorMode:i,apikey:r,defaultChainId:a,defaultToToken:s,defaultFromToken:l}){const c=I();A((()=>{i&&c((e=>t=>Se(void 0,void 0,void 0,(function*(){t({type:"SET_COLOR_MODE",payload:e})})))(i))}),[i]),A((()=>{var e;a&&c((e=a,t=>Se(void 0,void 0,void 0,(function*(){t({type:"SET_CHAIN_ID",payload:e})}))))}),[a]),A((()=>{c(Gt({height:t}))}),[t]),A((()=>{c(Gt({width:e}))}),[e]),A((()=>{r&&c(Gt({apikey:r}))}),[r]),A((()=>{n&&c(Gt({feeRate:n}))}),[n]),A((()=>{o&&c(Gt({rebateTo:o}))}),[o]),A((()=>{l&&c((e=>t=>Se(void 0,void 0,void 0,(function*(){t({type:"SET_DEFAULT_FROM_TOKEN",payload:e})})))(l))}),[l]),A((()=>{s&&c((e=>t=>Se(void 0,void 0,void 0,(function*(){t({type:"SET_DEFAULT_TO_TOKEN",payload:e})})))(s))}),[s])}function ln({refetch:e,interval:t}){let n;A((()=>(e(),clearTimeout(n),n=setInterval((()=>{e()}),null!=t?t:15e3),()=>clearTimeout(n))),[e])}function cn({fromToken:e,toToken:t,chainId:n}){const[o,i]=E(!1),[r,a]=E(""),[s,l]=E(""),c=C((()=>{if(!n||!e||!t)return;i(!0);const o=[e,t];pe.post("https://api.dodoex.io/price-api/api/v1/price/current/batch",{networks:o.map((()=>(e=>ke[e]||ke[Ce.MAINNET])(n))),addresses:o.map((e=>e.address)),symbols:o.map((e=>e.symbol)),isCache:!0},{headers:{apikey:"dodofrontend777888ofopensource"}}).then((n=>{var o;i(!1);const r=null===(o=n.data)||void 0===o?void 0:o.data;r&&(a(r.find((t=>t.address===e.address)).price),l(r.find((e=>e.address===t.address)).price))})).catch((e=>{i(!1),console.error(e)}))}),[n,e,t]);return ln({refetch:c}),{loading:o,refetch:c,toFiatPrice:s,fromFiatPrice:r}}const dn=e=>(null!=e?e:Ue.getState()).settings.slippage,un=e=>(null!=e?e:Ue.getState()).settings.ddl;var pn;function mn({toToken:e,fromToken:t,fromAmount:n,toAmount:o,marginAmount:i}){const{account:r,chainId:a,provider:s}=z(),l=R(He),c=w((()=>a||l),[a,l]),d=R(dn)||3,u=R(un)||20,{feeRate:p,rebateTo:m,apikey:h,isReverseRouting:f}=R(Rt),g=w((()=>Math.floor(Date.now()/1e3)+60*u),[u]),[b,y]=E(pn.Initial),[v,x]=E(null),[A,O]=E(""),[T,k]=E(null),[I,S]=E(null),[L,D]=E(null),[N,_]=E(me.from(0)),[B,P]=E(null),[F,j]=E(null),[M,U]=E(""),[H,W]=E(""),[$,V]=E(""),[K,G]=E(0),Y=C((()=>Se(this,void 0,void 0,(function*(){if(!c||!t||!e)return;if(!f&&!n)return;if(f&&!o)return;y(pn.Loading);const i={chainId:c,deadLine:g,apikey:h,slippage:d,source:"dodoV2AndMixWasm",toTokenAddress:e.address,toTokenDecimals:e.decimals,fromTokenAddress:t.address,fromTokenDecimals:t.decimals,userAddr:r||"0x0000000000000000000000000000000000000000"};f?i.toAmount=he(String(o||1),e.decimals).toString():i.fromAmount=he(String(n||1),t.decimals).toString(),m&&p&&(i.rebateTo=m,i.fee=p);try{const e=(yield pe.get("https://api.dodoex.io/route-service/v2/widget/getdodoroute",{params:i})).data.data;if((null==e?void 0:e.resAmount)?(y(pn.Success),x(e.resAmount),D(e.priceImpact),P(e.resPricePerFromToken),j(e.resPricePerToToken),k(e.baseFeeAmount),S(e.additionalFeeAmount),U(e.to),W(e.data),O(e.value),V(e.useSource),G(e.duration)):y(pn.Failed),!r||!s)return;const t=yield Wt({from:r,to:e.to,value:e.value,data:e.data},s);t&&_(t)}catch(e){y(pn.Failed),console.error(e)}}))),[g,r,c,e,p,d,m,t,s,n,o,h,f]);ln({refetch:Y});const q=w((()=>{const e=f?o:n;return b!==pn.Loading&&e?v:null}),[b,f,o,n,v]),X=function(){const{chainId:e,account:t}=z(),n=Zt();return C((({to:e,data:o,useSource:i,duration:r,ddl:a,gasLimit:s,subtitle:l,value:c})=>{const d=60*a,u=c;i&&"weth"!==i.toLowerCase()&&s&&s.lt(3e4)&&console.debug("Warning: GasLimit less than the minimum!");const p={from:t,to:e,data:o,value:u,route:i,duration:r,ddlSecRel:d,gasLimit:s};n.execute(le._("Swap"),Object.assign({opcode:Vt.TX},p),l)}),[t,e])}(),Z=C((e=>{t&&(f?v:n)&&X({to:M,data:H,useSource:$,duration:K,ddl:u,value:A,subtitle:e})}),[M,u,H,K,$,t,n,N,v,A,f]);return{status:b,refetch:Y,priceImpact:L,executeSwap:Z,baseFeeAmount:T,resAmount:q,additionalFeeAmount:I,resPricePerToToken:F,resPricePerFromToken:B}}!function(e){e.Initial="Initial",e.Loading="Loading",e.Failed="Failed",e.Success="Success"}(pn||(pn={}));function hn(e){mt(e),Qe(),Je();const{provider:t,connector:n}=z();A((()=>{const t=e.defaultChainId||1;(null==n?void 0:n.connectEagerly)?n.connectEagerly(t):n.activate(t)}),[n]),A((()=>{const e=null==t?void 0:t.provider;e&&e.once&&e.once("chainChanged",(()=>{setTimeout((()=>{window.location.reload()}),200||100)}))}),[t]);const o=e.width||375,i=e.height||494;return sn(Object.assign(Object.assign({},e),{width:o,height:i})),ae(s,{sx:{width:o,height:i,overflow:"hidden",position:"relative",display:"flex",flexDirection:"column",minWidth:335,minHeight:494,borderRadius:16,backgroundColor:"background.paper"},className:"dodo-widget-container",children:ae(rn,{...e,children:e.children})})}function fn(e){const t=h({mode:e.colorMode,theme:e.theme,lang:e.locale||"en-US"}),n=w((()=>e.defaultChainId||1),[e.defaultChainId]),o=ut({provider:e.provider,jsonRpcUrlMap:e.jsonRpcUrlMap,defaultChainId:n}),i=`${o.length}+${e.jsonRpcUrlMap?Object.entries(e.jsonRpcUrlMap):""}+${e.defaultChainId}+${n}`;return ae(S,{store:Ue,children:ae(Pt,{locale:e.locale,children:ae(f,{theme:t,children:re(G,{connectors:o,children:[ae(g,{container:".dodo-widget-container"}),ae(hn,{...e})]},i)})})})}function gn(e){const{width:t}=R(Rt),n=w((()=>{let e="";return"number"==typeof t?e=`${t}px`:t&&(e=t),e?`calc(${e} - 40px)`:"auto"}),[t]);return ae(b,{container:document.querySelector(".dodo-widget-container"),maxWidth:n,...e})}function bn({onClick:e}){const t=l();return ae(m,{sx:{width:"100%",position:"relative"},onClick:e,children:ae(s,{component:c,sx:{width:36,height:36,borderRadius:"50%",backgroundColor:t.palette.background.input,border:`4px solid ${t.palette.background.paper}`,display:"flex",alignItems:"center",justifyContent:"center",position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -50%) rotate(-90deg)"},children:ae(s,{component:P,sx:{width:18,color:"text.secondary"}})})})}function yn({open:t,execute:o,onClose:i,toToken:r,fromToken:a,fromAmount:d,toAmount:u,priceImpact:m,clearFromAmt:h,clearToAmt:f,baseFeeAmount:g,curToFiatPrice:b,curFromFiatPrice:y,pricePerFromToken:v,additionalFeeAmount:x}){var C,O;const T=l(),k=R(dn),S=I(),{contractStatus:D}=R(Rt),N=w((()=>new n(m).gt(15)),[m]),[_,B]=E(!1),[P,U]=E(!1);return A((()=>{D!==Pe.Pending&&i(),D===Pe.TxSuccess&&(f(),h())}),[D]),A((()=>{B(!1)}),[b]),ae(It,{open:t,onClose:()=>{S(Gt({contractStatus:Pe.Initial})),i()},title:ae(e,{id:"Swap summary"}),children:re(s,{sx:{margin:20,display:"flex",height:"100%",flexDirection:"column",borderTop:`1px solid ${T.palette.border.main}`},children:[re(s,{sx:{py:20,display:"flex",typography:"body2",alignItems:"center",justifyContent:"center",flexDirection:"column",borderBottom:`1px solid ${T.palette.border.main}`},children:[re(s,{sx:{display:"flex",alignItems:"center"},children:[re(s,{children:[re(s,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[ae(At,{width:16,height:16,url:null==a?void 0:a.logoURI,address:null!==(C=null==a?void 0:a.address)&&void 0!==C?C:"",marginRight:6}),ae(s,{children:`${be({input:d,decimals:null==a?void 0:a.decimals})} ${null==a?void 0:a.symbol}`})]}),ae(s,{sx:{mt:4,typography:"h6",color:T.palette.text.secondary},children:y?`$${ge({input:y,showDecimals:1})}`:"-"})]}),ae(s,{sx:{width:16,mx:16},component:F}),re(s,{children:[re(s,{sx:{display:"flex"},children:[ae(At,{width:16,height:16,marginRight:6,url:null==r?void 0:r.logoURI,address:null!==(O=null==r?void 0:r.address)&&void 0!==O?O:""}),ae(s,{children:`${be({input:u,decimals:null==r?void 0:r.decimals})} ${null==r?void 0:r.symbol}`})]}),ae(s,{sx:{typography:"h6",mt:4,color:T.palette.text.secondary},children:b?`$${ge({input:b,showDecimals:1})}(${m}%)`:"-"})]})]}),ae(s,{sx:{mt:12,typography:"h6"},children:`1 ${null==a?void 0:a.symbol} = ${be({input:new n(u).dividedBy(new n(d)),decimals:null==r?void 0:r.decimals})} ${null==r?void 0:r.symbol}`})]}),re(s,{sx:{py:15,typography:"body2",borderBottom:`1px solid ${T.palette.border.main}`},children:[re(s,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",color:T.palette.text.secondary},children:[re(s,{sx:{display:"flex",alignItems:"center"},children:[ae(s,{sx:{width:16,mr:7},component:j}),ae(e,{id:"Swap Detail"})]}),ae(s,{component:c,children:ae(s,{onClick:()=>U(!P),sx:{width:10,color:"text.secondary",transform:P?"rotateX(0deg)":"rotateX(180deg)"},component:L})})]}),re(s,{sx:{mt:16,display:P?"initial":"none"},children:[re(s,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[re(s,{sx:{display:"flex",alignItems:"center"},children:[ae(e,{id:"Basic Fee"}),ae(gn,{title:ae(e,{id:"Estimated service provider fees"}),ml:5})]}),ae(s,{children:`${be({input:g,decimals:null==r?void 0:r.decimals})} ${null==r?void 0:r.symbol}`})]}),re(s,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[re(s,{sx:{display:"flex",alignItems:"center"},children:[ae(e,{id:"Additional Fee"}),ae(gn,{title:ae(e,{id:"Additional routing fees set by the Widget user"}),ml:5})]}),ae(s,{children:`${be({input:x,decimals:null==r?void 0:r.decimals})} ${null==r?void 0:r.symbol}`})]}),re(s,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[re(s,{sx:{display:"flex",alignItems:"center"},children:[ae(e,{id:"Price Impact"}),ae(gn,{title:ae(e,{id:"Due to the market condition, market price and estimated price may have a slight difference"}),ml:5})]}),ae(s,{children:`${m}%`})]}),re(s,{sx:{mt:8,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[re(s,{sx:{display:"flex",alignItems:"center"},children:[ae(e,{id:"Slippage"}),ae(gn,{title:ae(e,{id:"High slippage tolerance will increase the success rate of transaction, but might not get the best quote."}),ml:5})]}),ae(s,{children:k})]})]})]}),ae(s,{sx:{flex:1}}),N&&re(s,{sx:{mb:14,display:"flex",cursor:"pointer",justifyContent:"center",alignItems:"center",typography:"h6"},onClick:()=>B(!_),children:[ae(s,{sx:{mr:4,width:18,height:18,alignItems:"center"},children:ae(s,_?{sx:{width:"100%",height:"100%",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"secondary.main"},children:ae(s,{component:M,sx:{width:14,color:"#1a1a1b"}})}:{sx:{width:"100%",height:"100%",borderRadius:4,border:`1px solid ${T.palette.text.secondary}`}})}),ae(s,{children:ae(e,{components:{0:ae(s,{component:"span",sx:{color:"error.main"}})},values:{priceImpact:m},id:"Price impact reaches <0>{priceImpact}</0>%, accept the quote"})})]}),ae(p,{isLoading:D==Pe.Pending,disabled:N&&!_,fullWidth:!0,onClick:()=>{o(),S(Gt({contractStatus:Pe.Pending}))},children:D==Pe.Pending?ae(e,{id:"Confirming"}):ae(e,{id:"Confirm swap"})})]})})}function vn(e){var{sx:t,maxVal:n,decimals:i=2,onInputChange:r}=e,a=Re(e,["sx","maxVal","decimals","onInputChange"]);return l(),ae(d,{...a,onChange:e=>{const t=0===e.target.value.length?null:xe(e.target.value,i),a=n&&t&&new o(t).gt(n)?n.toString():t;console.log("finalVal:",a),r&&r(a)}})}function xn({open:t,onClose:n}){const o=l(),i=I(),r=R(dn),a=R(un),c=w((()=>Number(r)>=50),[r]);return ae(It,{open:t,onClose:n,title:ae(e,{id:"Settings"}),children:re(s,{sx:{mx:20},children:[re(s,{sx:{py:20,borderTop:`1px solid ${o.palette.border.main}`},children:[re(s,{sx:{mb:16,display:"flex",alignItems:"center"},children:[ae(e,{id:"Slippage Tolerance"}),ae(gn,{title:ae(e,{id:"Attention: High slippage tolerance will increase the success rate of transaction, but might not get the best quote."}),ml:7})]}),re(s,{sx:{display:"flex",flexDirection:"column"},children:[ae(vn,{fullWidth:!0,maxVal:100,value:r,placeholder:3..toString(),onInputChange:e=>{i((e=>t=>Se(void 0,void 0,void 0,(function*(){t({type:"SET_SLIPPAGE",payload:e})})))(e))},suffix:ae(s,{sx:{color:"text.disabled"},children:"%"}),height:36}),c&&ae(s,{sx:{typography:"h6",mt:6,color:"error.main"},children:ae(e,{id:"Maximum slippage do not exceed 50%"})})]})]}),re(s,{sx:{py:20,borderTop:`1px solid ${o.palette.border.main}`},children:[re(s,{sx:{mb:16,display:"flex",alignItems:"center"},children:[ae(e,{id:"Transaction Deadline"}),ae(gn,{title:ae(e,{id:"If your transaction time exceeds the deadline, your transaction will be rescinded."}),ml:7})]}),ae(vn,{value:a,fullWidth:!0,height:36,placeholder:le._("{DEFAULT_SWAP_DDL} minutes",{DEFAULT_SWAP_DDL:20}),onInputChange:e=>{i((e=>t=>Se(void 0,void 0,void 0,(function*(){t({type:"SET_TRANSACTION_DDL",payload:e})})))(e?Math.max(Number(e),1):""))}})]})]})})}function En({toToken:t,fromToken:n,priceStatus:o,pricePerToToken:i,pricePerFromToken:r}){const[a,l]=E("-"),[d,u]=E(null),[p,m]=E("-"),[h,f]=E(null);A((()=>{l(null==n?void 0:n.symbol),m(null==t?void 0:t.symbol),u(i),f(r)}),[n,t,i,r]);const g=C((()=>{l(p),m(a),u(h),f(d)}),[a,d,p,h]);return ae(s,{sx:{display:"flex",justifyContent:"center",alignItems:"center"},children:{[pn.Initial]:"-",[pn.Loading]:re(se,{children:[ae(y,{sx:{mr:5}}),ae(e,{id:"Fetching best price..."})]}),[pn.Failed]:re(se,{children:[ae(s,{component:U,sx:{width:15,mr:5,color:"warning.main"}}),ae(e,{id:"Quote not available"})]}),[pn.Success]:re(se,{children:[ae(s,{sx:{typography:"body2"},children:`1 ${a} = ${ge({input:h,showDecimals:4})} ${p}`}),ae(s,{component:c,sx:{width:18,height:18,ml:6,borderRadius:"50%",backgroundColor:"border.main",display:"flex",justifyContent:"center",alignItems:"center"},children:ae(s,{sx:{width:16,color:"text.secondary"},onClick:g,component:H})})]})}[o]})}function wn({open:t,onClose:n}){const o=R(He);return ae(It,{title:ae(e,{id:"Connect to your wallet"}),open:t,onClose:n,children:ae(s,{sx:{mx:20,pb:20,border:"1px solid transparent",borderTopColor:"border.main"},children:Object.values(ct).map((t=>re(s,{sx:{display:"flex",alignItems:"center",flexDirection:"column",mt:20,p:20,backgroundColor:"background.tag",borderRadius:12,cursor:"pointer","&:hover":{backgroundColor:"hover.default"}},onClick:()=>{!function(e,t,n){var o;const i=dt[e];if(!i)throw new Error(`Unknown wallet type: ${e}`);const[r]=i;null===(o=r.activate(t))||void 0===o||o.catch((e=>{4001!==e.code?n(e):r.connectEagerly?r.connectEagerly(t):r.activate(t)}))}(t.type,o,(e=>{console.error(e)}))},children:[ae(s,{component:t.icon,sx:{width:32,height:32}}),ae(s,{sx:{mt:8,typography:"caption"},children:t.name}),ae(s,{sx:{mt:4,typography:"body2",color:"text.secondary"},children:ae(e,{id:"Connect to your {0} Wallet",values:{0:t.name}})})]},t.type)))})})}function Cn(){const{connector:t}=z(),[n,o]=E(!1);return re(se,{children:[ae(p,{size:p.Size.big,fullWidth:!0,onClick:()=>{t.deactivate?t.deactivate():t.resetState(),o(!0)},"data-testid":"connect-wallet-btn",children:ae(e,{id:"Connect to a wallet"})}),ae(wn,{open:n,onClose:()=>o(!1)})]})}var An;!function(e){e.Loading="Loading",e.Insufficient="ApprovalInsufficient",e.Approving="Approving",e.Sufficient="Sufficient",e.Unchecked="Unchecked"}(An||(An={}));const On=({account:e,chainId:t,offset:o,contractAddress:i})=>{var r;const a=R(He),s=w((()=>{var e;return Ke[null!==(e=t)&&void 0!==e?e:a]}),[t]),{isETH:l}=w((()=>we(t)),[t]),{DODO_APPROVE:c}=s||{},d=null!==(r=null!=i?i:c)&&void 0!==r?r:null,u=function(e){const{account:t}=z(),o=R(He),i=R(ft),r=w((()=>Te[o]),[o]),a=C((o=>{var a;if(!t||!e)return null;if(o.symbol===r.symbol&&Ee(o.address,r.address))return new n(Kt);const s=null===(a=null==i?void 0:i[o.address.toLowerCase()])||void 0===a?void 0:a.tokenAllowances;return null!=s?s:null}),[t,e,r.symbol,r.address,i]);return a}(d),p=xt(),{runningRequests:m}=qt(),h=R(vt),f=w((()=>{var e;return null===(e=Te[null!=t?t:a])||void 0===e?void 0:e.address}),[t]),g=C(((t,i,r)=>{if(!t)return An.Loading;const a=!!(null==m?void 0:m.find((e=>e.spec.opcode===Vt.Approval&&e.spec.token.address===(null==t?void 0:t.address)))),s=null!=r?r:t?p(t):null,l=t?u(t):null,c=new n(null!=i?i:0);if(!e)return An.Unchecked;if(!s||c.minus(null!=o?o:0).gt(s))return An.Unchecked;if(c.isZero())return An.Unchecked;return t.address===f?An.Sufficient:a?An.Approving:l&&c.minus(null!=o?o:0).gt(l)?An.Insufficient:An.Sufficient}),[p,u,e,o,d,t,h,m,f]),b=C((e=>{const t=e?u(e):null;return("USDT"===(null==e?void 0:e.symbol)||(null==e?void 0:e.address.toLowerCase())==="0x6426e6017968377529487E0ef0aA4E7759724e05".toLowerCase())&&null!==t&&t.gt(0)}),[u]),y=Zt(),v=I(),x=C(((t,o)=>Se(void 0,void 0,void 0,(function*(){if(!d||!e||!t)return;const i=(e=>{let t=e.symbol;return t.indexOf("DLP_")>-1&&(t=t.replace("DLP_","")),t.indexOf("DLP")>-1&&(t=t.replace("DLP","LP")),t})(t),r=o?new n(0):void 0,a=o?le._("Reset"):le._("Approve");var s;(yield y.execute(`${a} ${i}`,{opcode:Vt.Approval,token:t,contract:d,amt:r}))===jt.Success&&v((s=null!=r?r:Kt,e=>Se(void 0,void 0,void 0,(function*(){e({type:"SET_ACCOUNT_ALLOWANCES",payload:s})}))))}))),[d,e,t,y,v]),E=C((e=>{const t=new n(0);if(!e)return t.toNumber();const o=p(e);if(!o)return t.toNumber();let i=o;const r=l?.1:.02;return f===(null==e?void 0:e.address)&&(i=o.gt(r)?o.minus(r):t),i.toNumber()}),[t,p,l]);return{getApprovalState:g,getPendingRest:b,getMaxBalance:E,submitApprove:x}};function Tn(){var t,o;const i=l(),{isInflight:r}=qt(),{chainId:d,account:u}=z(),m=I(),{isReverseRouting:h}=R(Rt),f=R(He),g=R(yt),b=R(bt),{isETH:v}=w((()=>we(d)),[d]),x=w((()=>{var e;return null===(e=Te[null!=d?d:f])||void 0===e?void 0:e.address}),[d]),[O,T]=E(""),[k,S]=E(""),[L,D]=E(""),[N,_]=E(""),B=w((()=>a((e=>D(e)),1e3)),[]),P=w((()=>a((e=>_(e)),1e3)),[]),[j,M]=E(null),[H,V]=E(null),[K,G]=E(!1),[Y,q]=E(!1),{toFiatPrice:X,fromFiatPrice:Z}=cn({chainId:d,toToken:H,fromToken:j}),Q=xt(),J=w((()=>j?Q(j):null),[j,Q]);w((()=>H?Q(H):null),[H,Q]);const{getApprovalState:ee,submitApprove:te,getPendingRest:ne,getMaxBalance:oe}=On({account:u,chainId:d}),ie=w((()=>ne(h?H:j)),[null==j?void 0:j.address,null==H?void 0:H.address,ne,h]),{marginAmount:le}=an({token:h?H:j,fiatPrice:h?X:Z}),{resAmount:ce,priceImpact:de,executeSwap:ue,baseFeeAmount:pe,additionalFeeAmount:me,resPricePerToToken:he,resPricePerFromToken:fe,status:ye}=mn({toToken:H,fromToken:j,marginAmount:le,fromAmount:L,toAmount:N}),ve=C((e=>{const t=e.toString();T(t),B(t)}),[T,B]),xe=C((e=>{const t=e.toString();S(t),P(t)}),[S,P]);A((()=>{d&&(V(null),M(null),h?xe(""):ve("")),b&&b.chainId===d&&(M(b),b.amount&&(m(Gt({isReverseRouting:!1})),ve(b.amount))),g&&g.chainId===d&&(V(g),g.amount&&b&&!b.amount&&(m(Gt({isReverseRouting:!0})),xe(g.amount)))}),[g,b,d,ve,xe]);const Ee=C((()=>{ve(""),xe(""),M(H),V(j)}),[M,H,V,j,ve,xe]),Ae=C((e=>h?xe(oe(H)):ve(oe(j))),[ve,xe,oe,j,H,h]),Oe=w((()=>(100*Number(de)).toFixed(2)),[de]),ke=w((()=>{const e=h?ce:L;return e&&Z?new n(Z).multipliedBy(e):null}),[Z,L,h,ce]),Ie=w((()=>{const e=h?N:ce;return e&&X?new n(X).multipliedBy(e):null}),[X,N,h,ce]),Re=w((()=>re(s,{sx:{display:"flex",fontWeight:600,typography:"body2",alignItems:"center",justifyContent:"center"},children:[ae(gn,{title:ae(e,{id:"Due to the market condition, market price and estimated price may have a slight difference"}),mr:8}),re(s,{sx:{display:"flex"},children:[ae(e,{id:"Current price impact"}),re(s,{sx:{color:i.palette.error.main,ml:4},children:[Oe,"%"]})]})]})),[Oe]),Se=w((()=>ae(En,{toToken:H,fromToken:j,priceStatus:ye,pricePerToToken:he,pricePerFromToken:fe})),[H,j,ye,he,fe]),Le=w((()=>!Ce[d||1]),[d]),De=w((()=>ye===pn.Loading?ae(s,{sx:{display:"flex",justifyContent:"center",alignItems:"center"},children:re(se,{children:[ae(y,{sx:{mr:5}}),ae(e,{id:"Fetching best price..."})]})}):Le?re(se,{children:[ae(s,{component:U,sx:{mr:6,width:16,color:"warning.main"}}),ae(e,{id:"Unsupported network - switch to trade"})]}):O&&new n(Oe).gt(15)?Re:Se),[ye,Se,O,Re,Oe,Le]),Ne=w((()=>h?new n(k).gt(0)?be({input:ce,decimals:null==j?void 0:j.decimals}):"-":O),[O,k,ce,j,h]),_e=w((()=>h?k:new n(O).gt(0)?be({input:ce,decimals:null==H?void 0:H.decimals}):"-"),[O,k,ce,H,h]),Be=w((()=>{const t=ee(j,h?ce||0:L),o=t===An.Approving,i=t===An.Insufficient&&!ie,a=v?.1:.02,s=x===(null==j?void 0:j.address),l=new n(J||0);return u?r?ae(p,{fullWidth:!0,isLoading:!0,disabled:!0,children:ae(e,{id:"Transaction Pending"})}):j&&H?i?ae(p,{fullWidth:!0,disabled:o,onClick:()=>te(j),children:ae(e,o?{id:"Approving"}:{id:"Approve"})}):new n(h?N:L).gt(0)?ye===pn.Loading?ae(p,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-fetch-price-btn",children:ae(e,{id:"Fetching Price..."})}):ce?l.lt(h?ce:L)||s&&l.lte(a)?ae(p,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-insufficient-balance-btn",children:ae(e,{id:"Insufficient balance"})}):ae(p,{fullWidth:!0,onClick:()=>G(!0),"data-testid":"swap-review-btn",children:ae(e,{id:"Review Swap"})}):ae(p,{fullWidth:!0,disabled:!0,children:ae(e,{id:"Quote not available"})}):ae(p,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-enter-amount-btn",children:ae(e,{id:"Enter an amount"})}):ae(p,{fullWidth:!0,disabled:!0,"data-testid":"swap-alert-select-token-btn",children:ae(e,{id:"Select Tokens"})}):ae(Cn,{})}),[v,u,N,L,H,ce,j,r,ue,ie,te,ye,J,ee,x,h]),Pe=w((()=>j&&H?re(s,{sx:{display:"flex",alignItems:"center"},children:[ae(At,{token:j,sx:{width:16,height:16,mr:6}}),`${be({input:h?ce:L,decimals:null==j?void 0:j.decimals})} ${j.symbol}`,ae(s,{component:F,sx:{width:12,height:12,mx:16}}),ae(At,{token:H,sx:{width:16,height:16,mr:6}}),`${be({input:h?N:ce,decimals:null==H?void 0:H.decimals})} ${H.symbol}`]}):ae(s,{})),[j,H,L,N,ce,h]);return re(se,{children:[re(s,{sx:{display:"flex",justifyContent:"space-between",typography:"caption",margin:20},children:[ae(e,{id:"Swap"}),ae(s,{component:c,children:ae(s,{component:W,onClick:()=>q(!0),sx:{width:19,height:19,color:"text.primary",cursor:"pointer"}})})]}),re(s,{sx:{flex:1,padding:"0 20px 20px",overflowY:"auto"},children:[re(s,{children:[ae(_t,{sx:{mb:4},token:j,amt:Ne,onMaxClick:Ae,onInputChange:ve,onInputFocus:()=>{h&&ve(""),m(Gt({isReverseRouting:!1}))},showMaxBtn:!h&&!O,occupiedAddrs:[null!==(t=null==H?void 0:H.address)&&void 0!==t?t:""],fiatPriceTxt:ke?`$${ge({input:ke,showDecimals:1})}`:"-",onTokenChange:(e,t)=>{if(t)return Ee();ve(""),xe(""),M(e)},readOnly:h}),ae(bn,{onClick:Ee}),ae(_t,{token:H,amt:_e,onInputChange:xe,onInputFocus:()=>{h||xe(""),m(Gt({isReverseRouting:!0}))},occupiedAddrs:[null!==(o=null==j?void 0:j.address)&&void 0!==o?o:""],fiatPriceTxt:Ie?`$${ge({input:Ie,showDecimals:1})}(${Oe}%)`:"-",onTokenChange:(e,t)=>{if(t)return Ee();ve(""),xe(""),V(e)},readOnly:!h}),ae(s,{sx:{py:12,display:"flex",typography:"body2",alignItems:"center",justifyContent:"center",flexWrap:"wrap"},children:De})]}),Be,re(s,{sx:{mt:13,display:"flex",typography:"h6",cursor:"pointer",justifyContent:"center",alignItems:"center",color:i.palette.text.disabled},onClick:()=>window.open("https://app.dodoex.io"),children:[ae(s,{sx:{width:24,typography:"body2",transform:"translate(1px, 2px)","& path":{fill:i.palette.text.disabled}},component:$}),ae(e,{id:"Powered by DODO protocol"})]})]}),ae(yn,{toToken:H,fromToken:j,fromAmount:h?ce:L,toAmount:h?N:ce,open:K,baseFeeAmount:pe,priceImpact:Oe,additionalFeeAmount:me,curToFiatPrice:Ie,execute:()=>ue(Pe),clearFromAmt:()=>ve(""),clearToAmt:()=>xe(""),curFromFiatPrice:ke,pricePerFromToken:fe,onClose:()=>G(!1)}),ae(xn,{open:Y,onClose:()=>q(!1)})]})}function kn(e){return ae(fn,{...e,children:ae(Tn,{})})}function In(e){const t=document.getElementById("dodo-swap-widget");fe(t).render(ae(fn,{...e,children:ae(Tn,{})}))}export{In as InitSwapWidget,kn as SwapWidget};
|