From d86ef382504a7e2bb01cc77d4c9d3bd06071dd3f Mon Sep 17 00:00:00 2001 From: vee <897831508@qq.com> Date: Sat, 13 Nov 2021 22:25:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E9=92=B1=E5=8C=85=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/WalletUtil.js | 99 +++++++++++++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 31 deletions(-) diff --git a/utils/WalletUtil.js b/utils/WalletUtil.js index 5b86f41..7bdb5d4 100644 --- a/utils/WalletUtil.js +++ b/utils/WalletUtil.js @@ -182,44 +182,81 @@ console.log(password,'password') this.updateBalance(); }, updateBalance:function() { + let wallet = uni.getStorageSync('wallet'); - switch (wallet.type) { - case 'BTC': - BtcUtil.getBalance(wallet.address,function(balance){ - wallet.balance=balance; - wallet.coinList[0].balance=balance - uni.setStorageSync('wallet', wallet); - }) - break; - case 'ETH': - EthUtil.getBalance(wallet.address,function(balance){ - wallet.balance=balance; - wallet.coinList[0].balance=balance - for(let i=1;i { + wallet.balance=res; + wallet.coinList[0].balance=res + TronUtil.getContract('TWgEuYRuXgwfDbcfzZsteu5w5dq1nFR35w',wallet.coinList,function(list){ + wallet.coinList=list; + wallet.coinList[1].balancePrice=(wallet.coinList[1].balance*usdt).toFixed(2); + console.log(wallet.coinList) + uni.setStorageSync('wallet', wallet); + }) + + }) + + break; + + } - break; - case 'TRX': + }) + + }) + + }, + getPrice:function(type,success){ + uni.request({ + url: 'https://apilist.tronscan.org/api/token/price?token=' + type.toLowerCase(), //请求接口 + header: { + 'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息 + }, + success: (res) => { + console.log(res.data.price_in_usd) + success(res.data.price_in_usd) - TronUtil.getTronBalance(wallet.address).then((res) => { - wallet.balance=res; - wallet.coinList[0].balance=res - TronUtil.getContract(wallet.address,wallet.coinList,function(list){ - wallet.coinList=list; - console.log(wallet.coinList) - uni.setStorageSync('wallet', wallet); - }) - - }) - break; + // coinList: [{ + // name: "ETH", + // xname: 'Ethereum', + // balance: 0, + // icon: require('@/static/tongyonh/Frame3299.png') + // }, - } + } + }); + } + } export default WalletUtil From 66ceeec20755b82ac196a28da94630f1d44f6fb3 Mon Sep 17 00:00:00 2001 From: vee <897831508@qq.com> Date: Sat, 13 Nov 2021 22:31:06 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=92=B1=E5=8C=85=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/menu/collection/index.vue | 2 +- utils/WalletUtil.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pages/menu/collection/index.vue b/pages/menu/collection/index.vue index aff163f..330cfd5 100644 --- a/pages/menu/collection/index.vue +++ b/pages/menu/collection/index.vue @@ -21,7 +21,7 @@ - + diff --git a/utils/WalletUtil.js b/utils/WalletUtil.js index b7c37bc..2db6b8d 100644 --- a/utils/WalletUtil.js +++ b/utils/WalletUtil.js @@ -205,6 +205,7 @@ let WalletUtil = { wallet.balance=balance; wallet.balancePrice=(balance*rr).toFixed(2); wallet.coinList[0].balance=balance + wallet.coinList[0].balancePrice=wallet.balancePrice uni.setStorageSync('wallet', wallet); }) break; @@ -213,6 +214,7 @@ let WalletUtil = { wallet.balance=balance; wallet.balancePrice=(balance*rr).toFixed(2); wallet.coinList[0].balance=balance + wallet.coinList[0].balancePrice=wallet.balancePrice for(let i=1;i { wallet.balance=res; + wallet.balancePrice=(res*rr).toFixed(2); wallet.coinList[0].balance=res - TronUtil.getContract('TWgEuYRuXgwfDbcfzZsteu5w5dq1nFR35w',wallet.coinList,function(list){ + wallet.coinList[0].balancePrice=wallet.balancePrice + TronUtil.getContract(wallet.address,wallet.coinList,function(list){ wallet.coinList=list; wallet.coinList[1].balancePrice=(wallet.coinList[1].balance*usdt).toFixed(2); console.log(wallet.coinList) From 10d76c273b34cec70e62f8dd7a2e2cd98fac1ed3 Mon Sep 17 00:00:00 2001 From: vee <897831508@qq.com> Date: Sat, 13 Nov 2021 22:34:33 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E9=92=B1=E5=8C=85=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/WalletUtil.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils/WalletUtil.js b/utils/WalletUtil.js index 2db6b8d..cb8b5db 100644 --- a/utils/WalletUtil.js +++ b/utils/WalletUtil.js @@ -78,6 +78,7 @@ let WalletUtil = { let wallet = walletInfo.BTC[0]; uni.setStorageSync('walletInfo', walletInfo); uni.setStorageSync('wallet', wallet); + this.updateBalance(); }, //修改钱包名称 updateWalletName: function(type, address, name) { @@ -129,6 +130,7 @@ let WalletUtil = { console.log(walletInfo, 1111111) uni.setStorageSync('walletInfo', walletInfo); uni.setStorageSync('wallet', wallet); + this.updateBalance(); }, //私钥新建 privateKeyEstablishWallet: function(type, privateKey, password) { @@ -154,6 +156,7 @@ let WalletUtil = { walletInfo.push(wallet); uni.setStorageSync('walletInfo', walletInfo); uni.setStorageSync('wallet', wallet); + this.updateBalance(); }, //获取钱包列表 getWalletList: function(type) {