diff --git a/src/locales/en-us.json b/src/locales/en-us.json index f7bc43c..c46b01a 100644 --- a/src/locales/en-us.json +++ b/src/locales/en-us.json @@ -23,7 +23,10 @@ "Destination": "Destination", "darwinaPage": "https://darwinia.network/", "Claims": "Claimed", - "Not claimed": "Not claimed" + "Not claimed": "Not claimed", + "Extension": "Extension", + "Manual": "Manual", + "Please input the Darwinia address to be queried": "Please input the Darwinia address to be queried" }, "crosschain": { "title": "Cross-chain Transfer", diff --git a/src/locales/zh-cn.json b/src/locales/zh-cn.json index fca3e90..4b02d75 100644 --- a/src/locales/zh-cn.json +++ b/src/locales/zh-cn.json @@ -120,7 +120,10 @@ "The amount exceeds the account available balance": "输入数量超过账户可用余额", "The entered recipient account is incorrect": "输入的接收账号错误", "d2e crosschain gas tip 1": "· 请在「跨链历史交易」中发起以太坊网络的「领取交易」。", - "d2e crosschain gas tip 2": "· 每笔以太坊网络的「领取交易」预计消耗 600000 Gas。" + "d2e crosschain gas tip 2": "· 每笔以太坊网络的「领取交易」预计消耗 600000 Gas。", + "Extension": "从插件获取", + "Manual": "手动输入", + "Please input the Darwinia address to be queried": "输入需要查询的 Darwinia 账号" }, "crosschain_ethtron": { "claim": "跨链转账", diff --git a/src/page/CrossChain/index.js b/src/page/CrossChain/index.js index 4acfa4d..79b14b8 100644 --- a/src/page/CrossChain/index.js +++ b/src/page/CrossChain/index.js @@ -1,5 +1,5 @@ import React, { Component } from "react"; -import { Button, Form, Spinner, Dropdown, ButtonGroup, Modal } from 'react-bootstrap' +import { Button, Form, Spinner, Dropdown, ButtonGroup, Modal, Col } from 'react-bootstrap' import { withRouter } from 'react-router-dom'; import 'react-toastify/dist/ReactToastify.css'; @@ -113,6 +113,11 @@ class CrossChain extends Component { d2eModalData: { isShow: false, hash: '' + }, + crabAndDarwiniaHistory: { + isManual: false, + address: '', + isFetchingClaimParams: false } } this.querySubscribe = null @@ -258,6 +263,8 @@ class CrossChain extends Component { // this.querySubscribe = subscribe; if (Array.isArray(_account) && _account.length > 0) { initAccount = _account[0].address + } else if (Array.isArray(_account) && _account.length === 0) { + initAccount = '' } else { initAccount = _account } @@ -272,6 +279,7 @@ class CrossChain extends Component { crossChainFee: Web3.utils.toBN(0), } }, async () => { + if (this.state.account[_networkType]) { this.setState({ status: status @@ -315,6 +323,11 @@ class CrossChain extends Component { isReady: true } }) + } else { + if (status === 4) { + this.queryClaims() + return; + } } }) }, t); @@ -355,7 +368,6 @@ class CrossChain extends Component { }, t); break; case 'darwinia': - this.setState({ history: null, account: { @@ -378,6 +390,8 @@ class CrossChain extends Component { initAccount = this.state.account[_networkType] } else if (Array.isArray(_account) && _account.length > 0) { initAccount = _account[0].address + } else if (Array.isArray(_account) && _account.length === 0) { + initAccount = '' } else { initAccount = _account } @@ -388,7 +402,12 @@ class CrossChain extends Component { ...account, [_networkType]: initAccount, [`${_networkType}List`]: _account, - isReady: false + isReady: false, + }, + crabAndDarwiniaHistory: { + ...this.state.crabAndDarwiniaHistory, + isManual: !initAccount, + address: '' } }, async () => { if (this.state.account[_networkType]) { @@ -408,6 +427,11 @@ class CrossChain extends Component { isReady: true } }) + } else { + if (status === 4) { + this.queryClaims() + return; + } } }) }, t); @@ -601,6 +625,10 @@ class CrossChain extends Component { async queryClaims() { const { networkType, account } = this.state; let address = '' + this.setState({ + history: null + }) + switch (networkType) { case "eth": address = account[networkType] @@ -669,27 +697,35 @@ class CrossChain extends Component { break; case "darwinia": address = account[networkType] - await getDarwiniaToEthereumGenesisSwapInfo({ - query: { - address: '0x' + substrateAddressToPublicKey(address), - row: 200, - page: 0 - }, - method: "get" - }, (list, data) => { - this.setState({ - history: list, - historyMeta: { - best: data.best, - mmrRoot: data.MMRRoot - } - }) - }, () => { + try { + await getDarwiniaToEthereumGenesisSwapInfo({ + query: { + address: '0x' + substrateAddressToPublicKey(address), + row: 200, + page: 0 + }, + method: "get" + }, (list, data) => { + this.setState({ + history: list, + historyMeta: { + best: data.best, + mmrRoot: data.MMRRoot + } + }) + }, () => { + this.setState({ + history: [], + historyMeta: {} + }) + }); + } catch (error) { this.setState({ history: [], historyMeta: {} }) - }); + } + break; default: break; @@ -1298,7 +1334,7 @@ class CrossChain extends Component { step4 = () => { const { t } = this.props - const { networkType, account, history } = this.state + const { networkType, account, history, crabAndDarwiniaHistory } = this.state const middleScreen = isMiddleScreen() return ( @@ -1311,32 +1347,78 @@ class CrossChain extends Component { {networkType === 'crab' || networkType === 'darwinia' ? <>

{convertSS58Address(account[networkType])}

- - this.setCurrentAccount(networkType, value, async (account) => { - // const balances = await getTokenBalance('crab', account); - // this.setState({ - // ringBalance: Web3.utils.toBN(balances[0]), - // darwiniaAddress: convertSS58Address(account) - // }) - const params = new URLSearchParams() - const {hash} = this.props.location; - - if (account) { - params.append("address", account) - } else { - params.delete("address") + + {crabAndDarwiniaHistory.isManual ? + + this.setCurrentAccount(networkType, value, async (account) => { + const params = new URLSearchParams(); + const {hash} = this.props.location; + + if (account) { + params.append("address", account) + } else { + params.delete("address") + } + this.props.history.replace({hash: hash, search: params.toString()}) + + this.queryClaims() + })} type="text" placeholder={t('crosschain:Please input the Darwinia address to be queried')} /> + + : + + this.setCurrentAccount(networkType, value, async (account) => { + // const balances = await getTokenBalance('crab', account); + // this.setState({ + // ringBalance: Web3.utils.toBN(balances[0]), + // darwiniaAddress: convertSS58Address(account) + // }) + const params = new URLSearchParams(); + const {hash} = this.props.location; + + if (account) { + params.append("address", account) + } else { + params.delete("address") + } + this.props.history.replace({hash: hash, search: params.toString()}) + + this.queryClaims() + })}> + {account[`${networkType}List`]?.map((item, index) => { + return + }) } - this.props.history.replace({hash: hash, search: params.toString()}) + + } + + + + + + :

{account[networkType]}

} {networkType === 'eth' || networkType === 'tron' ? this.renderEthereumTronHistory(history) : null} {networkType === 'darwinia' ? this.renderDarwiniaToEthereumHistory(history) : null} @@ -1477,7 +1559,13 @@ class CrossChain extends Component { chain: 'eth' }, }, true, () => - item.signatures && !item.tx ? : null )} ) diff --git a/src/page/CrossChain/utils.js b/src/page/CrossChain/utils.js index d911bf5..f56eadc 100644 --- a/src/page/CrossChain/utils.js +++ b/src/page/CrossChain/utils.js @@ -196,16 +196,6 @@ async function connectSubstrate(accountsChangedCallback, t, networkType) { const allInjected = await web3Enable('wormhole.darwinia.network'); const allAccounts = await web3Accounts(); - if (!allInjected || allInjected.length === 0) { - formToast(t('common:Please install Polkadot Extension')); - return; - } - - if (!allAccounts || allAccounts.length === 0) { - formToast(t('common:Polkadot Extension has no account')); - return; - } - switch (networkType) { case 'crab': await connectNodeProvider('wss://crab.darwinia.network', 'crab'); @@ -219,6 +209,18 @@ async function connectSubstrate(accountsChangedCallback, t, networkType) { break; } + if (!allInjected || allInjected.length === 0) { + formToast(t('common:Please install Polkadot Extension')); + accountsChangedCallback && accountsChangedCallback(networkType, []); + return; + } + + if (!allAccounts || allAccounts.length === 0) { + formToast(t('common:Polkadot Extension has no account')); + accountsChangedCallback && accountsChangedCallback(networkType, []); + return; + } + accountsChangedCallback && accountsChangedCallback(networkType, allAccounts); } @@ -312,12 +314,16 @@ export function convertSS58Address(text, isShort = false) { if(!text) { return ''; } - let address = encodeAddress(text, config.S58_PREFIX) - const length = 8 - if(isShort) { - address = address.substr(0, length) + '...' +address.substr(address.length - length, length) + try { + let address = encodeAddress(text, config.S58_PREFIX) + const length = 8 + if(isShort) { + address = address.substr(0, length) + '...' +address.substr(address.length - length, length) + } + return address + } catch (error) { + return '' } - return address } export function isMiddleScreen() { @@ -780,7 +786,7 @@ export async function getMMRProof(blockNumber, mmrBlockNumber, blockHash) { const mmrProof = [ // eslint-disable-next-line no-undef - BigInt(blockNumber), BigInt(proof.mmrSize), hexToU8a('0x' + encodeProof), hexToU8a(blockHash) + blockNumber, proof.mmrSize, hexToU8a('0x' + encodeProof), hexToU8a(blockHash) ] const mmrProofConverted = convert(...mmrProof); @@ -809,72 +815,79 @@ function encodeMMRRootMessage(networkPrefix, methodID, mmrIndex, mmrRoot) { }) } -export async function ClaimTokenFromD2E({ networkPrefix, mmrIndex, mmrRoot, mmrSignatures, blockNumber, blockHeaderStr, blockHash, historyMeta} , callback, t ) { - connect('eth', async(_networkType, _account, subscribe) => { - - if(historyMeta.mmrRoot && historyMeta.best && historyMeta.best > blockNumber) { - - const blockHeader = encodeBlockHeader(blockHeaderStr); - const mmrProof = await getMMRProof(blockNumber, historyMeta.best, blockHash); - const eventsProof = await getMPTProof(blockHash); - - console.log('ClaimTokenFromD2E - darwiniaToEthereumVerifyProof', { - root: '0x' + historyMeta.mmrRoot, - MMRIndex: historyMeta.best, - blockNumber: blockNumber, - blockHeader: blockHeader.toHex(), - peaks: mmrProof.peaks, - siblings: mmrProof.siblings, - eventsProofStr: eventsProof.toHex() - }) +export async function ClaimTokenFromD2E({ networkPrefix, mmrIndex, mmrRoot, mmrSignatures, blockNumber, blockHeaderStr, blockHash, historyMeta} , callback, fetchingEndCallback, t ) { + try { + connect('eth', async(_networkType, _account, subscribe) => { + + if(historyMeta.mmrRoot && historyMeta.best && historyMeta.best > blockNumber) { + + const blockHeader = encodeBlockHeader(blockHeaderStr); + const mmrProof = await getMMRProof(blockNumber, historyMeta.best, blockHash); + const eventsProof = await getMPTProof(blockHash); + + console.log('ClaimTokenFromD2E - darwiniaToEthereumVerifyProof', { + root: '0x' + historyMeta.mmrRoot, + MMRIndex: historyMeta.best, + blockNumber: blockNumber, + blockHeader: blockHeader.toHex(), + peaks: mmrProof.peaks, + siblings: mmrProof.siblings, + eventsProofStr: eventsProof.toHex() + }) - darwiniaToEthereumVerifyProof(_account, { - root: '0x' + historyMeta.mmrRoot, - MMRIndex: historyMeta.best, - blockNumber: blockNumber, - blockHeader: blockHeader.toHex(), - peaks: mmrProof.peaks, - siblings: mmrProof.siblings, - eventsProofStr: eventsProof.toHex() - }, (result) => { - console.log('darwiniaToEthereumVerifyProof', result) - callback && callback(result); - }); - } else { - - const mmrRootMessage = encodeMMRRootMessage(networkPrefix, '0x479fbdf9', mmrIndex, mmrRoot); - const blockHeader = encodeBlockHeader(blockHeaderStr); - const mmrProof = await getMMRProof(blockNumber, mmrIndex, blockHash); - const eventsProof = await getMPTProof(blockHash); - - console.log('ClaimTokenFromD2E - darwiniaToEthereumAppendRootAndVerifyProof', { - message: mmrRootMessage.toHex(), - signatures: mmrSignatures.split(','), - root: mmrRoot, - MMRIndex: mmrIndex, - blockNumber: blockNumber, - blockHeader: blockHeader.toHex(), - peaks: mmrProof.peaks, - siblings: mmrProof.siblings, - eventsProofStr: eventsProof.toHex() - }) + darwiniaToEthereumVerifyProof(_account, { + root: '0x' + historyMeta.mmrRoot, + MMRIndex: historyMeta.best, + blockNumber: blockNumber, + blockHeader: blockHeader.toHex(), + peaks: mmrProof.peaks, + siblings: mmrProof.siblings, + eventsProofStr: eventsProof.toHex() + }, (result) => { + console.log('darwiniaToEthereumVerifyProof', result) + callback && callback(result); + }); + + fetchingEndCallback && fetchingEndCallback(); + } else { + + const mmrRootMessage = encodeMMRRootMessage(networkPrefix, '0x479fbdf9', mmrIndex, mmrRoot); + const blockHeader = encodeBlockHeader(blockHeaderStr); + const mmrProof = await getMMRProof(blockNumber, mmrIndex, blockHash); + const eventsProof = await getMPTProof(blockHash); + + console.log('ClaimTokenFromD2E - darwiniaToEthereumAppendRootAndVerifyProof', { + message: mmrRootMessage.toHex(), + signatures: mmrSignatures.split(','), + root: mmrRoot, + MMRIndex: mmrIndex, + blockNumber: blockNumber, + blockHeader: blockHeader.toHex(), + peaks: mmrProof.peaks, + siblings: mmrProof.siblings, + eventsProofStr: eventsProof.toHex() + }) - darwiniaToEthereumAppendRootAndVerifyProof(_account, { - message: mmrRootMessage.toHex(), - signatures: mmrSignatures.split(','), - root: mmrRoot, - MMRIndex: mmrIndex, - blockNumber: blockNumber, - blockHeader: blockHeader.toHex(), - peaks: mmrProof.peaks, - siblings: mmrProof.siblings, - eventsProofStr: eventsProof.toHex() - }, (result) => { - console.log('appendRootAndVerifyProof', result) - callback && callback(result); - }); - } - }, t) + darwiniaToEthereumAppendRootAndVerifyProof(_account, { + message: mmrRootMessage.toHex(), + signatures: mmrSignatures.split(','), + root: mmrRoot, + MMRIndex: mmrIndex, + blockNumber: blockNumber, + blockHeader: blockHeader.toHex(), + peaks: mmrProof.peaks, + siblings: mmrProof.siblings, + eventsProofStr: eventsProof.toHex() + }, (result) => { + console.log('appendRootAndVerifyProof', result) + callback && callback(result); + }); + fetchingEndCallback && fetchingEndCallback(); + } + }, t) + } catch (error) { + fetchingEndCallback && fetchingEndCallback(); + } } export async function darwiniaToEthereumAppendRootAndVerifyProof(account, { diff --git a/src/util/mmrConvert/ckb_merkle_mountain_range_bg.js b/src/util/mmrConvert/ckb_merkle_mountain_range_bg.js index 64d0ad7..30de715 100644 --- a/src/util/mmrConvert/ckb_merkle_mountain_range_bg.js +++ b/src/util/mmrConvert/ckb_merkle_mountain_range_bg.js @@ -7,10 +7,15 @@ createInstance() wasm = m; }); -const u32CvtShim = new Uint32Array(2); +// const u32CvtShim = new Uint32Array(2); -// eslint-disable-next-line no-undef -const uint64CvtShim = new BigUint64Array(u32CvtShim.buffer); +// const bigUintArrayType = +// typeof window.BigUint64Array === 'function' +// ? window.BigUint64Array +// : Float64Array + +// // eslint-disable-next-line no-undef +// const uint64CvtShim = new bigUintArrayType(u32CvtShim.buffer); let cachegetUint8Memory0 = null; function getUint8Memory0() { @@ -57,12 +62,21 @@ export function convert(block_num, mmr_size, mmr_proof, leaf) { try { const retptr = wasm.instance.exports.__wbindgen_export_0.value - 16; wasm.instance.exports.__wbindgen_export_0.value = retptr; - uint64CvtShim[0] = block_num; - const low0 = u32CvtShim[0]; - const high0 = u32CvtShim[1]; - uint64CvtShim[0] = mmr_size; - const low1 = u32CvtShim[0]; - const high1 = u32CvtShim[1]; + + // uint64CvtShim[0] = block_num; + // const low0 = u32CvtShim[0]; + // const high0 = u32CvtShim[1]; + // uint64CvtShim[0] = mmr_size; + // const low1 = u32CvtShim[0]; + // const high1 = u32CvtShim[1]; + + // uint64CvtShim[0] = block_num; + const low0 = block_num; + const high0 = 0; + // uint64CvtShim[0] = mmr_size; + const low1 = mmr_size; + const high1 = 0; + var ptr2 = passArray8ToWasm0(mmr_proof, wasm.instance.exports.__wbindgen_malloc); var len2 = WASM_VECTOR_LEN; var ptr3 = passArray8ToWasm0(leaf, wasm.instance.exports.__wbindgen_malloc);