diff --git a/src/app/components/HwWallet/Connect.js b/src/app/components/HwWallet/Connect.js index d8b0eb14..f8b26528 100755 --- a/src/app/components/HwWallet/Connect.js +++ b/src/app/components/HwWallet/Connect.js @@ -88,8 +88,9 @@ class Connect extends Component { if (res && Object.keys(res).length) { let addresses = this.state.addresses; addresses.forEach(item => { - if (Object.keys(res).includes(item.address)) { - item.balance = res[item.address]; + let found = Object.keys(res).find(addr => addr.toLowerCase() === item.address.toLowerCase()); + if (found !== undefined) { + item.balance = res[found]; } }) this.setState({ diff --git a/src/app/stores/btcAddress.js b/src/app/stores/btcAddress.js index b0128fad..36886edd 100644 --- a/src/app/stores/btcAddress.js +++ b/src/app/stores/btcAddress.js @@ -36,11 +36,11 @@ class BtcAddress { self.utxos = newUtxos; } - @action setCurrPage (page) { + @action setCurrPage(page) { self.currentPage = page; } - @action addAddress (newAddr) { + @action addAddress(newAddr) { self.addrInfo.normal[newAddr.address] = { name: newAddr.name ? newAddr.name : `BTC-Account${Number(newAddr.start) + 1}`, address: newAddr.address, @@ -54,7 +54,7 @@ class BtcAddress { this.updateTransHistory(); } - @action updateAddress (type, newAddress = {}) { + @action updateAddress(type, newAddress = {}) { if (typeof type === 'string') { self.addrInfo[type] = newAddress; } else { @@ -62,7 +62,7 @@ class BtcAddress { } } - @action addAddresses (type, addrArr) { + @action addAddresses(type, addrArr) { addrArr.forEach(addr => { if (!Object.keys(self.addrInfo[type]).includes(addr.address)) { if (addr.name === undefined) { @@ -99,7 +99,7 @@ class BtcAddress { }) } - @action setSelectedAddr (addr) { + @action setSelectedAddr(addr) { if (typeof addr === 'string') { self.selectedAddr = [addr]; } else { @@ -107,7 +107,7 @@ class BtcAddress { } } - @action updateBTCBalance (arr) { + @action updateBTCBalance(arr) { let keys = Object.keys(arr); let normal = Object.keys(self.addrInfo.normal); let rawKey = Object.keys(self.addrInfo['rawKey']); @@ -121,7 +121,7 @@ class BtcAddress { }) } - @action updateName (arr, wid) { + @action updateName(arr, wid) { let type = getTypeByWalletId(wid); wand.request('account_update', { walletID: wid, path: arr.path, meta: { name: arr.name, addr: arr.address } }, (err, val) => { if (!err && val) { @@ -130,7 +130,7 @@ class BtcAddress { }) } - @action getUserAccountFromDB (chainId) { + @action getUserAccountFromDB(chainId) { let chainID = chainId === CHAINID.MAIN ? BTCCHAINID.MAIN : BTCCHAINID.TEST; wand.request('account_getAll', { chainID }, (err, ret) => { if (err) console.log('Get user from DB failed ', err); @@ -172,7 +172,7 @@ class BtcAddress { }; } - @computed get getAddrList () { + @computed get getAddrList() { let addrList = []; let normalArr = self.addrInfo['normal']; let rawKeyArr = self.addrInfo['rawKey']; @@ -200,7 +200,7 @@ class BtcAddress { }); } - @computed get getNormalAddrList () { + @computed get getNormalAddrList() { let addrList = []; let normalArr = Object.keys(self.addrInfo.normal); normalArr.forEach(item => { @@ -219,26 +219,30 @@ class BtcAddress { } @computed get historyList() { - let historyList = []; - // console.log('his:', JSON.parse(JSON.stringify(self.transHistory))); - Object.keys(self.transHistory).forEach(item => { - let data = self.transHistory[item]; - let status = data.status; - if (data.crossAddress === undefined) { - historyList.push({ - key: item, - time: timeFormat(data.sendTime), - to: data.to, - value: formatNum(data.value), - status: languageIntl.language && ['Failed', 'Success'].includes(status) ? intl.get(`TransHistory.${status.toLowerCase()}`) : intl.get('TransHistory.pending'), - sendTime: data.sendTime, - }); - } - }); - return historyList.sort((a, b) => b.sendTime - a.sendTime); + try { + let historyList = []; + Object.keys(self.transHistory).forEach(item => { + let data = self.transHistory[item]; + let status = data.status; + if (data.crossAddress === undefined) { + historyList.push({ + key: item, + time: timeFormat(data.sendTime), + to: data.to, + value: formatNum(data.value), + status: languageIntl.language && ['Failed', 'Success'].includes(status) ? intl.get(`TransHistory.${status.toLowerCase()}`) : intl.get('TransHistory.pending'), + sendTime: data.sendTime, + }); + } + }); + return historyList.sort((a, b) => b.sendTime - a.sendTime); + } catch (e) { + console.log('get history list failed:', e); + return []; + } } - @computed get addrSelectedList () { + @computed get addrSelectedList() { let addrList = [] Object.keys(self.addrInfo.normal).forEach(addr => { addrList.push(addr); @@ -246,13 +250,13 @@ class BtcAddress { return addrList; } - @computed get getNormalAmount () { + @computed get getNormalAmount() { let sum = 0; Object.values({ normal: self.addrInfo.normal }).forEach(value => { sum = new BigNumber(sum).plus(Object.values(value).reduce((prev, curr) => new BigNumber(prev).plus(curr.balance), 0)) }); return sum.toString(); } - @computed get getAllAmount () { + @computed get getAllAmount() { let sum = 0; Object.values(self.addrInfo).forEach(value => { sum = new BigNumber(sum).plus(Object.values(value).reduce((prev, curr) => new BigNumber(prev).plus(curr.balance), 0)) }); return sum.toString(); diff --git a/src/app/stores/eosAddress.js b/src/app/stores/eosAddress.js index 8948e319..0d6ae63e 100644 --- a/src/app/stores/eosAddress.js +++ b/src/app/stores/eosAddress.js @@ -245,88 +245,98 @@ class EosAddress { } @computed get normalHistoryList() { - let historyList = []; - Object.keys(self.transHistory).forEach(item => { - let obj = self.transHistory[item]; - if (!obj.action) { - if (!self.historySelectedAccountName || self.historySelectedAccountName === obj['from']) { - let status = obj.status; - let value = `0`; - if (obj['value']) { - value = new BigNumber(obj['value'].replace(/ EOS/, '')).toString(); + try { + let historyList = []; + Object.keys(self.transHistory).forEach(item => { + let obj = self.transHistory[item]; + if (!obj.action) { + if (!self.historySelectedAccountName || self.historySelectedAccountName === obj['from']) { + let status = obj.status; + let value = `0`; + if (obj['value']) { + value = new BigNumber(obj['value'].replace(/ EOS/, '')).toString(); + } + historyList.push({ + key: item, + time: timeFormat(obj['sendTime']), + from: obj['from'], + to: obj['to'], + value: `${value} EOS`, + status: languageIntl.language && ['Failed', 'Success'].includes(status) ? intl.get(`TransHistory.${status.toLowerCase()}`) : intl.get('TransHistory.pending'), + sendTime: obj['sendTime'], + txHash: obj['txHash'] + }); } - historyList.push({ - key: item, - time: timeFormat(obj['sendTime']), - from: obj['from'], - to: obj['to'], - value: `${value} EOS`, - status: languageIntl.language && ['Failed', 'Success'].includes(status) ? intl.get(`TransHistory.${status.toLowerCase()}`) : intl.get('TransHistory.pending'), - sendTime: obj['sendTime'], - txHash: obj['txHash'] - }); } - } - }); - return historyList.sort((a, b) => b.sendTime - a.sendTime); + }); + return historyList.sort((a, b) => b.sendTime - a.sendTime); + } catch (e) { + console.log('get history list failed:', e); + return []; + } } @computed get resourceHistoryList() { - let historyList = []; - Object.keys(self.transHistory).forEach(item => { - let obj = self.transHistory[item]; - if (obj.action) { - if (!self.historySelectedAccountName || self.historySelectedAccountName === obj['from']) { - let status = obj.status; - let value = ''; - switch (obj['action']) { - case 'buyrambytes': - value = `${obj['ramBytes']} KB`; - break; - case 'sellram': - value = `${obj['ramBytes']} KB`; - break; - case 'newaccount': - let ram = obj['ramBytes']; - let cpu = obj['cpuAmount']; - let net = obj['netAmount']; - value = `${ram}KB/ ${Number(cpu.replace(/ EOS/, ''))}EOS/ ${Number(net.replace(/ EOS/, ''))}EOS`; - break; - case 'delegatebw': - if (obj['cpuAmount'] === '0.0000 EOS') { - value = `${obj['netAmount']}`; - } else { - value = `${obj['cpuAmount']}`; - } - break; - case 'undelegatebw': - if (obj['cpuAmount'] === '0.0000 EOS') { - value = `${obj['netAmount']}`; - } else { - value = `${obj['cpuAmount']}`; - } - break; - default: - value = obj['value']; - } - if (value.indexOf(' EOS') !== -1) { + try { + let historyList = []; + Object.keys(self.transHistory).forEach(item => { + let obj = self.transHistory[item]; + if (obj.action) { + if (!self.historySelectedAccountName || self.historySelectedAccountName === obj['from']) { + let status = obj.status; + let value = ''; + switch (obj['action']) { + case 'buyrambytes': + value = `${obj['ramBytes']} KB`; + break; + case 'sellram': + value = `${obj['ramBytes']} KB`; + break; + case 'newaccount': + let ram = obj['ramBytes']; + let cpu = obj['cpuAmount']; + let net = obj['netAmount']; + value = `${ram}KB/ ${Number(cpu.replace(/ EOS/, ''))}EOS/ ${Number(net.replace(/ EOS/, ''))}EOS`; + break; + case 'delegatebw': + if (obj['cpuAmount'] === '0.0000 EOS') { + value = `${obj['netAmount']}`; + } else { + value = `${obj['cpuAmount']}`; + } + break; + case 'undelegatebw': + if (obj['cpuAmount'] === '0.0000 EOS') { + value = `${obj['netAmount']}`; + } else { + value = `${obj['cpuAmount']}`; + } + break; + default: + value = obj['value']; + } + if (value.indexOf(' EOS') !== -1) { value = `${new BigNumber(value.replace(/ EOS/, '')).toString()} EOS` + } + historyList.push({ + key: item, + time: timeFormat(obj['sendTime']), + from: obj['from'], + to: obj['to'], + value: value, + status: languageIntl.language && ['Failed', 'Success'].includes(status) ? intl.get(`TransHistory.${status.toLowerCase()}`) : intl.get('TransHistory.pending'), + sendTime: obj['sendTime'], + action: obj['action'], + txHash: obj['txHash'] + }); } - historyList.push({ - key: item, - time: timeFormat(obj['sendTime']), - from: obj['from'], - to: obj['to'], - value: value, - status: languageIntl.language && ['Failed', 'Success'].includes(status) ? intl.get(`TransHistory.${status.toLowerCase()}`) : intl.get('TransHistory.pending'), - sendTime: obj['sendTime'], - action: obj['action'], - txHash: obj['txHash'] - }); } - } - }); - return historyList.sort((a, b) => b.sendTime - a.sendTime); + }); + return historyList.sort((a, b) => b.sendTime - a.sendTime); + } catch (e) { + console.log('get history list failed:', e); + return []; + } } } diff --git a/src/app/stores/ethAddress.js b/src/app/stores/ethAddress.js index 148d7957..1e45e0e4 100644 --- a/src/app/stores/ethAddress.js +++ b/src/app/stores/ethAddress.js @@ -207,32 +207,37 @@ class EthAddress { } @computed get historyList() { - let historyList = []; - let page = self.currentPage; - let addrList = []; - if (self.selectedAddr) { - addrList = self.selectedAddr - } else { - page.forEach(name => { - addrList = addrList.concat(Object.keys(self.addrInfo[name])) - }) - } - Object.keys(self.transHistory).forEach(item => { - if (addrList.includes(self.transHistory[item].from) && !('transferTo' in self.transHistory[item])) { - let status = self.transHistory[item].status; - let type = checkAddrType(self.transHistory[item].from, self.addrInfo) - historyList.push({ - key: item, - time: timeFormat(self.transHistory[item].sendTime), - from: self.addrInfo[type][self.transHistory[item].from].name, - to: self.transHistory[item].to.toLowerCase(), - value: formatNum(fromWei(self.transHistory[item].value)), - status: languageIntl.language && ['Failed', 'Success'].includes(status) ? intl.get(`TransHistory.${status.toLowerCase()}`) : intl.get('TransHistory.pending'), - sendTime: self.transHistory[item].sendTime, - }); + try { + let historyList = []; + let page = self.currentPage; + let addrList = []; + if (self.selectedAddr) { + addrList = self.selectedAddr + } else { + page.forEach(name => { + addrList = addrList.concat(Object.keys(self.addrInfo[name] || {})); + }) } - }); - return historyList.sort((a, b) => b.sendTime - a.sendTime); + Object.keys(self.transHistory).forEach(item => { + if (addrList.includes(self.transHistory[item].from) && !('transferTo' in self.transHistory[item])) { + let status = self.transHistory[item].status; + let type = checkAddrType(self.transHistory[item].from, self.addrInfo) + historyList.push({ + key: item, + time: timeFormat(self.transHistory[item].sendTime), + from: self.addrInfo[type][self.transHistory[item].from].name, + to: self.transHistory[item].to.toLowerCase(), + value: formatNum(fromWei(self.transHistory[item].value)), + status: languageIntl.language && ['Failed', 'Success'].includes(status) ? intl.get(`TransHistory.${status.toLowerCase()}`) : intl.get('TransHistory.pending'), + sendTime: self.transHistory[item].sendTime, + }); + } + }); + return historyList.sort((a, b) => b.sendTime - a.sendTime); + } catch (e) { + console.log('get history list failed:', e); + return []; + } } @computed get tokenTransferHistoryList() { diff --git a/src/app/stores/wanAddress.js b/src/app/stores/wanAddress.js index 2927f06f..4cd3d9ea 100644 --- a/src/app/stores/wanAddress.js +++ b/src/app/stores/wanAddress.js @@ -464,34 +464,39 @@ class WanAddress { } @computed get historyList() { - let historyList = []; - let page = self.currentPage; - let addrList = []; - if (self.selectedAddr) { - addrList = self.selectedAddr - } else { - page.forEach(name => { - addrList = addrList.concat(Object.keys(self.addrInfo[name])) - }) - } - Object.keys(self.transHistory).forEach(item => { - let data = self.transHistory[item]; - if (addrList.includes(data['from']) && !('transferTo' in data)) { - let status = data.status; - let type = checkAddrType(data['from'], self.addrInfo); - historyList.push({ - key: item, - time: timeFormat(data['sendTime']), - from: self.addrInfo[type][data['from']].name, - to: wanUtil.toChecksumAddress(data.to.toLowerCase()), - value: formatNum(fromWei(data.value)), - status: languageIntl.language && ['Failed', 'Success'].includes(status) ? intl.get(`TransHistory.${status.toLowerCase()}`) : intl.get('TransHistory.pending'), - sendTime: data['sendTime'], - offline: !!item.offline - }); + try { + let historyList = []; + let page = self.currentPage; + let addrList = []; + if (self.selectedAddr) { + addrList = self.selectedAddr + } else { + page.forEach(name => { + addrList = addrList.concat(Object.keys(self.addrInfo[name] || {})); + }) } - }); - return historyList.sort((a, b) => b.sendTime - a.sendTime); + Object.keys(self.transHistory).forEach(item => { + let data = self.transHistory[item]; + if (addrList.includes(data['from']) && !('transferTo' in data)) { + let status = data.status; + let type = checkAddrType(data['from'], self.addrInfo); + historyList.push({ + key: item, + time: timeFormat(data['sendTime']), + from: self.addrInfo[type][data['from']].name, + to: wanUtil.toChecksumAddress(data.to.toLowerCase()), + value: formatNum(fromWei(data.value)), + status: languageIntl.language && ['Failed', 'Success'].includes(status) ? intl.get(`TransHistory.${status.toLowerCase()}`) : intl.get('TransHistory.pending'), + sendTime: data['sendTime'], + offline: !!item.offline + }); + } + }); + return historyList.sort((a, b) => b.sendTime - a.sendTime); + } catch (e) { + console.log('get history list failed:', e); + return []; + } } @computed get privateHistoryList() { diff --git a/src/app/stores/xrpAddress.js b/src/app/stores/xrpAddress.js index 7c535c9a..5f1acdc5 100644 --- a/src/app/stores/xrpAddress.js +++ b/src/app/stores/xrpAddress.js @@ -88,23 +88,28 @@ class XrpAddress { } get historyList() { - let historyList = []; - Object.keys(self.transHistory).forEach(item => { - let data = self.transHistory[item]; - let { status, from, successTime, sendTime, value, to } = data; - if (Object.values(self.addrInfo).find(item => Object.keys(item).includes(from))) { - historyList.push({ - from, - key: item, - time: timeFormat((successTime || sendTime)), - to: to, - value: formatNum(value), - status: languageIntl.language && ['Failed', 'Success'].includes(status) ? intl.get(`TransHistory.${status.toLowerCase()}`) : intl.get('TransHistory.pending'), - sendTime: sendTime, - }); - } - }); - return historyList.sort((a, b) => b.sendTime - a.sendTime); + try { + let historyList = []; + Object.keys(self.transHistory).forEach(item => { + let data = self.transHistory[item]; + let { status, from, successTime, sendTime, value, to } = data; + if (Object.values(self.addrInfo).find(item => Object.keys(item).includes(from))) { + historyList.push({ + from, + key: item, + time: timeFormat((successTime || sendTime)), + to: to, + value: formatNum(value), + status: languageIntl.language && ['Failed', 'Success'].includes(status) ? intl.get(`TransHistory.${status.toLowerCase()}`) : intl.get('TransHistory.pending'), + sendTime: sendTime, + }); + } + }); + return historyList.sort((a, b) => b.sendTime - a.sendTime); + } catch (e) { + console.log('get history list failed:', e); + return []; + } } addAddress(newAddr) {