From e6c60044bcb1e5cf622bd7d76018e4a0b54c86cc Mon Sep 17 00:00:00 2001 From: yarkin Date: Mon, 4 Sep 2023 23:10:58 +0800 Subject: [PATCH 1/8] Preliminary implementation. --- src/assets/usdt.png | Bin 0 -> 1017 bytes src/erc20.json | 527 ++++++++++++++++++++++++++++++++++++++++++++ src/views/Home.vue | 139 ++++++++++-- 3 files changed, 643 insertions(+), 23 deletions(-) create mode 100644 src/assets/usdt.png create mode 100644 src/erc20.json diff --git a/src/assets/usdt.png b/src/assets/usdt.png new file mode 100644 index 0000000000000000000000000000000000000000..420b05cdd8961f51926fbbfb7021eb48c116d070 GIT binary patch literal 1017 zcmeAS@N?(olHy`uVBq!ia0vp^`9K`S!3-oD*ZlASQY`6?zK#qG8~eHcB(ehejKx9j zP7LeL$-D$|asqrpT!A#h{P_(1{R~s4Fif8gVoaS1A}38^m^>LIIB_C^0T%=^fXaXh zAZn1sA%bucA_XQ*uZzk7ty3-u@(X4V5Rg|;Ffg!p@b?dhk59-iD5$S*=QVp4msHOf=j(Gq=#xjdy3M`SKn2!cLtyA)}=pp7`a5&9W~ZnxEsUxy*>?`pUND_O_ZCiC)WdeZeRA!d5q1QtkV^y5)Qy!g9A9Q{Ll#>Oy&k>*|N+FITro zZ7n|~P{v_fvi;NHpyD-qOoDW;Ou4yZc6XMSo95TzyV<7}7u@qLO}2ac^o`o;-b=5G zKlI&F^m})ydgkQFQ1eB(VfC6z1WH5a%!_{U!b|euj$Oxpr(fLCTz2KK4d0_#xnFZ! zWMc09{j@4f@O8e_kGog;dVW6r(pC0tb@|b`aqq28_!}+Q?{lZ_lq&m)weCB)UZ=Od z?Kv%ZfU)S>Y_)>W+WJJzRmZ;kpR(=s<(<}zmJata=TGbD)>?bs-@a>RZ{Hsq^OkEB z_KD?*-~L=#eJ_!%KCI!hE6-wYsi&(>rbWvzNOP>udlPd{>Z0e*zgj9wMIL=KGw*rq zyT9yM{jpqw&w2Bgub+7+(jnwd_nKQbcZAMr>sh;bNJ#i6w8`p)^gI^J~N zy?=g>jpL1SrK+Ya39g@6)_RH*%lHTEo+PYN&AXRZtZM)9+FyC=zE|DJUvtB8()KC) ziqCKb?fI=F#;#JKI7jr(w-P?b#CyWeuO7c+sFr?L*xW6}K%C{>!<_0QqjS5qsXqR5 zVB*1l0>_I=0**dhk-&e^N#=Cm0lo(w0S-@A^gq3mz;upP?ctm3Xr*&(W)pOLs+HPX zKJH6ad3w*`|K5CYiESOM&F%%-28Rs3Gxk4Xi0JQlWx&U9!~KEIfBxLG^?GxU>%@Vw Nsi&)-%Q~loCIAMh+!_D? literal 0 HcmV?d00001 diff --git a/src/erc20.json b/src/erc20.json new file mode 100644 index 0000000..d84b9c2 --- /dev/null +++ b/src/erc20.json @@ -0,0 +1,527 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "previousAdmin", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "newAdmin", + "type": "address" + } + ], + "name": "AdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "beacon", + "type": "address" + } + ], + "name": "BeaconUpgraded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "string", + "name": "memo", + "type": "string" + } + ], + "name": "bridgeTransfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "egressFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "eosTokenContract", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "evmAddress", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "addedValue", + "type": "uint256" + } + ], + "name": "increaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "_precision", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "_egressFee", + "type": "uint256" + }, + { + "internalType": "string", + "name": "_name", + "type": "string" + }, + { + "internalType": "string", + "name": "_symbol", + "type": "string" + }, + { + "internalType": "string", + "name": "_eos_token_contract", + "type": "string" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "linkedEOSAccountName", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "linkedEOSAddress", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "precision", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "proxiableUUID", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_egressFee", + "type": "uint256" + } + ], + "name": "setFee", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + } + ], + "name": "upgradeTo", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "upgradeToAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + } +] \ No newline at end of file diff --git a/src/views/Home.vue b/src/views/Home.vue index f0ad8b7..e1029f8 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -38,7 +38,30 @@
{{ $t('home.insufficient') }}
- EOS +
+ + + + LOGO-EOSEOS + + + LOGO-USDTUSDT + + +
@@ -106,14 +129,18 @@
{{ transactionHash.slice(0, 6) + '...' + transactionHash.slice(-4) }}
- {{ $t('home.copyEvmTx') }}   {{ $t('home.viewEvmTx') }} + {{ $t('home.copyEvmTx') }}   {{ + $t('home.viewEvmTx') }}
{{ $t('home.eosTx') }}
{{ eosHash.slice(0, 4) + '...' + eosHash.slice(-4) }}
- {{ $t('home.copyEosTx') }}   {{ $t('home.viewEosTx') }} -
+ {{ $t('home.copyEosTx') }}   {{ $t('home.viewEosTx') + }} + {{ $t('home.eosTxError') }} {{ $t('home.eosTxPending') }} @@ -201,6 +228,7 @@ import Web3 from 'web3' import BN from 'bn.js' import clipboardCopy from '../utils/copy-text' +import erc20_abi from '../erc20.json' import { Api, JsonRpc, RpcError } from 'enf-eosjs'; @@ -229,7 +257,10 @@ export default { submitting: false, finished: false, transactionError: '', - extraWarning: '' + extraWarning: '', + tokenName: 'EOS', + erc20_addr: '', + erc20_contract: null, } }, created() { @@ -327,6 +358,12 @@ export default { let targetApiAddr = (this.env === "TESTNET" ? "https://api.testnet.evm.eosnetwork.com/" : "https://api.evm.eosnetwork.com/"); let targetExplorerAddr = (this.env === "TESTNET" ? "https://explorer.testnet.evm.eosnetwork.com" : "https://explorer.evm.eosnetwork.com"); let targetNetworkName = (this.env === "TESTNET" ? "EOS-EVM Testnet2" : "EOS-EVM"); + this.erc20_addr = (this.env === "TESTNET" ? "0x586898a6F226b42aC0b7d6c9Dd234813bB75b646" : ""); + this.erc20_contract = null; + if (this.erc20_addr != "") { + this.erc20_contract = new this.web3.eth.Contract(erc20_abi, this.erc20_addr); + } + console.log(chainId) if (chainId != targetChainid) { try { @@ -392,14 +429,31 @@ export default { const address = this.address this.wallet.connecting = true this.wallet.connected = false - const wei = await this.web3.eth.getBalance(address) - this.balance = this.web3.utils.fromWei(wei, 'ether') + if (this.tokenName === 'EOS') { + const wei = await this.web3.eth.getBalance(address) + this.balance = this.web3.utils.fromWei(wei, 'ether') + } + else if (this.tokenName === 'USDT') { + const wei = await this.erc20_contract.methods.balanceOf(address).call() + this.balance = this.web3.utils.fromWei(wei, 'mwei') + } + this.wallet.connected = true } finally { this.wallet.connecting = false } }, + onSelectToken(token) { + if (token === "EOS" || token === "USDT") { + if (token == "USDT" && this.erc20_contract == null ) { + return; + } + this.tokenName = token + this.getBalance() + } + }, + stringToUTF8Bytes(string) { return new TextEncoder().encode(string); }, @@ -421,30 +475,54 @@ export default { return targetExplorerAddr + '/tx/' + tx }, - async transfer() { - try { - this.submitting = true - - if (!window.confirm(this.$t('home.transferConfirm', [this.amount, this.targetAddress]))) { - return - } - this.gas = await this.web3.eth.estimateGas({ + prepareTx(gaslimit) { + + if (this.tokenName === 'EOS') { + let tx = { from: this.address, to: this.addressEvm, value: this.transferValue, gasPrice: this.gasPrice, data: this.bytesToHex(this.stringToUTF8Bytes(this.memo)), - }); - var vm = this + } - // Send EVM Transaction - await this.web3.eth.sendTransaction({ + if (gaslimit != null) { + tx.gas = gaslimit; + } + return tx + } + else if (this.tokenName === 'USDT'){ + // USDT + let tx = { from: this.address, to: this.addressEvm, value: this.transferValue, - gas: this.gas, - data: this.bytesToHex(this.stringToUTF8Bytes(this.memo)), - }).on('receipt', async function (receipt) { + gasPrice: this.gasPrice, + data: this.erc20_contract.methods.bridgeTransfer(this.addressEvm, this.transferValue, this.memo).encodeABI(), + } + + if (gaslimit != null) { + tx.gas = gaslimit; + } + return tx + } + + return {} + + }, + + async transfer() { + try { + this.submitting = true + + if (!window.confirm(this.$t('home.transferConfirm', [this.amount, this.targetAddress]))) { + return + } + this.gas = await this.web3.eth.estimateGas(this.prepareTx(null)); + var vm = this + + // Send EVM Transaction + await this.web3.eth.sendTransaction(this.prepareTx(this.gas)).on('receipt', async function (receipt) { // Receipt contains tx hash. vm.transactionHash = receipt.transactionHash vm.eosHash = '' @@ -586,7 +664,7 @@ export default { } .connect-btn { - width: 142px; + width: 142px !important; margin-left: -12px; } @@ -644,4 +722,19 @@ export default { color: rgba(var(--bs-link-color-rgb), var(--bs-link-opacity, 1)); cursor: pointer; } + +.dropdown-toggle::after { + content: unset !important; +} + +.my_dropdown-toggle::after { + display: inline-block; + margin-left: 0.255em; + vertical-align: 0.255em; + content: ""; + border-top: 0.3em solid; + border-right: 0.3em solid transparent; + border-bottom: 0; + border-left: 0.3em solid transparent; +} From d8eef482431a6c7d874fac8c00a84d6fc7704c04 Mon Sep 17 00:00:00 2001 From: yarkin Date: Mon, 11 Sep 2023 14:20:50 +0800 Subject: [PATCH 2/8] Change some text. Change deposit address to eosio.evmin --- src/i18n.js | 6 +++--- src/views/Home.vue | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/i18n.js b/src/i18n.js index 1503fc2..ffc4af0 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -55,7 +55,7 @@ const messages = { 'home.swtichNetPrompt' : 'You must switch to the correct network to continue.', 'home.addNetPrompt' : 'Please add the EOS EVM Network to your wallet.', - 'home.transferConfirm' : 'You are going to transfer {0} EOS to {1}', + 'home.transferConfirm' : 'You are going to transfer {0} {1} to {2}', 'navbar.about': 'About', 'navbar.docs': 'Docs', @@ -117,7 +117,7 @@ const messages = { 'home.swtichNetPrompt' : '계속 진행하기 위해서는 올바른 네트워크로 전환해야 합니다.', 'home.addNetPrompt' : 'EOS EVM 네트워크 지갑에 추가하세요', - 'home.transferConfirm' : '귀하의 {0} EOS를 {1}로 전송하려고 합니다.', + 'home.transferConfirm' : '귀하의 {0} {1}를 {2}로 전송하려고 합니다.', 'navbar.about': '정보t', 'navbar.docs': '문서', @@ -179,7 +179,7 @@ const messages = { 'home.swtichNetPrompt' : '您必须切换到正确的网络才能继续操作。', 'home.addNetPrompt' :'请在您的钱包中添加 EOS EVM 网络。', - 'home.transferConfirm' : '您即将把 {0} EOS 转移至 {1}', + 'home.transferConfirm' : '您即将把 {0} {1} 转移至 {2}', 'navbar.about': '关于我们', 'navbar.docs': '文档', diff --git a/src/views/Home.vue b/src/views/Home.vue index e1029f8..a9346f7 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -180,8 +180,8 @@
- - + +
@@ -515,7 +515,7 @@ export default { try { this.submitting = true - if (!window.confirm(this.$t('home.transferConfirm', [this.amount, this.targetAddress]))) { + if (!window.confirm(this.$t('home.transferConfirm', [this.amount, this.tokenName, this.targetAddress]))) { return } this.gas = await this.web3.eth.estimateGas(this.prepareTx(null)); From 7ff9700f2e9828560f5678a7b486f9ecdb74e533 Mon Sep 17 00:00:00 2001 From: yarkin Date: Tue, 12 Sep 2023 16:30:37 +0800 Subject: [PATCH 3/8] Read egress fee from contract and set it properly when preparing tx. Fix other bugs. --- src/views/Home.vue | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/views/Home.vue b/src/views/Home.vue index a9346f7..f954de3 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -475,7 +475,7 @@ export default { return targetExplorerAddr + '/tx/' + tx }, - prepareTx(gaslimit) { + async prepareTx(gaslimit) { if (this.tokenName === 'EOS') { let tx = { @@ -493,10 +493,11 @@ export default { } else if (this.tokenName === 'USDT'){ // USDT + const fee = await this.erc20_contract.methods.egressFee().call() let tx = { from: this.address, - to: this.addressEvm, - value: this.transferValue, + to: this.erc20_addr, + value: fee, gasPrice: this.gasPrice, data: this.erc20_contract.methods.bridgeTransfer(this.addressEvm, this.transferValue, this.memo).encodeABI(), } @@ -518,11 +519,11 @@ export default { if (!window.confirm(this.$t('home.transferConfirm', [this.amount, this.tokenName, this.targetAddress]))) { return } - this.gas = await this.web3.eth.estimateGas(this.prepareTx(null)); + this.gas = await this.web3.eth.estimateGas(await this.prepareTx(null)); var vm = this // Send EVM Transaction - await this.web3.eth.sendTransaction(this.prepareTx(this.gas)).on('receipt', async function (receipt) { + await this.web3.eth.sendTransaction(await this.prepareTx(this.gas)).on('receipt', async function (receipt) { // Receipt contains tx hash. vm.transactionHash = receipt.transactionHash vm.eosHash = '' From dfe2a5b62adba2c1720c83c7a1eac93554cc6fce Mon Sep 17 00:00:00 2001 From: yarkin Date: Wed, 13 Sep 2023 07:57:34 +0800 Subject: [PATCH 4/8] Add text for usdt support. --- src/i18n.js | 1 + src/views/Home.vue | 1 + 2 files changed, 2 insertions(+) diff --git a/src/i18n.js b/src/i18n.js index ffc4af0..60e1585 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -46,6 +46,7 @@ const messages = { 'home.netWarning.desc': 'Please confirm that your wallet is connected to the correct network before making a transfer. Using the wrong network may result in loss of tokens.', 'home.eos2evmDesc.p1': 'Please use a wallet that supports the EOS Network, such as Anchor, Wombat, TokenPocket or a centralized exchange such as Binance, Coinbase, etc.', 'home.eos2evmDesc.p2': 'To transfer funds to the following EOS Contract Address, please fill in the Destination EOS EVM Address in the memo to complete the deposit to EOS EVM.', + 'home.eos2evmDesc.p3': 'Officially supported tokens include EOS and USDT (EOS) at this time.', 'home.addressCheck.invalidAddress': 'Address includes an illegal character', 'home.addressCheck.invalid13Char': 'Invalid 13th character', diff --git a/src/views/Home.vue b/src/views/Home.vue index f954de3..8317633 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -162,6 +162,7 @@

{{ $t('home.eos2evmDesc.p1') }}

{{ $t('home.eos2evmDesc.p2') }}

+

{{ $t('home.eos2evmDesc.p3') }}

From 3b526ae90c537523aa9fc8f6c71f2e512be5484e Mon Sep 17 00:00:00 2001 From: yarkin Date: Thu, 14 Sep 2023 14:55:31 +0800 Subject: [PATCH 5/8] Fix estimate gas display. --- src/views/Home.vue | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/views/Home.vue b/src/views/Home.vue index 8317633..df9279c 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -343,13 +343,7 @@ export default { return } this.gasPrice = await this.web3.eth.getGasPrice() - this.gas = await this.web3.eth.estimateGas({ - from: this.address, - to: this.addressEvm, - value: this.transferValue, - gasPrice: this.gasPrice, - data: this.bytesToHex(this.stringToUTF8Bytes(this.memo)), - }) + this.gas = await this.web3.eth.estimateGas(await this.prepareTx(null)); }, async checkChainID() { From a703d1b6747c26ad656eecd335808f9866241b3b Mon Sep 17 00:00:00 2001 From: yarkin Date: Fri, 15 Sep 2023 16:45:22 +0800 Subject: [PATCH 6/8] Make thing work with the newly deployed contract on testnet. --- src/assets/jungle.svg | 112 ++++++++++++++++++++++++++++++++++++++++++ src/views/Home.vue | 107 ++++++++++++++++++++++++++-------------- 2 files changed, 182 insertions(+), 37 deletions(-) create mode 100644 src/assets/jungle.svg diff --git a/src/assets/jungle.svg b/src/assets/jungle.svg new file mode 100644 index 0000000..08acabb --- /dev/null +++ b/src/assets/jungle.svg @@ -0,0 +1,112 @@ + + + diff --git a/src/views/Home.vue b/src/views/Home.vue index df9279c..5a51256 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -38,29 +38,51 @@
{{ $t('home.insufficient') }}
-
+
- - - LOGO-EOSEOS - - - LOGO-USDTUSDT - - + + +
@@ -320,7 +342,12 @@ export default { return null } try { - return this.web3.utils.toBN(this.web3.utils.toWei(this.amount.toString(), 'ether')) + if (this.tokenName == "EOS") { + return this.web3.utils.toBN(this.web3.utils.toWei(this.amount.toString(), 'ether')) + } + else { + return this.web3.utils.toBN(this.web3.utils.toWei(this.amount.toString(), 'mwei')) + } } catch (err) { return null } @@ -344,6 +371,9 @@ export default { } this.gasPrice = await this.web3.eth.getGasPrice() this.gas = await this.web3.eth.estimateGas(await this.prepareTx(null)); + if (this.tokenName != "EOS") { + this.gas = new BN(this.gas).mul(new BN(2)).toString() + } }, async checkChainID() { @@ -353,12 +383,12 @@ export default { let targetApiAddr = (this.env === "TESTNET" ? "https://api.testnet.evm.eosnetwork.com/" : "https://api.evm.eosnetwork.com/"); let targetExplorerAddr = (this.env === "TESTNET" ? "https://explorer.testnet.evm.eosnetwork.com" : "https://explorer.evm.eosnetwork.com"); let targetNetworkName = (this.env === "TESTNET" ? "EOS-EVM Testnet2" : "EOS-EVM"); - this.erc20_addr = (this.env === "TESTNET" ? "0x586898a6F226b42aC0b7d6c9Dd234813bB75b646" : ""); + this.erc20_addr = (this.env === "TESTNET" ? "0x4ea3b729669bF6C34F7B80E5D6c17DB71F89F21F" : ""); this.erc20_contract = null; if (this.erc20_addr != "") { this.erc20_contract = new this.web3.eth.Contract(erc20_abi, this.erc20_addr); } - + console.log(chainId) if (chainId != targetChainid) { try { @@ -441,12 +471,12 @@ export default { onSelectToken(token) { if (token === "EOS" || token === "USDT") { - if (token == "USDT" && this.erc20_contract == null ) { + if (token == "USDT" && this.erc20_contract == null) { return; } this.tokenName = token this.getBalance() - } + } }, stringToUTF8Bytes(string) { @@ -471,7 +501,7 @@ export default { }, async prepareTx(gaslimit) { - + if (this.tokenName === 'EOS') { let tx = { from: this.address, @@ -485,8 +515,8 @@ export default { tx.gas = gaslimit; } return tx - } - else if (this.tokenName === 'USDT'){ + } + else if (this.tokenName === 'USDT') { // USDT const fee = await this.erc20_contract.methods.egressFee().call() let tx = { @@ -504,7 +534,7 @@ export default { } return {} - + }, async transfer() { @@ -515,6 +545,10 @@ export default { return } this.gas = await this.web3.eth.estimateGas(await this.prepareTx(null)); + if (this.tokenName != "EOS") { + this.gas = new BN(this.gas).mul(new BN(2)).toString() + } + var vm = this // Send EVM Transaction @@ -724,13 +758,12 @@ export default { } .my_dropdown-toggle::after { - display: inline-block; - margin-left: 0.255em; - vertical-align: 0.255em; - content: ""; - border-top: 0.3em solid; - border-right: 0.3em solid transparent; - border-bottom: 0; - border-left: 0.3em solid transparent; -} - + display: inline-block; + margin-left: 0.255em; + vertical-align: 0.255em; + content: ""; + border-top: 0.3em solid; + border-right: 0.3em solid transparent; + border-bottom: 0; + border-left: 0.3em solid transparent; +} From 8bdd3e2968963e2a122074277cccc1f624a0d082 Mon Sep 17 00:00:00 2001 From: yarkin Date: Tue, 19 Sep 2023 07:53:16 +0800 Subject: [PATCH 7/8] refactor --- {src/assets => public/images}/eos.png | Bin {src/assets => public/images}/jungle.svg | 2 +- {src/assets => public/images}/usdt.png | Bin src/views/Home.vue | 120 ++++++++++------------- 4 files changed, 55 insertions(+), 67 deletions(-) rename {src/assets => public/images}/eos.png (100%) rename {src/assets => public/images}/jungle.svg (99%) rename {src/assets => public/images}/usdt.png (100%) diff --git a/src/assets/eos.png b/public/images/eos.png similarity index 100% rename from src/assets/eos.png rename to public/images/eos.png diff --git a/src/assets/jungle.svg b/public/images/jungle.svg similarity index 99% rename from src/assets/jungle.svg rename to public/images/jungle.svg index 08acabb..91d0967 100644 --- a/src/assets/jungle.svg +++ b/public/images/jungle.svg @@ -3,7 +3,7 @@
-
- LOGO-EOSEOS -
-
- -
- LOGO-JUNGLEJUNGLE -
-
- LOGO-USDTUSDT -
-
-
- Error! -
+ + {{ tokenList[selectedToken].name }}
- - LOGO-EOSEOS - - -
- LOGO-JUNGLEJUNGLE -
-
- LOGO-USDTUSDT -
- + + + {{ item.name }} @@ -281,16 +251,33 @@ export default { finished: false, transactionError: '', extraWarning: '', - tokenName: 'EOS', - erc20_addr: '', - erc20_contract: null, + tokenList: null, + selectedToken: 0, + tokenListTestnet: [ + { name: 'EOS', addr: '', logo: 'images/eos.png' }, + { name: 'JUNGLE', addr: '0x4ea3b729669bF6C34F7B80E5D6c17DB71F89F21F', logo: 'images/jungle.svg', erc20_contract: null }, + ], + tokenListMainnet: [ + { name: 'EOS', addr: '', logo: 'images/eos.png' }, + { name: 'USDT', addr: '', logo: 'images/usdt.png' }, + ], } }, created() { + + this.wallet.connect = this.connectWallet this.web3 = new Web3(Web3.givenProvider || new Web3.providers.HttpProvider('http://localhost:8545')) + this.tokenList = this.env === "TESTNET" ? this.tokenListTestnet : this.tokenListMainnet; + this.selectedToken = 0; + for (var item of this.tokenList) { + if (item.addr != '') { + item.erc20_contract = new this.web3.eth.Contract(erc20_abi, item.addr); + } + } + this.web3.eth.getAccounts().then(async results => { if (results && results.length) { @@ -316,6 +303,7 @@ export default { } }, computed: { + disableTransfer() { return !this.addressEvm || this.addressEvm instanceof Error || this.submitting || this.finished || this.exceeded || !this.transferValue }, @@ -342,7 +330,7 @@ export default { return null } try { - if (this.tokenName == "EOS") { + if (this.tokenName() == "EOS") { return this.web3.utils.toBN(this.web3.utils.toWei(this.amount.toString(), 'ether')) } else { @@ -364,6 +352,9 @@ export default { }, methods: { + erc20_contract() { return this.tokenList[this.selectedToken].erc20_contract; }, + erc20_addr() { return this.tokenList[this.selectedToken].addr; }, + tokenName() { return this.tokenList[this.selectedToken].name; }, async calcFee() { if (this.disableTransfer) { @@ -371,7 +362,7 @@ export default { } this.gasPrice = await this.web3.eth.getGasPrice() this.gas = await this.web3.eth.estimateGas(await this.prepareTx(null)); - if (this.tokenName != "EOS") { + if (this.tokenName() != "EOS") { this.gas = new BN(this.gas).mul(new BN(2)).toString() } }, @@ -383,11 +374,8 @@ export default { let targetApiAddr = (this.env === "TESTNET" ? "https://api.testnet.evm.eosnetwork.com/" : "https://api.evm.eosnetwork.com/"); let targetExplorerAddr = (this.env === "TESTNET" ? "https://explorer.testnet.evm.eosnetwork.com" : "https://explorer.evm.eosnetwork.com"); let targetNetworkName = (this.env === "TESTNET" ? "EOS-EVM Testnet2" : "EOS-EVM"); - this.erc20_addr = (this.env === "TESTNET" ? "0x4ea3b729669bF6C34F7B80E5D6c17DB71F89F21F" : ""); - this.erc20_contract = null; - if (this.erc20_addr != "") { - this.erc20_contract = new this.web3.eth.Contract(erc20_abi, this.erc20_addr); - } + + console.log(chainId) if (chainId != targetChainid) { @@ -454,13 +442,17 @@ export default { const address = this.address this.wallet.connecting = true this.wallet.connected = false - if (this.tokenName === 'EOS') { + if (this.tokenName() === 'EOS') { const wei = await this.web3.eth.getBalance(address) this.balance = this.web3.utils.fromWei(wei, 'ether') } - else if (this.tokenName === 'USDT') { - const wei = await this.erc20_contract.methods.balanceOf(address).call() - this.balance = this.web3.utils.fromWei(wei, 'mwei') + else { + if ((this.erc20_contract())) { + const wei = await this.erc20_contract().methods.balanceOf(address).call() + this.balance = this.web3.utils.fromWei(wei, 'mwei') + } + else { this.balance = null; } + } this.wallet.connected = true @@ -469,14 +461,9 @@ export default { } }, - onSelectToken(token) { - if (token === "EOS" || token === "USDT") { - if (token == "USDT" && this.erc20_contract == null) { - return; - } - this.tokenName = token - this.getBalance() - } + onSelectToken(index) { + this.selectedToken = index; + this.getBalance() }, stringToUTF8Bytes(string) { @@ -502,7 +489,7 @@ export default { async prepareTx(gaslimit) { - if (this.tokenName === 'EOS') { + if (this.tokenName() === 'EOS') { let tx = { from: this.address, to: this.addressEvm, @@ -516,15 +503,15 @@ export default { } return tx } - else if (this.tokenName === 'USDT') { + else { // USDT - const fee = await this.erc20_contract.methods.egressFee().call() + const fee = await this.erc20_contract().methods.egressFee().call() let tx = { from: this.address, - to: this.erc20_addr, + to: this.erc20_addr(), value: fee, gasPrice: this.gasPrice, - data: this.erc20_contract.methods.bridgeTransfer(this.addressEvm, this.transferValue, this.memo).encodeABI(), + data: this.erc20_contract().methods.bridgeTransfer(this.addressEvm, this.transferValue, this.memo).encodeABI(), } if (gaslimit != null) { @@ -541,11 +528,11 @@ export default { try { this.submitting = true - if (!window.confirm(this.$t('home.transferConfirm', [this.amount, this.tokenName, this.targetAddress]))) { + if (!window.confirm(this.$t('home.transferConfirm', [this.amount, this.tokenName(), this.targetAddress]))) { return } this.gas = await this.web3.eth.estimateGas(await this.prepareTx(null)); - if (this.tokenName != "EOS") { + if (this.tokenName() != "EOS") { this.gas = new BN(this.gas).mul(new BN(2)).toString() } @@ -766,4 +753,5 @@ export default { border-right: 0.3em solid transparent; border-bottom: 0; border-left: 0.3em solid transparent; -} +} + From a9dad97a84bac94b303f5fba4f4eef46b0015a37 Mon Sep 17 00:00:00 2001 From: yarkin Date: Tue, 19 Sep 2023 09:56:39 +0800 Subject: [PATCH 8/8] bump version in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index df5960a..aef5fd5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "evm-bridge-frontend", - "version": "0.8.0", + "version": "0.9.0", "private": true, "scripts": { "dev": "vite",