From a4707eea616ddd39623d8c17ae6b5707e86b3945 Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Thu, 17 Aug 2023 10:58:22 +0300 Subject: [PATCH 01/15] Confirm lockEth via modal --- assets/js/components/ConfirmActionBridge.js | 47 ++++++++++++++++++ assets/js/config_test.js | 12 ++--- assets/js/pages/SpaceBridge.js | 54 +++++++++++++++++---- public/dev_index.html | 2 +- public/index.html | 2 +- 5 files changed, 100 insertions(+), 17 deletions(-) create mode 100644 assets/js/components/ConfirmActionBridge.js diff --git a/assets/js/components/ConfirmActionBridge.js b/assets/js/components/ConfirmActionBridge.js new file mode 100644 index 0000000..ee8c1ca --- /dev/null +++ b/assets/js/components/ConfirmActionBridge.js @@ -0,0 +1,47 @@ +import React from 'react'; +import CommonModal from "../elements/CommonModal" +import {Button } from 'react-bootstrap' +class ConfirmActionBridge extends React.Component { + constructor(props) { + super(props); + // this.state = { + // confirmActionVisibility : true + // } + } + + renderModalHeader() { + let action = 'Unknown action'; + + return 'Action' + } + + renderModalBody() { + return ( + <> + + + ) + } + + closeConfirmCard () { + this.props.context.setState({showBridgeActionConfirmModal : false}); + } + + render () { + return( + <> + {this.props.context.state.showBridgeActionConfirmModal && } + + ) + } +} + +export default ConfirmActionBridge; \ No newline at end of file diff --git a/assets/js/config_test.js b/assets/js/config_test.js index 4be5bb7..46eab12 100644 --- a/assets/js/config_test.js +++ b/assets/js/config_test.js @@ -48,8 +48,8 @@ export const availableNetworks = [ type : 'eth', //'eth', 'enq' testnet : true, //true false available : true, //true false - bridgeContractAddress : '0xa994aa746ba106DEf866B4AA27cAC2C35b0A4678', //strig, undefined if not used - vaultContractAddress : '0x9bA80762F115e3A6f2396dB22d74e32E1B46184c', //strig, undefined if not used + bridgeContractAddress : '0xB887Add45ff97785b7f99707A1E14D564e8bA65f', //strig, undefined if not used + vaultContractAddress : '0x2C8a3a9d360b00e95Bf89e8aA23012fB581a9f95', //strig, undefined if not used bridgeContractABI : spaceBridgeABI, //JSON, undefined if not used logo : undefined, //image, undefined if not used explorerURL : 'https://testnet.bscscan.com', // url to explorer mainpage @@ -63,8 +63,8 @@ export const availableNetworks = [ type : 'eth', //'eth', 'enq' testnet : true, //true false available : true, //true false - bridgeContractAddress : '0x9E7c6500244D2AF33B40Ae9df386f2Df8b188348', //strig, undefined if not used - vaultContractAddress : '0x745aA87F9e0cf367B3F603600aaE90E785b11993', //strig, undefined if not used + bridgeContractAddress : '0x124de276Ac6C4fADe5ec9255ccb27c1d0e9d0826', //strig, undefined if not used + vaultContractAddress : '0x748C3924Bc4268cbB6cc1BD0200Cf00c7ea222FC', //strig, undefined if not used bridgeContractABI : spaceBridgeABI, //JSON, undefined if not used logo : undefined, //image, undefined if not used explorerURL : 'https://mumbai.polygonscan.com', // url to explorer mainpage @@ -78,8 +78,8 @@ export const availableNetworks = [ type : 'eth', //'eth', 'enq' testnet : true, //true false available : true, //true false - bridgeContractAddress : '0x85130CA631c82Ef377AF161CB3936f8afDDa1805', //strig, undefined if not used - vaultContractAddress : '0xea07aF35235675437F05A9d591396EB9ad3d1855', //strig, undefined if not used + bridgeContractAddress : '0xE42Bd380502Ea6eccf9CfF440045D2432cCdF2cE', //strig, undefined if not used + vaultContractAddress : '0x788F2FCa3366b8DDa4f7A83efA92d4679112976b', //strig, undefined if not used bridgeContractABI : spaceBridgeABI, //JSON, undefined if not used logo : undefined, //image, undefined if not used explorerURL : 'https://sepolia.etherscan.io/', // url to explorer mainpage diff --git a/assets/js/pages/SpaceBridge.js b/assets/js/pages/SpaceBridge.js index df8ed13..822c998 100644 --- a/assets/js/pages/SpaceBridge.js +++ b/assets/js/pages/SpaceBridge.js @@ -19,6 +19,8 @@ import ChainsDropdown from './../elements/bridge/ChainsDropdown'; import TokenCardBridge from './../components/TokenCardBridge'; import RescueBridgeTxForm from './../components/RescueBridgeTxForm'; +import ConfirmActionBridge from './../components/ConfirmActionBridge'; + import '../../css/bridge.css'; @@ -56,7 +58,9 @@ class SpaceBridge extends React.Component { showFormInputWarning : false, formInputWarningCause : undefined, formInputWarningMsg : '', - blockConfirmByAmount : true + blockConfirmByAmount : true, + showBridgeActionConfirmModal : false, + bridgeActionParams : undefined } setInterval(() => { this.updateUserHistory(); @@ -494,7 +498,7 @@ class SpaceBridge extends React.Component { if (ethType && (bigIntAmount.value > this.props.srcTokenAllowance)) { this.setState({blockConfirmByAmount : true}); this.showAmountWarning('low-allowance'); - console.log('Amount less than allowance'); + console.log('Amount more than allowance'); } else if (bigIntAmount.value > this.props.srcTokenBalance) { this.setState({blockConfirmByAmount : true}); this.showAmountWarning('exeeds-balance'); @@ -524,6 +528,38 @@ class SpaceBridge extends React.Component { } } + + passActionDataToConfirm(method, parmsObj = undefined) { + let allowedMethods = ['connectWeb3Ext', + 'approveSrcTokenBalance', + 'lockEth', + 'encodeDataAndLock', + 'claimEth', + 'reClaimEth', + 'claimENQ']; + if (!allowedMethods.includes(method)) { + this.setState({'showBridgeActionConfirmModal' : false}); + this.setState({'bridgeActionParams' : undefined}); + this.setState({'bridgeActionType' : undefined}); + console.log('Try to call method', method); + return + } + this.setState({'showBridgeActionConfirmModal' : true}); + this.setState({'bridgeActionParams' : parmsObj}); + this.setState({'bridgeActionType' : method}); + + // connectWeb3Ext - без аргумента, без модалки + // approveSrcTokenBalance - без аргумента + + // lockEth - без аргумента + // encodeDataAndLock - без аргумента + // claimEth {item} + // reClaimEth {item} клейм тайп!!! + // claimENQ {item, claimType, resetCurrent} + + //claimENQ -> if (!(claimType === 'claim' || claimType === 'claimInit' || claimType === 'claimConfirm')) + } + async lockEth() { if (this.props.pubkey !== undefined && this.props.srcTokenHash !== undefined && @@ -1129,12 +1165,12 @@ class SpaceBridge extends React.Component { claimEnq(item, claimType, resetCurrent) { if (resetCurrent === true) - this.passDataToResetClaimModal(item, claimType); + this.passDataToResetClaim(item, claimType); this[`${claimType}Enq`](item); } reClaimEth(item) { - this.passDataToResetClaimModal(item, 'claim'); + this.passDataToResetClaim(item, 'claim'); this.claimEth(item); } @@ -1242,7 +1278,7 @@ class SpaceBridge extends React.Component { this.props.updateCurrentBridgeTx(undefined); } - passDataToResetClaimModal(item, claimType) { + passDataToResetClaim(item, claimType) { if (!(claimType === 'claim' || claimType === 'claimInit' || claimType === 'claimConfirm')) return @@ -1272,7 +1308,6 @@ class SpaceBridge extends React.Component { userHistory[itemIndexInHistory] = itemInHistory localStorage.setItem('bridge_history', JSON.stringify(userHistory)); this.setState({history: userHistory}); - console.log('aaaaaaaaaaaaaa') } } @@ -1303,7 +1338,7 @@ class SpaceBridge extends React.Component { Info {/* */} @@ -1524,7 +1559,7 @@ class SpaceBridge extends React.Component { } else if (cause == 'low-allowance') { this.setState({'formInputWarningCause' : cause}); this.setState({'showFormInputWarning' : true}); - this.setState({'formInputWarningMsg' : 'Amount less than appoved balance'}); + this.setState({'formInputWarningMsg' : 'Amount more than appoved balance'}); } else if (cause == 'exeeds-balance') { this.setState({'formInputWarningCause' : cause}); this.setState({'showFormInputWarning' : true}); @@ -1696,7 +1731,7 @@ class SpaceBridge extends React.Component { this.props.toBlockchain == undefined || this.state.blockConfirmByAmount || this.props.dstDecimals === undefined; - action = this.lockEth.bind(this); + action = this.passActionDataToConfirm.bind(this, 'lockEth'); } else if (this.props.fromBlockchain?.type === 'enq') { disabled = this.props.net.url !== this.props.fromBlockchain?.enqExtensionChainId || this.props.pubkey === undefined || @@ -2086,6 +2121,7 @@ class SpaceBridge extends React.Component { } + ); }; diff --git a/public/dev_index.html b/public/dev_index.html index a38e864..b46eed8 100644 --- a/public/dev_index.html +++ b/public/dev_index.html @@ -15,7 +15,7 @@ - + ENEX diff --git a/public/index.html b/public/index.html index a558ccb..5555289 100644 --- a/public/index.html +++ b/public/index.html @@ -15,7 +15,7 @@ - + ENEX From 4b41403fd548342d3d67c0b4b8cdd021f94a557d Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Thu, 17 Aug 2023 17:55:00 +0300 Subject: [PATCH 02/15] enq-eth bridge via new history workflow --- .../spaceBridgeProvider.js | 54 +++++---- assets/js/pages/SpaceBridge.js | 107 ++++++++++-------- assets/js/utils/BridgeHistoryProcessor.js | 55 ++++++++- 3 files changed, 147 insertions(+), 69 deletions(-) diff --git a/assets/js/contracts-providers/spaceBridgeProvider.js b/assets/js/contracts-providers/spaceBridgeProvider.js index 9e16f09..dc50701 100644 --- a/assets/js/contracts-providers/spaceBridgeProvider.js +++ b/assets/js/contracts-providers/spaceBridgeProvider.js @@ -33,21 +33,23 @@ class SpaceBridgeProvider { timestamp : Date.now() } }; + localStorage.setItem(`bh_lock_${txHash}`, JSON.stringify(accountInteractToBridgeItem)); let bridgeHistoryArray = that.bridgeHistoryProcessor.getBridgeHistoryArray(); - if (bridgeHistoryArray.length > 0) { - let itemIsExist = bridgeHistoryArray.find(function(elem) { - if ((elem.initiator.toUpperCase().includes(src_address.toUpperCase()) || elem.initiator.toUpperCase().includes(dst_address.toUpperCase())) && elem.lock?.transactionHash === transactionHash) - return true - }); + // if (bridgeHistoryArray.length > 0) { + // let itemIsExist = bridgeHistoryArray.find(function(elem) { + // if ((elem.initiator.toUpperCase().includes(src_address.toUpperCase()) || elem.initiator.toUpperCase().includes(dst_address.toUpperCase())) && elem.lock?.transactionHash === transactionHash) + // return true + // }); - if (itemIsExist !== undefined) - return - else - that.bridgeHistoryProcessor.addBridgeHistoryItem(accountInteractToBridgeItem); - } else { - that.bridgeHistoryProcessor.initiateHistoryStorage(accountInteractToBridgeItem); - } + // if (itemIsExist !== undefined) + // return + // else { + // that.bridgeHistoryProcessor.addBridgeHistoryItem(accountInteractToBridgeItem); + // } + // } else { + // that.bridgeHistoryProcessor.initiateHistoryStorage(accountInteractToBridgeItem); + // } } }); @@ -76,22 +78,30 @@ class SpaceBridgeProvider { params.ticket.origin_decimals ]; + let accountInteractToBridgeItem = { + initiator : `${params.ticket.src_address}_${params.ticket.dst_address}`, + validatorRes : params + }; + await this.spaceBridgeContract.methods.claim(ticket, [[params.validator_sign.v, params.validator_sign.r, params.validator_sign.s]]).send({ from: from_address }) .on('transactionHash', transactionHash => { console.log('Claim transactionHash ', transactionHash) if (transactionHash) { txHash = transactionHash; - let bridgeHistoryArray = that.bridgeHistoryProcessor.getBridgeHistoryArray(); - let updatedHistory = bridgeHistoryArray.map(elem => { - if ((elem.initiator.toUpperCase().includes(params.ticket.dst_address.toUpperCase()) || elem.initiator.toUpperCase().includes(params.ticket.src_address.toUpperCase())) && elem.lock.transactionHash !== undefined && elem.lock.transactionHash === elemLockTransactionHash) { - console.log('UPDATE STORAGE AFTER CLAIM -----------------------------------') - elem.claimTxHash = transactionHash; - elem.claimTxTimestamp = Date.now(); - } - return elem - }); + accountInteractToBridgeItem.claimTxHash = transactionHash; + accountInteractToBridgeItem.claimTxTimestamp = Date.now(); + localStorage.setItem(`bh_claim_eth_${txHash}`, JSON.stringify(accountInteractToBridgeItem)); + // let bridgeHistoryArray = that.bridgeHistoryProcessor.getBridgeHistoryArray(); + // let updatedHistory = bridgeHistoryArray.map(elem => { + // if ((elem.initiator.toUpperCase().includes(params.ticket.dst_address.toUpperCase()) || elem.initiator.toUpperCase().includes(params.ticket.src_address.toUpperCase())) && elem.lock.transactionHash !== undefined && elem.lock.transactionHash === elemLockTransactionHash) { + // console.log('UPDATE STORAGE AFTER CLAIM -----------------------------------') + // elem.claimTxHash = transactionHash; + // elem.claimTxTimestamp = Date.now(); + // } + // return elem + // }); - localStorage.setItem('bridge_history', JSON.stringify(updatedHistory)); + // localStorage.setItem('bridge_history', JSON.stringify(updatedHistory)); } }); console.log("send: " + txHash); diff --git a/assets/js/pages/SpaceBridge.js b/assets/js/pages/SpaceBridge.js index 08c5e08..5c5fdce 100644 --- a/assets/js/pages/SpaceBridge.js +++ b/assets/js/pages/SpaceBridge.js @@ -176,7 +176,7 @@ class SpaceBridge extends React.Component { let enqExtUserId = this.props.pubkey; let web3ExtUserId = this.props.nonNativeConnection.web3ExtensionAccountId; let userHistory = this.bridgeHistoryProcessor.getUserHistory(enqExtUserId, web3ExtUserId); - //console.log(userHistory) + console.log('aaaaaaaaaaaaa',userHistory) let that = this; if (userHistory.length > 0) { this.setState({history: userHistory}); @@ -193,7 +193,7 @@ class SpaceBridge extends React.Component { web3Provider.getTxReceipt(elem.lock.transactionHash, 'Lock').then(function(res) { if (res !== null && res !== undefined && res.status !== undefined) { elem.lock.status = Number(res.status) === 1 ? true : false; - localStorage.setItem('bridge_history', JSON.stringify(array)); + localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); that.setState({history: array}); } }, function(err) { @@ -209,8 +209,9 @@ class SpaceBridge extends React.Component { console.log(res) res.json().then(function(tx) { if (tx.status !== undefined) { - elem.lock.status = tx.status === 3 ? true : false; - localStorage.setItem('bridge_history', JSON.stringify(array)); + elem.lock.status = tx.status === 3 ? true : false; + localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); + //localStorage.setItem('bridge_history', JSON.stringify(array)); that.setState({history: array}); } else { console.log('Undefined lock transaction status', elem.lock.transactionHash); @@ -232,7 +233,8 @@ class SpaceBridge extends React.Component { web3Provider.getTxReceipt(elem.claimTxHash, 'Claim').then(function(res) { if (res !== null && res !== undefined && res.status !== undefined) { elem.claimTxStatus = Number(res.status) === 1 ? true : false; - localStorage.setItem('bridge_history', JSON.stringify(array)); + localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); + //localStorage.setItem('bridge_history', JSON.stringify(array)); that.setState({history: array}); } else { console.log('Undefined claim transaction status', elem.lock.transactionHash); @@ -252,7 +254,7 @@ class SpaceBridge extends React.Component { res.json().then(tx => { if (tx.status !== undefined) { elem.claimInitTxStatus = tx.status === 3 ? true : false; - localStorage.setItem('bridge_history', JSON.stringify(array)); + //localStorage.setItem('bridge_history', JSON.stringify(array)); that.setState({history: array}); } }, function(err) { @@ -275,7 +277,7 @@ class SpaceBridge extends React.Component { res.json().then(tx => { if (tx.status !== undefined) { elem.claimConfirmTxStatus = tx.status === 3 ? true : false; - localStorage.setItem('bridge_history', JSON.stringify(array)); + //localStorage.setItem('bridge_history', JSON.stringify(array)); that.setState({history: array}); console.log('7777777777777777777') } else { @@ -301,7 +303,8 @@ class SpaceBridge extends React.Component { return } elem.validatorRes = validatorRes; - localStorage.setItem('bridge_history', JSON.stringify(array)); + localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); + //localStorage.setItem('bridge_history', JSON.stringify(array)); that.setState({history: array}); console.log('888888888888888') }, function(err) { @@ -647,16 +650,23 @@ class SpaceBridge extends React.Component { return extRequests.claimInit(pubkey, claimInitData).then(result => { console.log('Success', result.hash); - let bridgeHistoryArray = that.bridgeHistoryProcessor.getBridgeHistoryArray(); - let updatedHistory = bridgeHistoryArray.map(elem => { - if (elem.initiator.toUpperCase().includes(pubkey.toUpperCase()) && elem.lock.transactionHash !== undefined && elem.lock.transactionHash === bridgeItem.lock.transactionHash) { - elem.claimInitTxTimestamp = Date.now(); - elem.claimInitTxHash = result.hash; - } - return elem - }); - - localStorage.setItem('bridge_history', JSON.stringify(updatedHistory)); + let accountInteractToBridgeItem = { + initiator : `${bridgeItem.ticket.src_address}_${bridgeItem.ticket.dst_address}`, + claimInitData, + claimInitTxTimestamp : Date.now(), + claimInitTxHash : result.hash + }; + localStorage.setItem(`bh_claim_init_enq_${result.hash}`, JSON.stringify(accountInteractToBridgeItem)); + // let bridgeHistoryArray = that.bridgeHistoryProcessor.getBridgeHistoryArray(); + // let updatedHistory = bridgeHistoryArray.map(elem => { + // if (elem.initiator.toUpperCase().includes(pubkey.toUpperCase()) && elem.lock.transactionHash !== undefined && elem.lock.transactionHash === bridgeItem.lock.transactionHash) { + // elem.claimInitTxTimestamp = Date.now(); + // elem.claimInitTxHash = result.hash; + // } + // return elem + // }); + + // localStorage.setItem('bridge_history', JSON.stringify(updatedHistory)); let interpolateParams, txTypes = presets.pending.allowedTxTypes; let actionType = presets.pending.allowedTxTypes.claim_init; @@ -678,17 +688,23 @@ class SpaceBridge extends React.Component { return extRequests.claimConfirm(pubkey, claimConfirmData).then(result => { console.log('Success', result.hash); - - let bridgeHistoryArray = that.bridgeHistoryProcessor.getBridgeHistoryArray(); - let updatedHistory = bridgeHistoryArray.map(elem => { - if (elem.initiator.toUpperCase().includes(pubkey.toUpperCase()) && elem.lock.transactionHash !== undefined && elem.lock.transactionHash === bridgeItem.lock.transactionHash) { - elem.claimConfirmTxTimestamp = Date.now(); - elem.claimConfirmTxHash = result.hash; - } - return elem - }); - - localStorage.setItem('bridge_history', JSON.stringify(updatedHistory)); + let accountInteractToBridgeItem = { + initiator : `${bridgeItem.ticket.src_address}_${bridgeItem.ticket.dst_address}`, + claimConfirmData, + claimConfirmTxTimestamp : Date.now(), + claimConfirmTxHash : result.hash + }; + localStorage.setItem(`bh_claim_confirm_enq_${result.hash}`, JSON.stringify(accountInteractToBridgeItem)); + // let bridgeHistoryArray = that.bridgeHistoryProcessor.getBridgeHistoryArray(); + // let updatedHistory = bridgeHistoryArray.map(elem => { + // if (elem.initiator.toUpperCase().includes(pubkey.toUpperCase()) && elem.lock.transactionHash !== undefined && elem.lock.transactionHash === bridgeItem.lock.transactionHash) { + // elem.claimConfirmTxTimestamp = Date.now(); + // elem.claimConfirmTxHash = result.hash; + // } + // return elem + // }); + + // localStorage.setItem('bridge_history', JSON.stringify(updatedHistory)); let interpolateParams, txTypes = presets.pending.allowedTxTypes; let actionType = presets.pending.allowedTxTypes.claim_confirm; @@ -786,21 +802,21 @@ class SpaceBridge extends React.Component { timestamp : Date.now() } }; - - let bridgeHistoryArray = that.bridgeHistoryProcessor.getBridgeHistoryArray(); - if (bridgeHistoryArray.length > 0) { - let itemIsExist = bridgeHistoryArray.find(function(elem) { - if (elem.initiator.toUpperCase().includes(pubkey.toUpperCase()) && elem.lock?.transactionHash === result.hash) - return true - }); - - if (itemIsExist !== undefined) - return - else - that.bridgeHistoryProcessor.addBridgeHistoryItem(accountInteractToBridgeItem); - } else { - that.bridgeHistoryProcessor.initiateHistoryStorage(accountInteractToBridgeItem); - } + localStorage.setItem(`bh_lock_${result.hash}`, JSON.stringify(accountInteractToBridgeItem)); + // let bridgeHistoryArray = that.bridgeHistoryProcessor.getBridgeHistoryArray(); + // if (bridgeHistoryArray.length > 0) { + // let itemIsExist = bridgeHistoryArray.find(function(elem) { + // if (elem.initiator.toUpperCase().includes(pubkey.toUpperCase()) && elem.lock?.transactionHash === result.hash) + // return true + // }); + + // if (itemIsExist !== undefined) + // return + // else + // that.bridgeHistoryProcessor.addBridgeHistoryItem(accountInteractToBridgeItem); + // } else { + // that.bridgeHistoryProcessor.initiateHistoryStorage(accountInteractToBridgeItem); + // } }, error => { console.log('Error') @@ -1270,9 +1286,8 @@ class SpaceBridge extends React.Component { itemInHistory[claimTxStatusPropStr] = undefined; itemInHistory[claimTxTimestampPropStr] = undefined; userHistory[itemIndexInHistory] = itemInHistory - localStorage.setItem('bridge_history', JSON.stringify(userHistory)); + //localStorage.setItem('bridge_history', JSON.stringify(userHistory)); this.setState({history: userHistory}); - console.log('aaaaaaaaaaaaaa') } } diff --git a/assets/js/utils/BridgeHistoryProcessor.js b/assets/js/utils/BridgeHistoryProcessor.js index b89904e..f0e4d3e 100644 --- a/assets/js/utils/BridgeHistoryProcessor.js +++ b/assets/js/utils/BridgeHistoryProcessor.js @@ -23,7 +23,7 @@ class BridgeHistoryProcessor { localStorage.setItem('bridge_history', JSON.stringify(history)); } - getUserHistory(enqExtUserId, web3ExtUserId) { + getUserHistoryFromTotalArray(enqExtUserId, web3ExtUserId) { let userHistory = []; if((enqExtUserId !== undefined && enqExtUserId !== '') || (web3ExtUserId !== undefined && web3ExtUserId !== '')) { @@ -38,6 +38,59 @@ class BridgeHistoryProcessor { } return userHistory; } + + getUserHistory(enqExtUserId, web3ExtUserId) { + let userHistory = []; + if ((enqExtUserId !== undefined && enqExtUserId !== '') || + (web3ExtUserId !== undefined && web3ExtUserId !== '')) { + console.log('call getUserHistory'); + let lockArr = []; + let claimEthArr = []; + let claimInitENQArr = []; + let claimConfirmENQArr = []; + for(let key in localStorage) { + if (key.includes('bh_lock_')) { + lockArr.push(JSON.parse(localStorage.getItem(key))) + } + if (key.includes('bh_claim_eth_')) { + claimEthArr.push(JSON.parse(localStorage.getItem(key))) + } + if (key.includes('bh_claim_init_enq_')) { + claimInitENQArr.push(JSON.parse(localStorage.getItem(key))) + } + if (key.includes('bh_claim_confirm_enq_')) { + claimConfirmENQArr.push(JSON.parse(localStorage.getItem(key))) + } + } + + if (lockArr.length > 0) { + lockArr.sort(function (a, b) { + return a.lock.timestamp - b.lock.timestamp; + }); + userHistory = lockArr; + + lockArr.forEach(function(lock, lockIndex, lockArray){ + claimEthArr.forEach(function(claim, claimIndex, claimArray){ + if (lock.hasOwnProperty('validatorRes') && lock.validatorRes?.ticket_hash !== undefined && + claim.hasOwnProperty('validatorRes') && claim.validatorRes?.ticket_hash !== undefined && + lock.validatorRes.ticket_hash === claim.validatorRes.ticket_hash) { + console.log('333333333333333333333333333333333333333333333') + lock.claimTxHash = claim.claimTxHash; + lock.claimTxTimestamp = claim.claimTxTimestamp; + localStorage.setItem(`bh_lock_${lock.lock.transactionHash}`, JSON.stringify(lock)); + } + }); + }); + userHistory = lockArr; + } else { + console.log('Empty locks list') + } + + + } + + return userHistory; + } } export default BridgeHistoryProcessor; \ No newline at end of file From 7fd09e001e928a996354aaa1628e7ef079260343 Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Fri, 18 Aug 2023 14:55:18 +0300 Subject: [PATCH 03/15] eth claim, reclaim via new history workflow --- .gitignore | 3 +- .../spaceBridgeProvider.js | 8 ++-- assets/js/pages/SpaceBridge.js | 22 +++++----- assets/js/utils/BridgeHistoryProcessor.js | 44 ++++++++++++++++--- 4 files changed, 56 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 9ffd2fa..136c95f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ public/* !public/favicon-32x32.png !public/tokenList.js package-lock.json -.idea \ No newline at end of file +.idea +assets/js/config.js \ No newline at end of file diff --git a/assets/js/contracts-providers/spaceBridgeProvider.js b/assets/js/contracts-providers/spaceBridgeProvider.js index dc50701..46c7576 100644 --- a/assets/js/contracts-providers/spaceBridgeProvider.js +++ b/assets/js/contracts-providers/spaceBridgeProvider.js @@ -16,7 +16,7 @@ class SpaceBridgeProvider { .on('transactionHash', transactionHash => { console.log('Lock transactionHash ', transactionHash) if (transactionHash) { - txHash = transactionHash + txHash = transactionHash; let accountInteractToBridgeItem = { initiator : `${src_address}_${dst_address}`, lock : { @@ -34,8 +34,10 @@ class SpaceBridgeProvider { } }; localStorage.setItem(`bh_lock_${txHash}`, JSON.stringify(accountInteractToBridgeItem)); - - let bridgeHistoryArray = that.bridgeHistoryProcessor.getBridgeHistoryArray(); + if (callback !== undefined) { + callback(txHash) + } + //let bridgeHistoryArray = that.bridgeHistoryProcessor.getBridgeHistoryArray(); // if (bridgeHistoryArray.length > 0) { // let itemIsExist = bridgeHistoryArray.find(function(elem) { // if ((elem.initiator.toUpperCase().includes(src_address.toUpperCase()) || elem.initiator.toUpperCase().includes(dst_address.toUpperCase())) && elem.lock?.transactionHash === transactionHash) diff --git a/assets/js/pages/SpaceBridge.js b/assets/js/pages/SpaceBridge.js index 5c5fdce..7e895e2 100644 --- a/assets/js/pages/SpaceBridge.js +++ b/assets/js/pages/SpaceBridge.js @@ -176,7 +176,6 @@ class SpaceBridge extends React.Component { let enqExtUserId = this.props.pubkey; let web3ExtUserId = this.props.nonNativeConnection.web3ExtensionAccountId; let userHistory = this.bridgeHistoryProcessor.getUserHistory(enqExtUserId, web3ExtUserId); - console.log('aaaaaaaaaaaaa',userHistory) let that = this; if (userHistory.length > 0) { this.setState({history: userHistory}); @@ -254,6 +253,7 @@ class SpaceBridge extends React.Component { res.json().then(tx => { if (tx.status !== undefined) { elem.claimInitTxStatus = tx.status === 3 ? true : false; + localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); //localStorage.setItem('bridge_history', JSON.stringify(array)); that.setState({history: array}); } @@ -277,9 +277,9 @@ class SpaceBridge extends React.Component { res.json().then(tx => { if (tx.status !== undefined) { elem.claimConfirmTxStatus = tx.status === 3 ? true : false; + localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); //localStorage.setItem('bridge_history', JSON.stringify(array)); that.setState({history: array}); - console.log('7777777777777777777') } else { console.log('Undefined claim confirm transaction status', elem.lock.transactionHash); } @@ -306,7 +306,6 @@ class SpaceBridge extends React.Component { localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); //localStorage.setItem('bridge_history', JSON.stringify(array)); that.setState({history: array}); - console.log('888888888888888') }, function(err) { console.log('Can\'t get notify response ', err); }); @@ -318,7 +317,6 @@ class SpaceBridge extends React.Component { clearHistory() { localStorage.removeItem('bridge_history'); this.setState({history: []}); - console.log('9999999999999999') this.toggleHistoryBridge(); } @@ -565,9 +563,7 @@ class SpaceBridge extends React.Component { console.log({src_address_trim_0x, token_hash_trim_0x, fromBlockchain : this.props.fromBlockchain.id, dst_address, toBlockchain : this.props.toBlockchain.id}) let nonce = await bridgeProvider.getTransfer(src_address_trim_0x, token_hash_trim_0x, this.props.fromBlockchain.id, dst_address, this.props.toBlockchain.id); nonce = !isNaN(nonce) ? nonce + 1 : nonce; - bridgeProvider.lock(src_address, this.props.fromBlockchain.id, dst_address, this.props.toBlockchain.id /*11*/, amount, token_hash, nonce, token_decimals, ticker, that.props.updateCurrentBridgeTx).then(function(lockTx) { - console.log('lock result', lockTx); - }); + bridgeProvider.lock(src_address, this.props.fromBlockchain.id, dst_address, this.props.toBlockchain.id /*11*/, amount, token_hash, nonce, token_decimals, ticker, that.props.updateCurrentBridgeTx); } else { alert('Wrong input data') } @@ -575,7 +571,6 @@ class SpaceBridge extends React.Component { getValidatorRes () { let that = this; - console.log(this.props.pubkey, this.props.nonNativeConnection.web3ExtensionAccountId) let userHistory = this.bridgeHistoryProcessor.getUserHistory(this.props.pubkey, this.props.nonNativeConnection.web3ExtensionAccountId); if (this.props.currentBridgeTx !== undefined) { @@ -651,8 +646,9 @@ class SpaceBridge extends React.Component { extRequests.claimInit(pubkey, claimInitData).then(result => { console.log('Success', result.hash); let accountInteractToBridgeItem = { - initiator : `${bridgeItem.ticket.src_address}_${bridgeItem.ticket.dst_address}`, + initiator : `${bridgeItem.validatorRes.ticket.src_address}_${bridgeItem.validatorRes.ticket.dst_address}`, claimInitData, + validatorRes : bridgeItem.validatorRes, claimInitTxTimestamp : Date.now(), claimInitTxHash : result.hash }; @@ -689,8 +685,9 @@ class SpaceBridge extends React.Component { extRequests.claimConfirm(pubkey, claimConfirmData).then(result => { console.log('Success', result.hash); let accountInteractToBridgeItem = { - initiator : `${bridgeItem.ticket.src_address}_${bridgeItem.ticket.dst_address}`, + initiator : `${bridgeItem.validatorRes.ticket.src_address}_${bridgeItem.validatorRes.ticket.dst_address}`, claimConfirmData, + validatorRes : bridgeItem.validatorRes, claimConfirmTxTimestamp : Date.now(), claimConfirmTxHash : result.hash }; @@ -1267,7 +1264,7 @@ class SpaceBridge extends React.Component { let claimTxStatusPropStr = `${claimType}TxStatus`; let claimTxTimestampPropStr = `${claimType}TxTimestamp`; - let userHistory = this.bridgeHistoryProcessor.getBridgeHistoryArray(); + let userHistory = this.state.history;//this.bridgeHistoryProcessor.getBridgeHistoryArray(); let itemIndexInHistory = userHistory.findIndex(elem => elem[claimTxHashPropStr] === item[claimTxHashPropStr] && elem.lock.transactionHash === item.lock.transactionHash); if (itemIndexInHistory !== -1) { @@ -1285,7 +1282,8 @@ class SpaceBridge extends React.Component { itemInHistory[claimTxHashPropStr] = undefined; itemInHistory[claimTxStatusPropStr] = undefined; itemInHistory[claimTxTimestampPropStr] = undefined; - userHistory[itemIndexInHistory] = itemInHistory + userHistory[itemIndexInHistory] = itemInHistory; + localStorage.setItem(`bh_lock_${item.lock.transactionHash}`, JSON.stringify(item)); //localStorage.setItem('bridge_history', JSON.stringify(userHistory)); this.setState({history: userHistory}); } diff --git a/assets/js/utils/BridgeHistoryProcessor.js b/assets/js/utils/BridgeHistoryProcessor.js index f0e4d3e..e3d54d8 100644 --- a/assets/js/utils/BridgeHistoryProcessor.js +++ b/assets/js/utils/BridgeHistoryProcessor.js @@ -42,8 +42,7 @@ class BridgeHistoryProcessor { getUserHistory(enqExtUserId, web3ExtUserId) { let userHistory = []; if ((enqExtUserId !== undefined && enqExtUserId !== '') || - (web3ExtUserId !== undefined && web3ExtUserId !== '')) { - console.log('call getUserHistory'); + (web3ExtUserId !== undefined && web3ExtUserId !== '')) { let lockArr = []; let claimEthArr = []; let claimInitENQArr = []; @@ -55,7 +54,7 @@ class BridgeHistoryProcessor { if (key.includes('bh_claim_eth_')) { claimEthArr.push(JSON.parse(localStorage.getItem(key))) } - if (key.includes('bh_claim_init_enq_')) { + if (key.includes('bh_claim_init_enq_')) { claimInitENQArr.push(JSON.parse(localStorage.getItem(key))) } if (key.includes('bh_claim_confirm_enq_')) { @@ -63,9 +62,27 @@ class BridgeHistoryProcessor { } } + if (claimEthArr.length > 0) { + claimEthArr.sort(function (a, b) { + return a.claimTxTimestamp - b.claimTxTimestamp; + }); + } + + if (claimInitENQArr.length > 0) { + claimInitENQArr.sort(function (a, b) { + return a.claimInitTxTimestamp - b.claimInitTxTimestamp; + }); + } + + if (claimConfirmENQArr.length > 0) { + claimConfirmENQArr.sort(function (a, b) { + return a.claimConfirmTxTimestamp - b.claimConfirmTxTimestamp; + }); + } + if (lockArr.length > 0) { lockArr.sort(function (a, b) { - return a.lock.timestamp - b.lock.timestamp; + return a.lock.timestamp - b.lock.timestamp; }); userHistory = lockArr; @@ -74,12 +91,29 @@ class BridgeHistoryProcessor { if (lock.hasOwnProperty('validatorRes') && lock.validatorRes?.ticket_hash !== undefined && claim.hasOwnProperty('validatorRes') && claim.validatorRes?.ticket_hash !== undefined && lock.validatorRes.ticket_hash === claim.validatorRes.ticket_hash) { - console.log('333333333333333333333333333333333333333333333') lock.claimTxHash = claim.claimTxHash; lock.claimTxTimestamp = claim.claimTxTimestamp; localStorage.setItem(`bh_lock_${lock.lock.transactionHash}`, JSON.stringify(lock)); } }); + claimInitENQArr.forEach(function(claim, claimIndex, claimArray){ + if (lock.hasOwnProperty('validatorRes') && lock.validatorRes?.ticket_hash !== undefined && + claim.hasOwnProperty('validatorRes') && claim.validatorRes?.ticket_hash !== undefined && + lock.validatorRes.ticket_hash === claim.validatorRes.ticket_hash) { + lock.claimInitTxHash = claim.claimInitTxHash; + lock.claimInitTxTimestamp = claim.claimInitTxTimestamp; + localStorage.setItem(`bh_lock_${lock.lock.transactionHash}`, JSON.stringify(lock)); + } + }); + claimConfirmENQArr.forEach(function(claim, claimIndex, claimArray){ + if (lock.hasOwnProperty('validatorRes') && lock.validatorRes?.ticket_hash !== undefined && + claim.hasOwnProperty('validatorRes') && claim.validatorRes?.ticket_hash !== undefined && + lock.validatorRes.ticket_hash === claim.validatorRes.ticket_hash) { + lock.claimConfirmTxHash = claim.claimConfirmTxHash; + lock.claimConfirmTxTimestamp = claim.claimConfirmTxTimestamp; + localStorage.setItem(`bh_lock_${lock.lock.transactionHash}`, JSON.stringify(lock)); + } + }); }); userHistory = lockArr; } else { From c2ef73f624c2221bbf8734ece1f0a7bb57b63dd5 Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Fri, 18 Aug 2023 15:28:00 +0300 Subject: [PATCH 04/15] use only success or fail statuses --- assets/js/pages/SpaceBridge.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/assets/js/pages/SpaceBridge.js b/assets/js/pages/SpaceBridge.js index 7e895e2..64446a8 100644 --- a/assets/js/pages/SpaceBridge.js +++ b/assets/js/pages/SpaceBridge.js @@ -191,7 +191,11 @@ class SpaceBridge extends React.Component { let web3Provider = new web3LibProvider(dataProvider); web3Provider.getTxReceipt(elem.lock.transactionHash, 'Lock').then(function(res) { if (res !== null && res !== undefined && res.status !== undefined) { - elem.lock.status = Number(res.status) === 1 ? true : false; + if (Number(res.status) === 1) + elem.lock.status = true; + else if (Number(res.status) === 0) + elem.lock.status = false; + // elem.lock.status = Number(res.status) === 1 ? true : false; localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); that.setState({history: array}); } @@ -208,7 +212,11 @@ class SpaceBridge extends React.Component { console.log(res) res.json().then(function(tx) { if (tx.status !== undefined) { - elem.lock.status = tx.status === 3 ? true : false; + if (tx.status === 3) + elem.lock.status = true; + else if (tx.status === 2) + elem.lock.status = false; + localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); //localStorage.setItem('bridge_history', JSON.stringify(array)); that.setState({history: array}); @@ -231,7 +239,11 @@ class SpaceBridge extends React.Component { let web3Provider = new web3LibProvider(dataProvider); web3Provider.getTxReceipt(elem.claimTxHash, 'Claim').then(function(res) { if (res !== null && res !== undefined && res.status !== undefined) { - elem.claimTxStatus = Number(res.status) === 1 ? true : false; + if (Number(res.status) === 1) + elem.claimTxStatus = true; + else if (Number(res.status) === 0) + elem.claimTxStatus = false; + //elem.claimTxStatus = Number(res.status) === 1 ? true : false; localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); //localStorage.setItem('bridge_history', JSON.stringify(array)); that.setState({history: array}); @@ -252,7 +264,11 @@ class SpaceBridge extends React.Component { if (res !== null && !res.lock) { res.json().then(tx => { if (tx.status !== undefined) { - elem.claimInitTxStatus = tx.status === 3 ? true : false; + if (tx.status === 3) + elem.claimInitTxStatus = true; + else if (tx.status === 2) + elem.claimInitTxStatus = false; + localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); //localStorage.setItem('bridge_history', JSON.stringify(array)); that.setState({history: array}); @@ -276,7 +292,11 @@ class SpaceBridge extends React.Component { if (res !== null && !res.lock) { res.json().then(tx => { if (tx.status !== undefined) { - elem.claimConfirmTxStatus = tx.status === 3 ? true : false; + if (tx.status === 3) + elem.claimConfirmTxStatus = true; + else if (tx.status === 2) + elem.claimConfirmTxStatus = false; + localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); //localStorage.setItem('bridge_history', JSON.stringify(array)); that.setState({history: array}); From ef84b95c53ffe14aae0492f6e3869e69df1b7f33 Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Tue, 22 Aug 2023 16:02:03 +0300 Subject: [PATCH 05/15] bridgeAPI url to config --- assets/js/config_prod.js | 5 +---- assets/js/config_test.js | 17 +++++++---------- assets/js/pages/SpaceBridge.js | 6 +++--- assets/js/requests/ValidatorRequests.js | 6 +++--- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/assets/js/config_prod.js b/assets/js/config_prod.js index dd39f66..198bd5e 100644 --- a/assets/js/config_prod.js +++ b/assets/js/config_prod.js @@ -3,11 +3,8 @@ import vaultABI from './../ABI/vault'; import spaceBridgeABI from './../ABI/abi_spaceBridge.json'; import wethABI from './../ABI/abi_weth.json'; -export const defaultParams = { - chain : '0x1' -} - export const maxEnqValue = BigInt('18446744073709551615'); //amount in cents +export const bridgeApiURL = 'https://bridge.enex.space/api/v1'; export const availableNetworks = [ { diff --git a/assets/js/config_test.js b/assets/js/config_test.js index 4be5bb7..619b03b 100644 --- a/assets/js/config_test.js +++ b/assets/js/config_test.js @@ -3,11 +3,8 @@ import vaultABI from './../ABI/vault'; import spaceBridgeABI from './../ABI/abi_spaceBridge.json'; import wethABI from './../ABI/abi_weth.json'; -export const defaultParams = { - chain : '0x1' -} - export const maxEnqValue = BigInt('18446744073709551615'); //amount in cents +export const bridgeApiURL = 'https://bridge.enex.space/api/v1'; export const availableNetworks = [ { @@ -48,8 +45,8 @@ export const availableNetworks = [ type : 'eth', //'eth', 'enq' testnet : true, //true false available : true, //true false - bridgeContractAddress : '0xa994aa746ba106DEf866B4AA27cAC2C35b0A4678', //strig, undefined if not used - vaultContractAddress : '0x9bA80762F115e3A6f2396dB22d74e32E1B46184c', //strig, undefined if not used + bridgeContractAddress : '0xB887Add45ff97785b7f99707A1E14D564e8bA65f', //strig, undefined if not used + vaultContractAddress : '0x2C8a3a9d360b00e95Bf89e8aA23012fB581a9f95', //strig, undefined if not used bridgeContractABI : spaceBridgeABI, //JSON, undefined if not used logo : undefined, //image, undefined if not used explorerURL : 'https://testnet.bscscan.com', // url to explorer mainpage @@ -63,8 +60,8 @@ export const availableNetworks = [ type : 'eth', //'eth', 'enq' testnet : true, //true false available : true, //true false - bridgeContractAddress : '0x9E7c6500244D2AF33B40Ae9df386f2Df8b188348', //strig, undefined if not used - vaultContractAddress : '0x745aA87F9e0cf367B3F603600aaE90E785b11993', //strig, undefined if not used + bridgeContractAddress : '0x124de276Ac6C4fADe5ec9255ccb27c1d0e9d0826', //strig, undefined if not used + vaultContractAddress : '0x748C3924Bc4268cbB6cc1BD0200Cf00c7ea222FC', //strig, undefined if not used bridgeContractABI : spaceBridgeABI, //JSON, undefined if not used logo : undefined, //image, undefined if not used explorerURL : 'https://mumbai.polygonscan.com', // url to explorer mainpage @@ -78,8 +75,8 @@ export const availableNetworks = [ type : 'eth', //'eth', 'enq' testnet : true, //true false available : true, //true false - bridgeContractAddress : '0x85130CA631c82Ef377AF161CB3936f8afDDa1805', //strig, undefined if not used - vaultContractAddress : '0xea07aF35235675437F05A9d591396EB9ad3d1855', //strig, undefined if not used + bridgeContractAddress : '0xE42Bd380502Ea6eccf9CfF440045D2432cCdF2cE', //strig, undefined if not used + vaultContractAddress : '0x788F2FCa3366b8DDa4f7A83efA92d4679112976b', //strig, undefined if not used bridgeContractABI : spaceBridgeABI, //JSON, undefined if not used logo : undefined, //image, undefined if not used explorerURL : 'https://sepolia.etherscan.io/', // url to explorer mainpage diff --git a/assets/js/pages/SpaceBridge.js b/assets/js/pages/SpaceBridge.js index 64446a8..ada03cf 100644 --- a/assets/js/pages/SpaceBridge.js +++ b/assets/js/pages/SpaceBridge.js @@ -37,7 +37,7 @@ import extRequests from '../requests/extRequests'; import networkApi from "../requests/networkApi"; import validatorRequests from "../requests/ValidatorRequests"; -import {availableNetworks, smartContracts} from'./../config'; +import {availableNetworks, smartContracts, bridgeApiURL} from'./../config'; import metamaskLogo from './../../img/metamask-logo.webp'; @@ -444,7 +444,7 @@ class SpaceBridge extends React.Component { // } async getDstDecimalsFromValidator(src_network_id, dst_network_id, src_token_hash) { - let URL = `https://bridge.enex.space/api/v1/get_dst_decimals?src_network_id=${src_network_id}&dst_network_id=${dst_network_id}&hash=${src_token_hash}`; + let URL = `${bridgeApiURL}/get_dst_decimals?src_network_id=${src_network_id}&dst_network_id=${dst_network_id}&hash=${src_token_hash}`; return fetch(URL, { method: 'GET' }).then(function(response) { @@ -758,7 +758,7 @@ class SpaceBridge extends React.Component { nonce++; - URL = 'https://bridge.enex.space/api/v1/encode_lock'; + URL = `${bridgeApiURL}/encode_lock`; let token_decimals = Number(this.props.srcTokenDecimals); let amount = this.valueProcessor.valueToBigInt(this.props.srcTokenAmountToSend, token_decimals).value; let data = { diff --git a/assets/js/requests/ValidatorRequests.js b/assets/js/requests/ValidatorRequests.js index ac16609..fa52cb3 100644 --- a/assets/js/requests/ValidatorRequests.js +++ b/assets/js/requests/ValidatorRequests.js @@ -1,11 +1,11 @@ /** - * @fileoverview Requets to Validator + * @fileoverview Requests to Validator */ -import config from '../config.js'; +import {bridgeApiURL} from './../config.js'; class ValidatorRequests { constructor () { - this.url = 'https://bridge.enex.space/api/v1/notify'; + this.url = `${bridgeApiURL}/notify`; } async postToValidator(txHash, srcNetwork = undefined) { From 427988abe490bbc66bff6634336b1f925f76d6eb Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Wed, 23 Aug 2023 09:52:18 +0300 Subject: [PATCH 06/15] claim after confirm --- assets/js/components/ConfirmActionBridge.js | 26 +++++-- assets/js/pages/SpaceBridge.js | 77 +++++++++++---------- 2 files changed, 63 insertions(+), 40 deletions(-) diff --git a/assets/js/components/ConfirmActionBridge.js b/assets/js/components/ConfirmActionBridge.js index ee8c1ca..8f22834 100644 --- a/assets/js/components/ConfirmActionBridge.js +++ b/assets/js/components/ConfirmActionBridge.js @@ -15,17 +15,33 @@ class ConfirmActionBridge extends React.Component { return 'Action' } + getActionTitle() { + let method = this.props.context.state.bridgeActionType; + let res = 'Unknown Method'; + if (this.props.context.allowedMethods.includes(method)) { + if (method === 'connectWeb3Ext') + res = 'Connect Web3 Extension'; + else if (method === 'approveSrcTokenBalance') + res = 'Approve Balance'; + else if (method === 'lockEth' || method === 'encodeDataAndLock') + res = 'Lock'; + else if (method === 'claimEth' || method === 'reClaimEth' || method === 'claimInitEnq' || method === claimConfirmEnq) + res = 'Claim'; + } + return res + } + renderModalBody() { return ( <> - - ) + )//{ this.props.context.state.bridgeActionType } } closeConfirmCard () { @@ -36,7 +52,7 @@ class ConfirmActionBridge extends React.Component { return( <> {this.props.context.state.showBridgeActionConfirmModal && } diff --git a/assets/js/pages/SpaceBridge.js b/assets/js/pages/SpaceBridge.js index cac5c31..1b4dfeb 100644 --- a/assets/js/pages/SpaceBridge.js +++ b/assets/js/pages/SpaceBridge.js @@ -49,6 +49,14 @@ class SpaceBridge extends React.Component { this.bridgeHistoryProcessor = new BridgeHistoryProcessor(); this.valueProcessor = new ValueProcessor; this.availableNetworksUtils = new AvailableNetworksUtils(); + this.allowedMethods = ['connectWeb3Ext', + 'approveSrcTokenBalance', + 'lockEth', + 'encodeDataAndLock', + 'claimEth', + 'reClaimEth', + 'claimInitEnq', + 'claimConfirmEnq']; this.state = { initData : undefined, confirmData : undefined, @@ -551,14 +559,7 @@ class SpaceBridge extends React.Component { passActionDataToConfirm(method, parmsObj = undefined) { - let allowedMethods = ['connectWeb3Ext', - 'approveSrcTokenBalance', - 'lockEth', - 'encodeDataAndLock', - 'claimEth', - 'reClaimEth', - 'claimENQ']; - if (!allowedMethods.includes(method)) { + if (!this.allowedMethods.includes(method)) { this.setState({'showBridgeActionConfirmModal' : false}); this.setState({'bridgeActionParams' : undefined}); this.setState({'bridgeActionType' : undefined}); @@ -692,19 +693,23 @@ class SpaceBridge extends React.Component { } } - claimInitEnq(bridgeItem) { + claimInitEnq(bridgeActionParams) { if (this.props.pubkey !== undefined) { let that = this; let pubkey = this.props.pubkey; - let claimInitData = bridgeItem.validatorRes.encoded_data.enq.init; + let claimInitData = bridgeActionParams.bridgeItem.validatorRes.encoded_data.enq.init; if (!(pubkey && claimInitData)) return + + if (bridgeActionParams.resetCurrent === true) + this.passDataToResetClaim(bridgeActionParams.bridgeItem, claimType); + extRequests.claimInit(pubkey, claimInitData).then(result => { console.log('Success', result.hash); let accountInteractToBridgeItem = { - initiator : `${bridgeItem.validatorRes.ticket.src_address}_${bridgeItem.validatorRes.ticket.dst_address}`, + initiator : `${bridgeActionParams.bridgeItem.validatorRes.ticket.src_address}_${bridgeActionParams.bridgeItem.validatorRes.ticket.dst_address}`, claimInitData, - validatorRes : bridgeItem.validatorRes, + validatorRes : bridgeActionParams.bridgeItem.validatorRes, claimInitTxTimestamp : Date.now(), claimInitTxHash : result.hash }; @@ -731,19 +736,23 @@ class SpaceBridge extends React.Component { } } - claimConfirmEnq(bridgeItem) { + claimConfirmEnq(bridgeActionParams) { if (this.props.pubkey !== undefined) { let that = this; let pubkey = this.props.pubkey; - let claimConfirmData = bridgeItem.validatorRes.encoded_data.enq.confirm; + let claimConfirmData = bridgeActionParams.bridgeItem.validatorRes.encoded_data.enq.confirm; if (!(pubkey && claimConfirmData)) return + + if (bridgeActionParams.resetCurrent === true) + this.passDataToResetClaim(bridgeActionParams.item, claimType); + extRequests.claimConfirm(pubkey, claimConfirmData).then(result => { console.log('Success', result.hash); let accountInteractToBridgeItem = { - initiator : `${bridgeItem.validatorRes.ticket.src_address}_${bridgeItem.validatorRes.ticket.dst_address}`, + initiator : `${bridgeActionParams.bridgeItem.validatorRes.ticket.src_address}_${bridgeActionParams.bridgeItem.validatorRes.ticket.dst_address}`, claimConfirmData, - validatorRes : bridgeItem.validatorRes, + validatorRes : bridgeActionParams.bridgeItem.validatorRes, claimConfirmTxTimestamp : Date.now(), claimConfirmTxHash : result.hash }; @@ -786,8 +795,6 @@ class SpaceBridge extends React.Component { let response = await networkApi.getBridgeLastLockTransfer(address, this.props.pubkey, this.props.toBlockchain.id, this.props.srcTokenHash); - - let nonce = await response.json(); if (nonce !== undefined && nonce !== null) nonce = Number(nonce); @@ -993,7 +1000,7 @@ class SpaceBridge extends React.Component { let resume = 'Validated successfully'; let stateId = 0; let txHash = undefined; - let claimType = 'claimInit'; + let claimType = 'claimInitEnq'; let actionStr = 'Claim'; let resetCurrent = false; let showResetBridge = undefined; @@ -1007,7 +1014,7 @@ class SpaceBridge extends React.Component { resume = 'Claim confirmation failed'; stateId = 2; txHash = item.claimConfirmTxHash; - claimType = 'claimConfirm'; + claimType = 'claimConfirmEnq'; actionStr = 'Retry'; resetCurrent = true; showResetBridge = true; @@ -1020,14 +1027,14 @@ class SpaceBridge extends React.Component { resume = 'Claim confirmation failed'; stateId = 4; actionStr = 'Retry'; - claimType = 'claimConfirm'; + claimType = 'claimConfirmEnq'; resetCurrent = true; showResetBridge = true; } else { resume = 'Claim is ready'; stateId = 5; actionStr = 'Confirm'; - claimType = 'claimConfirm'; + claimType = 'claimConfirmEnq'; resetCurrent = false; } } else if (item.claimInitTxStatus === false || (item.claimInitTxStatus === undefined && (item.hasOwnProperty('claimInitAttemptsList') && Array.isArray(item.claimInitAttemptsList) && item.claimInitAttemptsList.length > 0))) { @@ -1038,7 +1045,7 @@ class SpaceBridge extends React.Component { resume = 'Claim inititalization failed'; stateId = 6; txHash = item.claimInitTxHash; - claimType = 'claimInit'; + claimType = 'claimInitEnq'; actionStr = 'Retry'; resetCurrent = true; showResetBridge = true; @@ -1124,8 +1131,8 @@ class SpaceBridge extends React.Component { {[0,2,4,5,6].includes(stateId) && matchChains && matchDstAddress && <> @@ -1196,11 +1203,11 @@ class SpaceBridge extends React.Component { ) } - claimEnq(item, claimType, resetCurrent) { - if (resetCurrent === true) - this.passDataToResetClaim(item, claimType); - this[`${claimType}Enq`](item); - } + // claimEnq(claimType, bridgeActionParams) { + // if (bridgeActionParams.resetCurrent === true) + // this.passDataToResetClaim(bridgeActionParams.item, claimType); + // this[`${claimType}Enq`](item); + // } reClaimEth(item) { this.passDataToResetClaim(item, 'claim'); @@ -1222,15 +1229,15 @@ class SpaceBridge extends React.Component { title = `Connect address ${utils.packHashString(item.lock.dst_address)}`; } else if (dstNetworkHexId === this.props.nonNativeConnection.web3ExtensionChain) { if (item.claimTxStatus === false) { - action = this.reClaimEth.bind(this, item); + action = this.passActionDataToConfirm.bind(this, 'reClaimEth', item); //reClaimEth.bind(this, item); resume = 'Failed'; title = 'Retry'; } else if (item.hasOwnProperty('claimAttemptsList') && Array.isArray(item.claimAttemptsList) && item.claimAttemptsList.length > 0) { - action = this.claimEth.bind(this, item); + action = this.passActionDataToConfirm.bind(this, 'claimEth', item); //claimEth.bind(this, item); resume = 'Failed'; title = 'Retry'; } else { - action = this.claimEth.bind(this, item); + action = this.passActionDataToConfirm.bind(this, 'claimEth', item); //claimEth.bind(this, item); title = 'Claim'; } } else if (dstNetworkHexId !== this.props.nonNativeConnection.web3ExtensionChain && chainId !== undefined) { @@ -1472,7 +1479,7 @@ class SpaceBridge extends React.Component { Approved balance: {this.props.srcTokenAllowance / Math.pow(10, this.props.srcTokenDecimals)} + onClick={this.passActionDataToConfirm.bind(this, 'approveSrcTokenBalance')}>Approve @@ -1777,7 +1784,7 @@ class SpaceBridge extends React.Component { this.props.toBlockchain == undefined || this.state.blockConfirmByAmount || this.props.dstDecimals === undefined; - action = this.encodeDataAndLock.bind(this); + action = this.passActionDataToConfirm.bind(this, 'encodeDataAndLock'); } } From e1cb0a0e7a0b712abecffb858364a021cb54b828 Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Wed, 23 Aug 2023 12:07:02 +0300 Subject: [PATCH 07/15] confirm action message --- assets/js/components/ConfirmActionBridge.js | 68 +++++++++++++++++---- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/assets/js/components/ConfirmActionBridge.js b/assets/js/components/ConfirmActionBridge.js index 8f22834..8e96378 100644 --- a/assets/js/components/ConfirmActionBridge.js +++ b/assets/js/components/ConfirmActionBridge.js @@ -1,9 +1,12 @@ import React from 'react'; import CommonModal from "../elements/CommonModal" import {Button } from 'react-bootstrap' +import ValueProcessor from '../utils/ValueProcessor'; + class ConfirmActionBridge extends React.Component { constructor(props) { super(props); + this.valueProcessor = new ValueProcessor; // this.state = { // confirmActionVisibility : true // } @@ -16,30 +19,71 @@ class ConfirmActionBridge extends React.Component { } getActionTitle() { + return 'Confirm action' + // let method = this.props.context.state.bridgeActionType; + // let res = 'Unknown Method'; + // if (this.props.context.allowedMethods.includes(method)) { + // if (method === 'connectWeb3Ext') + // res = 'Connect Web3 Extension'; + // else if (method === 'approveSrcTokenBalance') + // res = 'Approve Balance'; + // else if (method === 'lockEth' || method === 'encodeDataAndLock') + // res = 'Lock'; + // else if (method === 'claimEth' || method === 'reClaimEth' || method === 'claimInitEnq' || method === claimConfirmEnq) + // res = 'Claim'; + // } + // return res + } + + getActionDescription() { let method = this.props.context.state.bridgeActionType; let res = 'Unknown Method'; if (this.props.context.allowedMethods.includes(method)) { if (method === 'connectWeb3Ext') res = 'Connect Web3 Extension'; - else if (method === 'approveSrcTokenBalance') - res = 'Approve Balance'; - else if (method === 'lockEth' || method === 'encodeDataAndLock') - res = 'Lock'; - else if (method === 'claimEth' || method === 'reClaimEth' || method === 'claimInitEnq' || method === claimConfirmEnq) - res = 'Claim'; + else if (method === 'approveSrcTokenBalance') { + res = `Approve ${this.props.context.props.srcTokenTicker} balance`; + } else if (method === 'lockEth' || method === 'encodeDataAndLock') { + let ticker = this.props.context.props.srcTokenTicker ? this.props.context.props.srcTokenTicker : undefined; + let decimals = Number(this.props.context.props.srcTokenDecimals); + let amountBI = this.valueProcessor.valueToBigInt(this.props.context.props.srcTokenAmountToSend, decimals); + let amountFormatted; + if (Number(amountBI.fractionalPart) > 0) { + amountFormatted = this.valueProcessor.usCommasBigIntDecimals(amountBI.value, decimals, decimals).replace(/0*$/,""); + } else + amountFormatted = this.valueProcessor.usCommasBigIntDecimals(amountBI.value, decimals, 2) + + res = `Lock ${amountFormatted} ${ticker}`; + } else if (method === 'claimEth' || method === 'reClaimEth' || method === 'claimInitEnq' || method === 'claimConfirmEnq') { + let ticker = this.props.context.state.bridgeActionParams.lock.ticker || this.props.context.state.bridgeActionParams.bridgeItem.lock.ticker; + if (method === 'claimEth' || method === 'reClaimEth' || method === 'claimConfirmEnq') { + res = `Claim ${ticker} tokens`; + } else if (method === 'claimInitEnq') { + res = `Initialize claim ${ticker} tokens`; + } + } } return res } + executeAction() { + this.props.context[this.props.context.state.bridgeActionType](this.props.context.state.bridgeActionParams); + this.closeConfirmCard(); + } + renderModalBody() { return ( <> - + +
{this.getActionDescription()}
+
+ +
)//{ this.props.context.state.bridgeActionType } } From 322ae7b87b1876a583534e71894e38fc6668b3cf Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Thu, 24 Aug 2023 10:41:56 +0300 Subject: [PATCH 08/15] rescue via new history --- assets/js/components/RescueBridgeTxForm.js | 6 +++--- assets/js/utils/BridgeHistoryProcessor.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/assets/js/components/RescueBridgeTxForm.js b/assets/js/components/RescueBridgeTxForm.js index 45e9c01..a1254b2 100644 --- a/assets/js/components/RescueBridgeTxForm.js +++ b/assets/js/components/RescueBridgeTxForm.js @@ -70,7 +70,7 @@ class RescueBridgeTxForm extends React.Component { }; - let bridgeHistoryArray = that.bridgeHistoryProcessor.getBridgeHistoryArray(); + let bridgeHistoryArray = that.bridgeHistoryProcessor.getBridgeHistoryLocksArray(); if (bridgeHistoryArray.length > 0) { let itemIsExist = bridgeHistoryArray.find(function(elem) { if ((elem.initiator.toUpperCase().includes(ticket.src_address.toUpperCase()) || @@ -83,11 +83,11 @@ class RescueBridgeTxForm extends React.Component { return } else { console.log('addBridgeHistoryItem') - that.bridgeHistoryProcessor.addBridgeHistoryItem(accountInteractToBridgeItem); + localStorage.setItem(`bh_lock_${transactionHash}`, JSON.stringify(accountInteractToBridgeItem)); } } else { console.log('initiateHistoryStorage') - that.bridgeHistoryProcessor.initiateHistoryStorage(accountInteractToBridgeItem); + localStorage.setItem(`bh_lock_${transactionHash}`, JSON.stringify(accountInteractToBridgeItem)); } }, function(err) { console.log('Can\'t get notify response ', err); diff --git a/assets/js/utils/BridgeHistoryProcessor.js b/assets/js/utils/BridgeHistoryProcessor.js index e3d54d8..cb29745 100644 --- a/assets/js/utils/BridgeHistoryProcessor.js +++ b/assets/js/utils/BridgeHistoryProcessor.js @@ -13,6 +13,16 @@ class BridgeHistoryProcessor { return history } + getBridgeHistoryLocksArray() { + let locksArr = []; + for(let key in localStorage) { + if (key.includes('bh_lock_')) { + lockArr.push(JSON.parse(localStorage.getItem(key))) + } + } + return locksArr; + } + initiateHistoryStorage(item) { localStorage.setItem('bridge_history', JSON.stringify([item])); } From cc5ffac626517a954efe4df946f4f9e1a37028c0 Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Thu, 24 Aug 2023 10:57:36 +0300 Subject: [PATCH 09/15] fix get locks method --- assets/js/utils/BridgeHistoryProcessor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/utils/BridgeHistoryProcessor.js b/assets/js/utils/BridgeHistoryProcessor.js index cb29745..85d07e2 100644 --- a/assets/js/utils/BridgeHistoryProcessor.js +++ b/assets/js/utils/BridgeHistoryProcessor.js @@ -17,7 +17,7 @@ class BridgeHistoryProcessor { let locksArr = []; for(let key in localStorage) { if (key.includes('bh_lock_')) { - lockArr.push(JSON.parse(localStorage.getItem(key))) + locksArr.push(JSON.parse(localStorage.getItem(key))) } } return locksArr; From a12fce00382b2cf5b1a42a43a153cbeda26670e7 Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Thu, 24 Aug 2023 11:00:21 +0300 Subject: [PATCH 10/15] hide mumbai --- assets/js/config_test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/config_test.js b/assets/js/config_test.js index 619b03b..d980fc8 100644 --- a/assets/js/config_test.js +++ b/assets/js/config_test.js @@ -52,7 +52,7 @@ export const availableNetworks = [ explorerURL : 'https://testnet.bscscan.com', // url to explorer mainpage txPageUrl : 'https://testnet.bscscan.com/tx/' // url to tx page without tx hash }, - { + /* { id : 80001, // Number, hex ??? web3ExtensionChainId : '0x13881', //strig as in Metamask, undefined if not used, enqExtensionChainId : undefined, @@ -66,7 +66,7 @@ export const availableNetworks = [ logo : undefined, //image, undefined if not used explorerURL : 'https://mumbai.polygonscan.com', // url to explorer mainpage txPageUrl : 'https://mumbai.polygonscan.com/tx/' // url to tx page without tx hash - }, + },*/ { id : 11155111, // Number, hex ??? web3ExtensionChainId : '0xaa36a7', //strig as in Metamask, undefined if not used, From f9861da1a4a66e6d5ab4b161bdaf2c51c18edc84 Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Thu, 24 Aug 2023 12:27:45 +0300 Subject: [PATCH 11/15] bridge api test url --- assets/js/config_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/config_test.js b/assets/js/config_test.js index d980fc8..f6880cb 100644 --- a/assets/js/config_test.js +++ b/assets/js/config_test.js @@ -4,7 +4,7 @@ import spaceBridgeABI from './../ABI/abi_spaceBridge.json'; import wethABI from './../ABI/abi_weth.json'; export const maxEnqValue = BigInt('18446744073709551615'); //amount in cents -export const bridgeApiURL = 'https://bridge.enex.space/api/v1'; +export const bridgeApiURL = 'https://bridge-test.enex.space/api/v1'; export const availableNetworks = [ { From 8bcf6199308c4c1fafc9b265068d4d30628b3709 Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Thu, 24 Aug 2023 13:21:48 +0300 Subject: [PATCH 12/15] migrate to new history workflow --- assets/js/pages/SpaceBridge.js | 1 + assets/js/utils/BridgeHistoryProcessor.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/assets/js/pages/SpaceBridge.js b/assets/js/pages/SpaceBridge.js index 1b4dfeb..a9ee867 100644 --- a/assets/js/pages/SpaceBridge.js +++ b/assets/js/pages/SpaceBridge.js @@ -185,6 +185,7 @@ class SpaceBridge extends React.Component { } async updateUserHistory() { + this.bridgeHistoryProcessor.fragmentBridgeHistoryToSingleLocks(); let enqExtUserId = this.props.pubkey; let web3ExtUserId = this.props.nonNativeConnection.web3ExtensionAccountId; let userHistory = this.bridgeHistoryProcessor.getUserHistory(enqExtUserId, web3ExtUserId); diff --git a/assets/js/utils/BridgeHistoryProcessor.js b/assets/js/utils/BridgeHistoryProcessor.js index 85d07e2..693c2ff 100644 --- a/assets/js/utils/BridgeHistoryProcessor.js +++ b/assets/js/utils/BridgeHistoryProcessor.js @@ -3,6 +3,29 @@ class BridgeHistoryProcessor { } + fragmentBridgeHistoryToSingleLocks() { + let history = this.getBridgeHistoryArray(); + if (history.length > 0) { + let locksArr = this.getBridgeHistoryLocksArray(); + history.forEach(function(itemOfBridgeHistory, index, array) { + if (itemOfBridgeHistory.hasOwnProperty('lock') && itemOfBridgeHistory.lock?.transactionHash !== undefined) { + let txHash = itemOfBridgeHistory.lock.transactionHash; + let itemIsExistAsSingleLock = locksArr.find(function(singleLockItem) { + if (singleLockItem.lock?.transactionHash == txHash) + return true + }); + if (itemIsExistAsSingleLock !== undefined) { + return + } else { + localStorage.setItem(`bh_lock_${txHash}`, JSON.stringify(itemOfBridgeHistory)); + } + } + }); + localStorage.setItem('bridge_history_archive', JSON.stringify(history)); + localStorage.removeItem('bridge_history'); + } + } + getBridgeHistoryArray() { let history = []; let lsHistory = localStorage.getItem('bridge_history'); From 12007242fbb6837317b66bd6f238c63d6f4dbc18 Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Thu, 31 Aug 2023 12:08:00 +0300 Subject: [PATCH 13/15] fix get ticker for claims --- assets/js/components/ConfirmActionBridge.js | 2 +- assets/js/config_test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/components/ConfirmActionBridge.js b/assets/js/components/ConfirmActionBridge.js index 8e96378..36b7407 100644 --- a/assets/js/components/ConfirmActionBridge.js +++ b/assets/js/components/ConfirmActionBridge.js @@ -55,7 +55,7 @@ class ConfirmActionBridge extends React.Component { res = `Lock ${amountFormatted} ${ticker}`; } else if (method === 'claimEth' || method === 'reClaimEth' || method === 'claimInitEnq' || method === 'claimConfirmEnq') { - let ticker = this.props.context.state.bridgeActionParams.lock.ticker || this.props.context.state.bridgeActionParams.bridgeItem.lock.ticker; + let ticker = this.props.context.state.bridgeActionParams.lock?.ticker || this.props.context.state.bridgeActionParams.bridgeItem?.lock?.ticker; if (method === 'claimEth' || method === 'reClaimEth' || method === 'claimConfirmEnq') { res = `Claim ${ticker} tokens`; } else if (method === 'claimInitEnq') { diff --git a/assets/js/config_test.js b/assets/js/config_test.js index f6880cb..11732f2 100644 --- a/assets/js/config_test.js +++ b/assets/js/config_test.js @@ -80,7 +80,7 @@ export const availableNetworks = [ bridgeContractABI : spaceBridgeABI, //JSON, undefined if not used logo : undefined, //image, undefined if not used explorerURL : 'https://sepolia.etherscan.io/', // url to explorer mainpage - txPageUrl : 'https://sepolia.etherscan.io//tx/' // url to tx page without tx hash + txPageUrl : 'https://sepolia.etherscan.io/tx/' // url to tx page without tx hash } ] From facee8dd917e35808a441c31676057b6d327df02 Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Fri, 8 Sep 2023 10:47:03 +0300 Subject: [PATCH 14/15] set claim type for passDataToResetClaim method --- assets/js/pages/SpaceBridge.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/pages/SpaceBridge.js b/assets/js/pages/SpaceBridge.js index a9ee867..cb2beaa 100644 --- a/assets/js/pages/SpaceBridge.js +++ b/assets/js/pages/SpaceBridge.js @@ -703,7 +703,7 @@ class SpaceBridge extends React.Component { return if (bridgeActionParams.resetCurrent === true) - this.passDataToResetClaim(bridgeActionParams.bridgeItem, claimType); + this.passDataToResetClaim(bridgeActionParams.bridgeItem, 'claimInit'); extRequests.claimInit(pubkey, claimInitData).then(result => { console.log('Success', result.hash); @@ -746,7 +746,7 @@ class SpaceBridge extends React.Component { return if (bridgeActionParams.resetCurrent === true) - this.passDataToResetClaim(bridgeActionParams.item, claimType); + this.passDataToResetClaim(bridgeActionParams.item, 'claimConfirm'); extRequests.claimConfirm(pubkey, claimConfirmData).then(result => { console.log('Success', result.hash); From 26f1ef115e591a7b9f449cfb241970a0c4a79be1 Mon Sep 17 00:00:00 2001 From: "@djdfy" Date: Mon, 11 Sep 2023 14:00:04 +0300 Subject: [PATCH 15/15] avoid display multiple failed claims --- assets/js/pages/SpaceBridge.js | 114 ++++++++++++---------- assets/js/utils/BridgeHistoryProcessor.js | 82 ++++++++++++++-- 2 files changed, 137 insertions(+), 59 deletions(-) diff --git a/assets/js/pages/SpaceBridge.js b/assets/js/pages/SpaceBridge.js index cb2beaa..bb11482 100644 --- a/assets/js/pages/SpaceBridge.js +++ b/assets/js/pages/SpaceBridge.js @@ -247,82 +247,90 @@ class SpaceBridge extends React.Component { } } else if (elem.lock.status === true) { if (dstNetworkType === 'eth') { - if (elem.claimTxHash !== undefined && !elem.hasOwnProperty('claimTxStatus') && that.props.nonNativeConnection.web3Extension?.provider) { + if (elem.claimTxHash == undefined && !elem.hasOwnProperty('claimTxStatus') && that.props.nonNativeConnection.web3Extension?.provider) { let dataProvider = that.props.nonNativeConnection.web3Extension.provider; let web3Provider = new web3LibProvider(dataProvider); - web3Provider.getTxReceipt(elem.claimTxHash, 'Claim').then(function(res) { - if (res !== null && res !== undefined && res.status !== undefined) { - if (Number(res.status) === 1) - elem.claimTxStatus = true; - else if (Number(res.status) === 0) - elem.claimTxStatus = false; - //elem.claimTxStatus = Number(res.status) === 1 ? true : false; - localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); - //localStorage.setItem('bridge_history', JSON.stringify(array)); - that.setState({history: array}); - } else { - console.log('Undefined claim transaction status', elem.lock.transactionHash); + console.log(elem.claimEthStorage) + elem.claimEthStorage.forEach(function(claim, claimIndex, claimArray) { + let lsClaimEth = that.bridgeHistoryProcessor.getBridgeHistoryItem(`bh_claim_eth_${claim}`); + if (lsClaimEth !== undefined && lsClaimEth.claimTxStatus == undefined) { + web3Provider.getTxReceipt(lsClaimEth.claimTxHash, 'Claim').then(function(res) { + if (res !== null && res !== undefined && res.status !== undefined) { + if (Number(res.status) === 1) + lsClaimEth.claimTxStatus = true; + else if (Number(res.status) === 0) + lsClaimEth.claimTxStatus = false; + + localStorage.setItem(`bh_claim_eth_${claim}`, JSON.stringify(lsClaimEth)); + } else { + console.log('Undefined claim transaction status', claim); + } + }, function(err) { + console.log('Can\'t get receipt for claim transaction', claim, err); + }); } - }, function(err) { - console.log('Can\'t get receipt for claim transaction', elem.claimTxHash, err); }); } } - if (elem.claimInitTxHash !== undefined && elem.claimInitTxStatus === undefined) { + if (elem.claimInitTxHash == undefined && elem.claimInitTxStatus === undefined) { if (dstNetworkType === 'enq') { let net = that.availableNetworksUtils.getChainById(Number(elem.lock.dst_network)); let url = net !== undefined ? net.explorerURL : undefined; - if (url !== undefined) { - networkApi.getTx(url, elem.claimInitTxHash).then(function(res) { - if (res !== null && !res.lock) { - res.json().then(tx => { - if (tx.status !== undefined) { - if (tx.status === 3) - elem.claimInitTxStatus = true; - else if (tx.status === 2) - elem.claimInitTxStatus = false; - - localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); - //localStorage.setItem('bridge_history', JSON.stringify(array)); - that.setState({history: array}); + if (url !== undefined) { + elem.claimInitENQStorage.forEach(function(claim, claimIndex, claimArray){ + let lsClaimInitENQ = that.bridgeHistoryProcessor.getBridgeHistoryItem(`bh_claim_init_enq_${claim}`); + if (lsClaimInitENQ !== undefined && lsClaimInitENQ.claimInitTxStatus == undefined) { + networkApi.getTx(url, lsClaimInitENQ.claimInitTxHash).then(function(res) { + if (res !== null && !res.lock) { + res.json().then(tx => { + if (tx.status !== undefined) { + if (tx.status === 3) + lsClaimInitENQ.claimInitTxStatus = true; + else if (tx.status === 2) + lsClaimInitENQ.claimInitTxStatus = false; + + localStorage.setItem(`bh_claim_init_enq_${claim}`, JSON.stringify(lsClaimInitENQ)); + } + }, function(err) { + console.log('Can\'t get status for Claim Init transaction', claim, err); + }); } }, function(err) { - console.log('Can\'t get status for Claim Init transaction', elem.claimInitTxHash, err); + console.log('Can\'t get data for Claim init transaction', claim, err); }); } - }, function(err) { - console.log('Can\'t get data for Claim init transaction', elem.claimInitTxHash, err); - }); + }); } } } - if (elem.claimConfirmTxHash !== undefined && elem.claimConfirmTxStatus === undefined) { + if (elem.claimConfirmTxHash == undefined && elem.claimConfirmTxStatus === undefined) { if (dstNetworkType === 'enq') { let net = that.availableNetworksUtils.getChainById(Number(elem.lock.dst_network)); let url = net !== undefined ? net.explorerURL : undefined; - if (url !== undefined) { - networkApi.getTx(url, elem.claimConfirmTxHash).then(function(res) { - if (res !== null && !res.lock) { - res.json().then(tx => { - if (tx.status !== undefined) { - if (tx.status === 3) - elem.claimConfirmTxStatus = true; - else if (tx.status === 2) - elem.claimConfirmTxStatus = false; - - localStorage.setItem(`bh_lock_${elem.lock.transactionHash}`, JSON.stringify(elem)); - //localStorage.setItem('bridge_history', JSON.stringify(array)); - that.setState({history: array}); - } else { - console.log('Undefined claim confirm transaction status', elem.lock.transactionHash); + if (url !== undefined) { + elem.claimConfirmENQStorage.forEach(function(claim, claimIndex, claimArray){ + let lsClaimConfirmENQ = that.bridgeHistoryProcessor.getBridgeHistoryItem(`bh_claim_confirm_enq_${claim}`); + if (lsClaimConfirmENQ !== undefined && lsClaimConfirmENQ.claimConfirmTxStatus == undefined) { + networkApi.getTx(url, lsClaimConfirmENQ.claimConfirmTxHash).then(function(res) { + if (res !== null && !res.lock) { + res.json().then(tx => { + if (tx.status !== undefined) { + if (tx.status === 3) + lsClaimConfirmENQ.claimConfirmTxStatus = true; + else if (tx.status === 2) + lsClaimConfirmENQ.claimConfirmTxStatus = false; + + localStorage.setItem(`bh_claim_confirm_enq_${claim}`, JSON.stringify(lsClaimConfirmENQ)); + } + }, function(err) { + console.log('Can\'t get status for Claim Confirm transaction', claim, err); + }); } }, function(err) { - console.log('Can\'t get status for claim confirm transaction', elem.claimConfirmTxHash); + console.log('Can\'t get data for Claim Confirm transaction', claim, err); }); } - }, function(err) { - console.log('Can\'t get data for Claim Confirm transaction', elem.claimConfirmTxHash); - }); + }); } } } diff --git a/assets/js/utils/BridgeHistoryProcessor.js b/assets/js/utils/BridgeHistoryProcessor.js index 693c2ff..bb9292e 100644 --- a/assets/js/utils/BridgeHistoryProcessor.js +++ b/assets/js/utils/BridgeHistoryProcessor.js @@ -36,6 +36,16 @@ class BridgeHistoryProcessor { return history } + getBridgeHistoryItem(itemKey) { + let item = undefined; + let lsItem = localStorage.getItem(itemKey); + if (lsItem !== undefined && lsItem !== null && (typeof lsItem === 'string')) { + let parsedItem = JSON.parse(lsItem); + item = parsedItem; + } + return item + } + getBridgeHistoryLocksArray() { let locksArr = []; for(let key in localStorage) { @@ -120,33 +130,93 @@ class BridgeHistoryProcessor { userHistory = lockArr; lockArr.forEach(function(lock, lockIndex, lockArray){ + lock.claimEthStorage = []; + lock.claimInitENQStorage = []; + lock.claimConfirmENQStorage = []; + + let claimEthFailCounter = 0; + let claimInitENQFailCounter = 0; + let claimConfirmENQFailCounter = 0; + let claimEthLastFailTx = undefined; + let claimInitENQLastFailTx = undefined; + let claimConfirmENQLastFailTx = undefined; + claimEthArr.forEach(function(claim, claimIndex, claimArray){ if (lock.hasOwnProperty('validatorRes') && lock.validatorRes?.ticket_hash !== undefined && claim.hasOwnProperty('validatorRes') && claim.validatorRes?.ticket_hash !== undefined && + lock.lock.status === true && lock.validatorRes.ticket_hash === claim.validatorRes.ticket_hash) { - lock.claimTxHash = claim.claimTxHash; - lock.claimTxTimestamp = claim.claimTxTimestamp; + if (claim.hasOwnProperty('claimTxStatus') && claim.claimTxStatus === true) { + lock.claimTxHash = claim.claimTxHash; + lock.claimTxStatus = true; + lock.claimTxTimestamp = claim.claimTxTimestamp; + } else if (claim.hasOwnProperty('claimTxStatus') && claim.claimTxStatus === false) { + claimEthFailCounter++; + claimEthLastFailTx = claim; + } + // lock.claimTxHash = claim.claimTxHash; + // lock.claimTxTimestamp = claim.claimTxTimestamp; + lock.claimEthStorage.push(claim.claimTxHash); localStorage.setItem(`bh_lock_${lock.lock.transactionHash}`, JSON.stringify(lock)); } }); + if (claimEthFailCounter > 0 && claimEthFailCounter === lock.claimEthStorage.length) { + lock.claimTxHash = claimEthLastFailTx.claimTxHash; + lock.claimTxStatus = false; + lock.claimTxTimestamp = claimEthLastFailTx.claimTxTimestamp; + } + claimInitENQArr.forEach(function(claim, claimIndex, claimArray){ if (lock.hasOwnProperty('validatorRes') && lock.validatorRes?.ticket_hash !== undefined && claim.hasOwnProperty('validatorRes') && claim.validatorRes?.ticket_hash !== undefined && + lock.lock.status === true && lock.validatorRes.ticket_hash === claim.validatorRes.ticket_hash) { - lock.claimInitTxHash = claim.claimInitTxHash; - lock.claimInitTxTimestamp = claim.claimInitTxTimestamp; + if (claim.hasOwnProperty('claimInitTxStatus') && claim.claimInitTxStatus === true) { + lock.claimInitTxHash = claim.claimInitTxHash; + lock.claimInitTxStatus = true; + lock.claimInitTxTimestamp = claim.claimInitTxTimestamp; + } else if (claim.hasOwnProperty('claimInitTxStatus') && claim.claimInitTxStatus === false) { + claimInitENQFailCounter++; + claimInitENQLastFailTx = claim; + } + // lock.claimInitTxHash = claim.claimInitTxHash; + // lock.claimInitTxTimestamp = claim.claimInitTxTimestamp; + lock.claimInitENQStorage.push(claim.claimInitTxHash); localStorage.setItem(`bh_lock_${lock.lock.transactionHash}`, JSON.stringify(lock)); } }); + if (claimInitENQFailCounter > 0 && claimInitENQFailCounter === lock.claimInitENQStorage.length) { + lock.claimInitTxHash = claimInitENQLastFailTx.claimInitTxHash; + lock.claimInitTxStatus = false; + lock.claimInitTxTimestamp = claimInitENQLastFailTx.claimInitTxTimestamp; + } + + claimConfirmENQArr.forEach(function(claim, claimIndex, claimArray){ if (lock.hasOwnProperty('validatorRes') && lock.validatorRes?.ticket_hash !== undefined && claim.hasOwnProperty('validatorRes') && claim.validatorRes?.ticket_hash !== undefined && + lock.lock.status === true && lock.validatorRes.ticket_hash === claim.validatorRes.ticket_hash) { - lock.claimConfirmTxHash = claim.claimConfirmTxHash; - lock.claimConfirmTxTimestamp = claim.claimConfirmTxTimestamp; + if (claim.hasOwnProperty('claimConfirmTxStatus') && claim.claimConfirmTxStatus === true) { + lock.claimConfirmTxHash = claim.claimConfirmTxHash; + lock.claimConfirmTxStatus = true; + lock.claimConfirmTxTimestamp = claim.claimConfirmTxTimestamp; + } else if (claim.hasOwnProperty('claimConfirmTxStatus') && claim.claimConfirmTxStatus === false) { + claimConfirmENQFailCounter++; + claimConfirmENQLastFailTx = claim; + } + // lock.claimConfirmTxHash = claim.claimConfirmTxHash; + // lock.claimConfirmTxTimestamp = claim.claimConfirmTxTimestamp; + lock.claimConfirmENQStorage.push(claim.claimConfirmTxHash); localStorage.setItem(`bh_lock_${lock.lock.transactionHash}`, JSON.stringify(lock)); } }); + if (claimConfirmENQFailCounter > 0 && claimConfirmENQFailCounter === lock.claimConfirmENQStorage.length) { + lock.claimConfirmTxHash = claimConfirmENQLastFailTx.claimConfirmTxHash; + lock.claimConfirmTxStatus = false; + lock.claimConfirmTxTimestamp = claimConfirmENQLastFailTx.claimConfirmTxTimestamp; + } + localStorage.setItem(`bh_lock_${lock.lock.transactionHash}`, JSON.stringify(lock)); }); userHistory = lockArr; } else {