Browse Source

钱包工具类

master
vee 4 years ago
parent
commit
0d7607cf62
  1. 149
      package-lock.json
  2. 2
      package.json
  3. 7
      pages/menu/token/btc/index.vue
  4. 1
      pages/menu/wallet/index.vue
  5. 25
      unpackage/dist/dev/app-plus/app-service.js
  6. 14
      unpackage/dist/dev/app-plus/app-view.js
  7. 3
      utils/BtcUtil.js
  8. 39
      utils/TronUtil.js
  9. 18
      utils/WalletUtil.js

149
package-lock.json

@ -5,9 +5,9 @@
"requires": true,
"dependencies": {
"@babel/runtime": {
"version": "7.16.0",
"resolved": "https://registry.npmmirror.com/@babel/runtime/download/@babel/runtime-7.16.0.tgz",
"integrity": "sha1-4nuXfy4giLokdIv5m14d7OZOTws=",
"version": "7.16.3",
"resolved": "https://registry.npmmirror.com/@babel/runtime/download/@babel/runtime-7.16.3.tgz?cache=0&sync_timestamp=1636494819594&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2F%40babel%2Fruntime%2Fdownload%2F%40babel%2Fruntime-7.16.3.tgz",
"integrity": "sha512-WBwekcqacdY2e9AF/Q7WLFUWmdJGJTkbjqTjoMDgXkVZ3ZRUvOPsLb5KdwISoQVsbP+DQzVZW4Zhci0DvpbNTQ==",
"requires": {
"regenerator-runtime": "^0.13.4"
}
@ -535,6 +535,22 @@
"follow-redirects": "^1.14.4"
}
},
"babel-runtime": {
"version": "6.26.0",
"resolved": "https://registry.nlark.com/babel-runtime/download/babel-runtime-6.26.0.tgz",
"integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=",
"requires": {
"core-js": "^2.4.0",
"regenerator-runtime": "^0.11.0"
},
"dependencies": {
"regenerator-runtime": {
"version": "0.11.1",
"resolved": "https://registry.nlark.com/regenerator-runtime/download/regenerator-runtime-0.11.1.tgz?cache=0&sync_timestamp=1626993001371&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fregenerator-runtime%2Fdownload%2Fregenerator-runtime-0.11.1.tgz",
"integrity": "sha1-vgWtf5v30i4Fb5cmzuUBf78Z4uk="
}
}
},
"base-x": {
"version": "3.0.9",
"resolved": "https://registry.npmmirror.com/base-x/download/base-x-3.0.9.tgz?cache=0&sync_timestamp=1635764191053&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fbase-x%2Fdownload%2Fbase-x-3.0.9.tgz",
@ -795,6 +811,11 @@
"ieee754": "^1.1.13"
}
},
"buffer-equal-constant-time": {
"version": "1.0.1",
"resolved": "https://registry.npm.taobao.org/buffer-equal-constant-time/download/buffer-equal-constant-time-1.0.1.tgz",
"integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk="
},
"buffer-to-arraybuffer": {
"version": "0.0.5",
"resolved": "https://registry.npm.taobao.org/buffer-to-arraybuffer/download/buffer-to-arraybuffer-0.0.5.tgz",
@ -967,6 +988,11 @@
"resolved": "https://registry.npmmirror.com/cookiejar/download/cookiejar-2.1.3.tgz?cache=0&sync_timestamp=1632881937184&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fcookiejar%2Fdownload%2Fcookiejar-2.1.3.tgz",
"integrity": "sha1-/HpiFuQI50QUuQIwBQhC2s2nWsw="
},
"core-js": {
"version": "2.6.12",
"resolved": "https://registry.npmmirror.com/core-js/download/core-js-2.6.12.tgz",
"integrity": "sha1-2TM9+nsGXjR8xWgiGdb2kIWcwuw="
},
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.nlark.com/core-util-is/download/core-util-is-1.0.2.tgz",
@ -1142,6 +1168,14 @@
"safer-buffer": "^2.1.0"
}
},
"ecdsa-sig-formatter": {
"version": "1.0.11",
"resolved": "https://registry.nlark.com/ecdsa-sig-formatter/download/ecdsa-sig-formatter-1.0.11.tgz",
"integrity": "sha1-rg8PothQRe8UqBfao86azQSJ5b8=",
"requires": {
"safe-buffer": "^5.0.1"
}
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.nlark.com/ee-first/download/ee-first-1.1.1.tgz",
@ -2059,6 +2093,30 @@
"graceful-fs": "^4.1.6"
}
},
"jsonwebtoken": {
"version": "8.5.1",
"resolved": "https://registry.npm.taobao.org/jsonwebtoken/download/jsonwebtoken-8.5.1.tgz",
"integrity": "sha1-AOceC431TCEhofJhN98igGc7zA0=",
"requires": {
"jws": "^3.2.2",
"lodash.includes": "^4.3.0",
"lodash.isboolean": "^3.0.3",
"lodash.isinteger": "^4.0.4",
"lodash.isnumber": "^3.0.3",
"lodash.isplainobject": "^4.0.6",
"lodash.isstring": "^4.0.1",
"lodash.once": "^4.0.0",
"ms": "^2.1.1",
"semver": "^5.6.0"
},
"dependencies": {
"ms": {
"version": "2.1.3",
"resolved": "https://registry.npmmirror.com/ms/download/ms-2.1.3.tgz",
"integrity": "sha1-V0yBOM4dK1hh8LRFedut1gxmFbI="
}
}
},
"jsprim": {
"version": "1.4.1",
"resolved": "https://registry.npmmirror.com/jsprim/download/jsprim-1.4.1.tgz?cache=0&sync_timestamp=1635970868806&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fjsprim%2Fdownload%2Fjsprim-1.4.1.tgz",
@ -2070,6 +2128,25 @@
"verror": "1.10.0"
}
},
"jwa": {
"version": "1.4.1",
"resolved": "https://registry.npm.taobao.org/jwa/download/jwa-1.4.1.tgz",
"integrity": "sha1-dDwymFy56YZVUw1TZBtmyGRbA5o=",
"requires": {
"buffer-equal-constant-time": "1.0.1",
"ecdsa-sig-formatter": "1.0.11",
"safe-buffer": "^5.0.1"
}
},
"jws": {
"version": "3.2.2",
"resolved": "https://registry.npm.taobao.org/jws/download/jws-3.2.2.tgz",
"integrity": "sha1-ABCZ82OUaMlBQADpmZX6UvtHgwQ=",
"requires": {
"jwa": "^1.4.1",
"safe-buffer": "^5.0.1"
}
},
"keccak": {
"version": "3.0.2",
"resolved": "https://registry.nlark.com/keccak/download/keccak-3.0.2.tgz",
@ -2093,6 +2170,41 @@
"resolved": "https://registry.nlark.com/lodash/download/lodash-4.17.21.tgz?cache=0&sync_timestamp=1624543041613&other_urls=https%3A%2F%2Fregistry.nlark.com%2Flodash%2Fdownload%2Flodash-4.17.21.tgz",
"integrity": "sha1-Z5WRxWTDv/quhFTPCz3zcMPWkRw="
},
"lodash.includes": {
"version": "4.3.0",
"resolved": "https://registry.npm.taobao.org/lodash.includes/download/lodash.includes-4.3.0.tgz",
"integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8="
},
"lodash.isboolean": {
"version": "3.0.3",
"resolved": "https://registry.npm.taobao.org/lodash.isboolean/download/lodash.isboolean-3.0.3.tgz",
"integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY="
},
"lodash.isinteger": {
"version": "4.0.4",
"resolved": "https://registry.npm.taobao.org/lodash.isinteger/download/lodash.isinteger-4.0.4.tgz",
"integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M="
},
"lodash.isnumber": {
"version": "3.0.3",
"resolved": "https://registry.npm.taobao.org/lodash.isnumber/download/lodash.isnumber-3.0.3.tgz",
"integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w="
},
"lodash.isplainobject": {
"version": "4.0.6",
"resolved": "https://registry.npm.taobao.org/lodash.isplainobject/download/lodash.isplainobject-4.0.6.tgz",
"integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs="
},
"lodash.isstring": {
"version": "4.0.1",
"resolved": "https://registry.npm.taobao.org/lodash.isstring/download/lodash.isstring-4.0.1.tgz",
"integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE="
},
"lodash.once": {
"version": "4.1.1",
"resolved": "https://registry.nlark.com/lodash.once/download/lodash.once-4.1.1.tgz",
"integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w="
},
"lowercase-keys": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/lowercase-keys/download/lowercase-keys-1.0.1.tgz?cache=0&sync_timestamp=1634551715073&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Flowercase-keys%2Fdownload%2Flowercase-keys-1.0.1.tgz",
@ -2649,7 +2761,7 @@
},
"semver": {
"version": "5.7.1",
"resolved": "https://registry.nlark.com/semver/download/semver-5.7.1.tgz?cache=0&sync_timestamp=1622604551741&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fsemver%2Fdownload%2Fsemver-5.7.1.tgz",
"resolved": "https://registry.nlark.com/semver/download/semver-5.7.1.tgz?cache=0&sync_timestamp=1618847119601&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fsemver%2Fdownload%2Fsemver-5.7.1.tgz",
"integrity": "sha1-qVT5Ma66UI0we78Gnv8MAclhFvc="
},
"send": {
@ -2953,20 +3065,22 @@
}
},
"tronweb": {
"version": "4.0.0",
"resolved": "https://registry.nlark.com/tronweb/download/tronweb-4.0.0.tgz",
"integrity": "sha1-o2d9TS7hoGIxqg/XXBWrDW1V/JE=",
"version": "3.2.6",
"resolved": "https://registry.nlark.com/tronweb/download/tronweb-3.2.6.tgz",
"integrity": "sha1-Sppe7XBWHk7DzG+u4Ct4gx3Pr2Q=",
"requires": {
"@babel/runtime": "^7.0.0",
"axios": "^0.21.1",
"bignumber.js": "^9.0.1",
"elliptic": "^6.5.4",
"ethers": "^5.4.4",
"babel-runtime": "^6.26.0",
"bignumber.js": "^7.2.1",
"elliptic": "^6.5.3",
"ethers": "^5.0.8",
"eventemitter3": "^3.1.0",
"injectpromise": "^1.0.0",
"lodash": "^4.17.21",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.14",
"semver": "^5.6.0",
"validator": "^13.6.0"
"validator": "^10.7.1"
},
"dependencies": {
"axios": {
@ -2977,6 +3091,11 @@
"follow-redirects": "^1.14.0"
}
},
"bignumber.js": {
"version": "7.2.1",
"resolved": "https://registry.npm.taobao.org/bignumber.js/download/bignumber.js-7.2.1.tgz",
"integrity": "sha1-gMBIdZ2CaACAfEv9Uh5Q7bulel8="
},
"eventemitter3": {
"version": "3.1.2",
"resolved": "https://registry.nlark.com/eventemitter3/download/eventemitter3-3.1.2.tgz",
@ -3123,9 +3242,9 @@
"integrity": "sha1-sj5DWK+oogL+ehAK8fX4g/AgB+4="
},
"validator": {
"version": "13.7.0",
"resolved": "https://registry.npmmirror.com/validator/download/validator-13.7.0.tgz",
"integrity": "sha1-T5ZYuhO6jz2C7ogdNRZInqhcCFc="
"version": "10.11.0",
"resolved": "https://registry.npmmirror.com/validator/download/validator-10.11.0.tgz",
"integrity": "sha1-ADEI6m6amHTTHMyeUAaFbM12sig="
},
"varint": {
"version": "5.0.2",

2
package.json

@ -22,7 +22,7 @@
"ethers": "^5.5.1",
"js-md5": "^0.7.3",
"tki-qrcode": "^0.1.6",
"tronweb": "^4.0.0",
"tronweb": "^3.2.6",
"vue-clipboard2": "^0.3.3",
"web3": "^1.3.4"
}

7
pages/menu/token/btc/index.vue

@ -200,9 +200,14 @@
this.param.address = this.address
this.userObject = this.infoWallet
var that = this
this.$dataUtil.transactionData('ETH', 'send', this.address2, '0xdac17f958d2ee523a2206206994597c13d831ec7',
this.$dataUtil.transactionData('ETH', this.type, this.address2, '0xdac17f958d2ee523a2206206994597c13d831ec7',
1, 20,
function(data) {
if(data.length==0){
that.showInfo=true;
}else{
that.showInfo=false;
}
that.trxs = data
that.trxs2 = data
console.log(that.trxs, 12121)

1
pages/menu/wallet/index.vue

@ -92,7 +92,6 @@
onLoad() {
this.setStorage();
var a=uni.getStorageSync('wallet')
if(a!=''){
this.userObj=uni.getStorageSync('wallet');

25
unpackage/dist/dev/app-plus/app-service.js

File diff suppressed because one or more lines are too long

14
unpackage/dist/dev/app-plus/app-view.js

@ -23220,9 +23220,19 @@ __webpack_require__.r(__webpack_exports__);
!*** ./node_modules/babel-loader/lib!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader??ref--12-1!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/script.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-app-loader/using-components.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib??vue-loader-options!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/style.js!C:/Users/Administrator/Desktop/bitcoo/pages/menu/wallet/index.vue?vue&type=script&lang=js&mpType=page ***!
\********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });exports.default = void 0;var _default =
{
throw new Error("Module build failed (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/script.js):\nSyntaxError: Unexpected token (94:0)\n at Object._raise (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:746:17)\n at Object.raiseWithData (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:739:17)\n at Object.raise (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:733:17)\n at Object.unexpected (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:8807:16)\n at Object.parseExprAtom (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:10130:20)\n at Object.parseExprSubscripts (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:9656:23)\n at Object.parseMaybeUnary (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:9636:21)\n at Object.parseMaybeUnary (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:6877:20)\n at Object.parseExprOps (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:9506:23)\n at Object.parseMaybeConditional (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:9479:23)\n at Object.parseMaybeAssign (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:9434:21)\n at Object.parseMaybeAssign (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:6822:20)\n at Object.parseExpression (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:9386:23)\n at Object.parseStatementContent (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:11285:23)\n at Object.parseStatementContent (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:6575:18)\n at Object.parseStatement (C:\\Users\\Administrator\\Desktop\\HBuilderX\\plugins\\uniapp-cli\\node_modules\\@babel\\parser\\lib\\index.js:11156:17)");
data: function data() {
return {
wxsProps: {} };
},
components: {} };exports.default = _default;
/***/ }),
/* 539 */

3
utils/BtcUtil.js

@ -12,7 +12,8 @@ let BtcUtil = {
if (res.data.code === 1) {
if(res.data.data.length>0){
var data=res.data.data[0];
for(obj b in data){
console.log(data,11111)
for(let b in data){
balance=data[b];
}
}

39
utils/TronUtil.js

@ -26,6 +26,7 @@ let tron = {
console.log(Number(tronWeb.fromSun(balance).toString()));
return Number(tronWeb.fromSun(balance).toString());
},
//查询TRC/USDT余额
getTronTokenBalance: async function(address, contract) {
const contract_address = await tronWeb.address.fromHex(contract);
@ -74,6 +75,44 @@ let tron = {
return receipt.txid
}
return null;
},
getContract:function(address,list,success){
uni.request({
url: 'https://apiasia.tronscan.io:5566/api/account/tokens?limit=100&address=' + address, //请求接口
header: {
'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息
},
success: (res) => {
console.log(res.data.data[6].tokenDecimal)
for(let i=1;i<res.data.data.length;i++){
if(res.data.data[i].tokenAbbr==='USDT'){
list[1].balance=(Number(res.data.data[i].balance)/ Math.pow(10, res.data.data[i].tokenDecimal));
}else{
console.log(Number(res.data.data[i].balance)/Math.pow(10, res.data.data[i].tokenDecimal))
var coin={
name: res.data.data[i].tokenAbbr,
xname: res.data.data[i].tokenName,
balance: (Number(res.data.data[i].balance)/ Math.pow(10, res.data.data[i].tokenDecimal)),
icon: res.data.data[i].tokenLogo
}
list.push(coin)
}
}
console.log(list,12313)
success(list);
// coinList: [{
// name: "ETH",
// xname: 'Ethereum',
// balance: 0,
// icon: require('@/static/tongyonh/Frame3299.png')
// },
}
});
}
}

18
utils/WalletUtil.js

@ -188,6 +188,7 @@ console.log(password,'password')
BtcUtil.getBalance(wallet.address,function(balance){
wallet.balance=balance;
wallet.coinList[0].balance=balance
uni.setStorageSync('wallet', wallet);
})
break;
case 'ETH':
@ -197,6 +198,7 @@ console.log(password,'password')
for(let i=1;i<wallet.coinList.length;i++){
EthUtil.getTokenBalance(wallet.address,wallet.coinList[i].contractAddress,function(b){
wallet.coinList[i].balance=b;
uni.setStorageSync('wallet', wallet);
});
}
});
@ -207,16 +209,16 @@ console.log(password,'password')
TronUtil.getTronBalance(wallet.address).then((res) => {
wallet.balance=res;
wallet.coinList[0].balance=res
for(let i=1;i<wallet.coinList.length;i++){
TronUtil.getTronTokenBalance(wallet.address,wallet.coinList[i].contractAddress).then((res) => {
wallet.coinList[i].balance=res;
})
}
}).catch(err => {
console.log(err)
TronUtil.getContract('TWgEuYRuXgwfDbcfzZsteu5w5dq1nFR35w',wallet.coinList,function(list){
wallet.coinList=list;
console.log(wallet.coinList)
uni.setStorageSync('wallet', wallet);
})
})
break;
uni.setStorageSync('wallet', wallet);
}
}
}

Loading…
Cancel
Save