Skip to content

Commit

Permalink
avoid display multiple failed claims
Browse files Browse the repository at this point in the history
  • Loading branch information
@djdfy committed Sep 11, 2023
1 parent facee8d commit 26f1ef1
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 59 deletions.
114 changes: 61 additions & 53 deletions assets/js/pages/SpaceBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}
}
}
Expand Down
82 changes: 76 additions & 6 deletions assets/js/utils/BridgeHistoryProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 26f1ef1

Please sign in to comment.