Skip to content

Commit

Permalink
Merge branch '1.5-dev' into 1.5-release
Browse files Browse the repository at this point in the history
  • Loading branch information
ZaneCQ committed Feb 25, 2021
2 parents 0fba70f + 7a41a13 commit 53dfdd4
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 175 deletions.
5 changes: 3 additions & 2 deletions src/app/components/HwWallet/Connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
64 changes: 34 additions & 30 deletions src/app/stores/btcAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -54,15 +54,15 @@ class BtcAddress {
this.updateTransHistory();
}

@action updateAddress (type, newAddress = {}) {
@action updateAddress(type, newAddress = {}) {
if (typeof type === 'string') {
self.addrInfo[type] = newAddress;
} else {
type.forEach(item => { self.addrInfo[item] = newAddress })
}
}

@action addAddresses (type, addrArr) {
@action addAddresses(type, addrArr) {
addrArr.forEach(addr => {
if (!Object.keys(self.addrInfo[type]).includes(addr.address)) {
if (addr.name === undefined) {
Expand Down Expand Up @@ -99,15 +99,15 @@ class BtcAddress {
})
}

@action setSelectedAddr (addr) {
@action setSelectedAddr(addr) {
if (typeof addr === 'string') {
self.selectedAddr = [addr];
} else {
self.selectedAddr = addr;
}
}

@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']);
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -172,7 +172,7 @@ class BtcAddress {
};
}

@computed get getAddrList () {
@computed get getAddrList() {
let addrList = [];
let normalArr = self.addrInfo['normal'];
let rawKeyArr = self.addrInfo['rawKey'];
Expand Down Expand Up @@ -200,7 +200,7 @@ class BtcAddress {
});
}

@computed get getNormalAddrList () {
@computed get getNormalAddrList() {
let addrList = [];
let normalArr = Object.keys(self.addrInfo.normal);
normalArr.forEach(item => {
Expand All @@ -219,40 +219,44 @@ 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);
});
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();
Expand Down
158 changes: 84 additions & 74 deletions src/app/stores/eosAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
}
}

Expand Down
55 changes: 30 additions & 25 deletions src/app/stores/ethAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 53dfdd4

Please sign in to comment.