Skip to content

Commit

Permalink
Merge pull request #27 from Enecuum/avoid-double-clicks
Browse files Browse the repository at this point in the history
Avoid double clicks
  • Loading branch information
djdfy authored Sep 15, 2023
2 parents 5078a43 + fb6122d commit ad414ae
Show file tree
Hide file tree
Showing 9 changed files with 562 additions and 172 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public/*
!public/favicon-32x32.png
!public/tokenList.js
package-lock.json
.idea
.idea
assets/js/config.js
107 changes: 107 additions & 0 deletions assets/js/components/ConfirmActionBridge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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
// }
}

renderModalHeader() {
let action = 'Unknown action';

return 'Action'
}

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 ${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 (
<>

<div className="text-center h5">{this.getActionDescription()}</div>
<div>
<Button
className='btn-secondary mx-auto mt-5 d-block button-bg-3'
onClick={this.executeAction.bind(this)}
>
Confirm
</Button>
</div>
</>
)//{ this.props.context.state.bridgeActionType }
}

closeConfirmCard () {
this.props.context.setState({showBridgeActionConfirmModal : false});
}

render () {
return(
<>
{this.props.context.state.showBridgeActionConfirmModal && <CommonModal
renderHeader={this.getActionTitle.bind(this)}
renderBody={this.renderModalBody.bind(this)}
closeAction={this.closeConfirmCard.bind(this)}/>}
</>
)
}
}

export default ConfirmActionBridge;
6 changes: 3 additions & 3 deletions assets/js/components/RescueBridgeTxForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) ||
Expand All @@ -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);
Expand Down
23 changes: 10 additions & 13 deletions assets/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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-test.enex.space/api/v1';

export const availableNetworks = [
{
Expand Down Expand Up @@ -48,28 +45,28 @@ 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
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,
name : 'Mumbai', //string
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
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,
Expand All @@ -78,12 +75,12 @@ 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
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
}
]

Expand Down
5 changes: 1 addition & 4 deletions assets/js/config_prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down
62 changes: 37 additions & 25 deletions assets/js/contracts-providers/spaceBridgeProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : {
Expand All @@ -33,21 +33,25 @@ class SpaceBridgeProvider {
timestamp : Date.now()
}
};

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 (itemIsExist !== undefined)
return
else
that.bridgeHistoryProcessor.addBridgeHistoryItem(accountInteractToBridgeItem);
} else {
that.bridgeHistoryProcessor.initiateHistoryStorage(accountInteractToBridgeItem);
localStorage.setItem(`bh_lock_${txHash}`, JSON.stringify(accountInteractToBridgeItem));
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)
// return true
// });

// if (itemIsExist !== undefined)
// return
// else {
// that.bridgeHistoryProcessor.addBridgeHistoryItem(accountInteractToBridgeItem);
// }
// } else {
// that.bridgeHistoryProcessor.initiateHistoryStorage(accountInteractToBridgeItem);
// }
}
});

Expand Down Expand Up @@ -76,22 +80,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);
Expand Down
Loading

0 comments on commit ad414ae

Please sign in to comment.