Browse Source

验证钱包地址

master
vee 4 years ago
parent
commit
a8e82f401e
  1. 4723
      package-lock.json
  2. 2
      package.json
  3. 29
      pages/menu/sendToken/addAddress/index.vue
  4. 63
      pages/menu/sendToken/addAddress2/index.vue
  5. 30
      pages/menu/sendToken/transfer/index.vue
  6. 2
      pages/menu/token/btc/index.css
  7. 11
      pages/menu/token/btc/index.vue
  8. 99
      utils/TokenUtil.js
  9. 31
      utils/WalletUtil.js
  10. 1
      utils/locales/en.js
  11. 1
      utils/locales/zh-F.js
  12. 1
      utils/locales/zh.js

4723
package-lock.json

File diff suppressed because it is too large

2
package.json

@ -21,10 +21,12 @@
"ethereumjs-tx": "^1.3.7",
"ethers": "^5.5.1",
"js-md5": "^0.7.3",
"js-sha256": "^0.9.0",
"node": "^17.1.0",
"tki-qrcode": "^0.1.6",
"tronweb": "^3.2.6",
"vue-clipboard2": "^0.3.3",
"wallet-address-validator": "^0.2.4",
"web3": "^1.3.4"
}
}

29
pages/menu/sendToken/addAddress/index.vue

@ -191,6 +191,16 @@
if (this.value == 'BTC') {
if(!this.$Token.validateBtc(this.bigAddress))
{
uni.showToast({
title: this.$t('index').addressFormatError,
icon: 'none',
duration: 1500
})
return
}
console.log(uni.getStorageSync('BTCAddressInfo'), 777)
if (uni.getStorageSync('BTCAddressInfo').length > 0) {
let btc = new Object;
@ -247,6 +257,16 @@
if (this.value == 'ETH') {
console.log(this.bigAddress,this.$Token.validateEth(this.bigAddress))
if(!this.$Token.validateEth(this.bigAddress))
{
uni.showToast({
title: this.$t('index').addressFormatError,
icon: 'none',
duration: 1500
})
return
}
console.log(uni.getStorageSync('ETHAddressInfo'), 777)
if (uni.getStorageSync('ETHAddressInfo').length > 0) {
let eth = new Object;
@ -306,6 +326,15 @@
}
if (this.value == 'TRX') {
if(!this.$Token.validateTrx(this.bigAddress))
{
uni.showToast({
title: this.$t('index').addressFormatError,
icon: 'none',
duration: 1500
})
return
}
console.log(uni.getStorageSync('TRXAddressInfo'), 777)
if (uni.getStorageSync('TRXAddressInfo').length > 0) {
let trx = new Object;

63
pages/menu/sendToken/addAddress2/index.vue

@ -202,6 +202,15 @@
if (this.info.coinList[0].name2 == 'TRX') {
this.$walletUtil.updateAddress(this.info.coinList[0].name2, this.value);
if (this.value == 'ETH') {
if(!this.$Token.validateEth(this.bigAddress))
{
uni.showToast({
title: this.$t('index').addressFormatError,
icon: 'none',
duration: 1500
})
return
}
this.gai = uni.getStorageSync('ETHAddressInfo')
this.gai2 = uni.getStorageSync('TRXAddressInfo')
var index = uni.getStorageSync('editIndex')
@ -296,6 +305,15 @@
if (this.info.coinList[0].name2 == 'ETH') {
if (this.value == 'TRX') {
if(!this.$Token.validateTrx(this.bigAddress))
{
uni.showToast({
title: this.$t('index').addressFormatError,
icon: 'none',
duration: 1500
})
return
}
this.gai = uni.getStorageSync('TRXAddressInfo')
this.gai2 = uni.getStorageSync('ETHAddressInfo')
var index = uni.getStorageSync('editIndex')
@ -329,6 +347,15 @@
})
}
if (this.value == 'ETH') {
if(!this.$Token.validateEth(this.bigAddress))
{
uni.showToast({
title: this.$t('index').addressFormatError,
icon: 'none',
duration: 1500
})
return
}
this.gai = uni.getStorageSync('ETHAddressInfo')
var index = uni.getStorageSync('editIndex')
let eth = new Object;
@ -354,6 +381,15 @@
}
if (this.value == 'BTC') {
if(!this.$Token.validateBtc(this.bigAddress))
{
uni.showToast({
title: this.$t('index').addressFormatError,
icon: 'none',
duration: 1500
})
return
}
this.gai = uni.getStorageSync('BTCAddressInfo')
this.gai2 = uni.getStorageSync('ETHAddressInfo')
var index = uni.getStorageSync('editIndex')
@ -391,6 +427,15 @@
if (this.info.coinList[0].name2 == 'BTC') {
if (this.value == 'TRX') {
if(!this.$Token.validateTrx(this.bigAddress))
{
uni.showToast({
title: this.$t('index').addressFormatError,
icon: 'none',
duration: 1500
})
return
}
this.gai = uni.getStorageSync('TRXAddressInfo')
this.gai2 = uni.getStorageSync('BTCAddressInfo')
@ -426,6 +471,15 @@
})
}
if (this.value == 'BTC') {
if(!this.$Token.validateBtc(this.bigAddress))
{
uni.showToast({
title: this.$t('index').addressFormatError,
icon: 'none',
duration: 1500
})
return
}
this.gai = uni.getStorageSync('BTCAddressInfo')
var index = uni.getStorageSync('editIndex')
let btc = new Object;
@ -451,6 +505,15 @@
}
if (this.value == 'ETH') {
if(!this.$Token.validateEth(this.bigAddress))
{
uni.showToast({
title: this.$t('index').addressFormatError,
icon: 'none',
duration: 1500
})
return
}
this.gai = uni.getStorageSync('ETHAddressInfo')
this.gai2 = uni.getStorageSync('BTCAddressInfo')
var index = uni.getStorageSync('editIndex')

30
pages/menu/sendToken/transfer/index.vue

@ -305,7 +305,7 @@
}, 1000)
} else {
console.log(err, 'cuowu')
that.showFinger = false;
that.showBottom = true;
uni.showToast({
@ -441,6 +441,15 @@
let that = this
if (this.coin.type === 'ETH') {
if(!this.$Token.validateEth(this.transInfoPass.toAddress))
{
uni.showToast({
title: this.$t('index').addressFormatError,
icon: 'none',
duration: 1500
})
return
}
this.$EthUtil.getGas().then((res) => {
console.log(res, 'ETH')
this.$EthUtil.getGas().then((res) => {
@ -451,6 +460,15 @@
})
} else if (this.coin.type === 'TRX') {
if(!this.$Token.validateTrx(this.transInfoPass.toAddress))
{
uni.showToast({
title: this.$t('index').addressFormatError,
icon: 'none',
duration: 1500
})
return
}
this.$TronUtil.getTransaction(this.transInfoPass.fromAddress,
this.transInfoPass.toAddress, this.transInfoPass.amount, this.transInfoPass.remark, this
.transInfoPass.contractAddress)
@ -477,6 +495,16 @@
})
})
}else if(this.coin.type === 'BTC'){
if(!this.$Token.validateBtc(this.transInfoPass.toAddress))
{
uni.showToast({
title: this.$t('index').addressFormatError,
icon: 'none',
duration: 1500
})
return
}
}
},

2
pages/menu/token/btc/index.css

@ -196,7 +196,7 @@
.main .money_con {
margin-top: 32rpx;
background-image: linear-gradient(to right, #6441CF, #877BFE);
height: 320rpx;
height: 354rpx;
padding: 40rpx 36rpx;
position: relative;
border-radius: 24rpx;

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

@ -16,7 +16,8 @@
{{coin.balance}} {{coin.name}}
</view>
<text class="text2">
{{currency=='USD'?'$ '+(!coin.balancePrice?0.00:coin.balancePrice):'¥ '+(!coin.balanceCnyPrice?0.00:coin.balanceCnyPrice)}}
{{currency=='USD'?'$ '+(!coin.balancePrice?0.00:coin.balancePrice):'¥ '+(!coin.balanceCnyPrice?0.00:coin.balanceCnyPrice)}}
</text>
</text>
@ -54,7 +55,8 @@
</u-tabs>
<u-empty :text="teee" mode="list" v-if="showInfo"></u-empty>
<scroll-view v-if="!showInfo":scroll-y="true" style="max-height: 880rpx;" @scrolltolower="scrollToPage" lower-threshold="50">
<scroll-view v-if="!showInfo" :scroll-y="true" style="max-height: 880rpx;"
@scrolltolower="scrollToPage" lower-threshold="50">
<view class="item1" v-for="(item,index) in trxs" @click="goDetail(item,index)">
<view class="lef_con">
<image src="../../../../static/tongyonh/arrow-up-left.png" mode="aspectFit" class="img1"
@ -212,13 +214,16 @@
}
},
async getWalletInfo() {
let params = {
address: this.coin.address,
chainName: this.coin.type,
contract: this.coin.contractAddress,
type: this.coin.tokenType,
pageNum: this.pageNum,
pageSize: this.pageSize
}
console.log(params)
if (this.type === 'send') {
params.fromAddress = this.coin.address;
} else if (this.type === 'receive') {
@ -247,6 +252,8 @@
if (currency) {
this.currency = currency;
}
var a=this.$Token.validateTrx('TWgEuYRuXgwfDbcfzZsteu5w5dq1nFR35w');
console.log(a,123465)
}
};

99
utils/TokenUtil.js

@ -5,7 +5,8 @@ const util = require('ethereumjs-util')
const ethers = require('ethers')
const bitcoin = require('bitcoinjs-lib')
let Tx = require('ethereumjs-tx');
const WAValidator = require('wallet-address-validator');
const sha256= require('js-sha256').sha256;
@ -175,30 +176,82 @@ let token = {
}
return wallrtInfo;
},
validateBtc: function(address) {
let valid = WAValidator.validate(address, 'BTC');
console.log(valid, 'BTC')
return valid;
},
validateEth: function(address) {
let valid = WAValidator.validate(address, 'ETH');
console.log(valid, 'eth')
return valid;
},
validateTrx: function(base58Str) {
if (typeof(base58Str) !== 'string')
return false;
// creatingWallets: function() {
// let mnemonic = this.generateMnemonic();
// let eth = this.generateEth(mnemonic);
// let tron = this.generateTron(mnemonic);
// let btc = this.generateBtc(mnemonic);
// // let privateKey = this.getPrivateKey(mnemonic);
// return {
// 'eth': eth,
// 'tron': tron,
// 'btc': btc,
// 'mnemonic': mnemonic,
// // 'privateKey': privateKey
// };
// },
creatingWallets: function() {
let mnemonic = this.generateMnemonic();
// let privateKey = this.getPrivateKey(mnemonic);
return {
if (base58Str.length !== 34)
return false;
'mnemonic': mnemonic,
// 'privateKey': privateKey
};
let address = this.decode58(base58Str);
if (address.length !== 25)
return false;
if (address[0] !== 0x41)
return false;
// const checkSum = address.slice(21);
// address = address.slice(0, 21);
// const hash0 = sha256.sha256(address);
// const hash1 = sha256.sha256(hash0);
// const checkSum1 = hash1.slice(0, 4);
// console.log(hash1)
// console.log(address,1111)
// console.log(checkSum1)
// console.log(checkSum)
// if (checkSum[0] == checkSum1[0] && checkSum[1] == checkSum1[1] && checkSum[2] ==
// checkSum1[2] && checkSum[3] == checkSum1[3]
// ) {
return true
// }
// return false;
},
decode58: function (string) {
var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
var ALPHABET_MAP = {};
var BASE = 58;
for (var i = 0; i < ALPHABET.length; i++) {
ALPHABET_MAP[ALPHABET.charAt(i)] = i;
}
if (string.length === 0) return [];
var i,
j,
bytes = [0];
for (i = 0; i < string.length; i++) {
var c = string[i];
// c是不是ALPHABET_MAP的key
if (!(c in ALPHABET_MAP)) throw new Error('Non-base58 character');
for (j = 0; j < bytes.length; j++) bytes[j] *= BASE;
bytes[0] += ALPHABET_MAP[c];
var carry = 0;
for (j = 0; j < bytes.length; ++j) {
bytes[j] += carry;
carry = bytes[j] >> 8;
// 0xff --> 11111111
bytes[j] &= 0xff;
}
while (carry) {
bytes.push(carry & 0xff);
carry >>= 8;
}
}
// deal with leading zeros
for (i = 0; string[i] === '1' && i < string.length - 1; i++) bytes.push(0);
return bytes.reverse();
}
}
export default token

31
utils/WalletUtil.js

@ -181,7 +181,8 @@ let WalletUtil = {
walletList = walletInfo[type]
for (var k = 0, length = walletList.length; k < length; k++) {
let address = walletList[k].address;
walletList[k].ellipsisAddress = address.substring(0, 6) + '...' + address.substring(address.length - 6,
walletList[k].ellipsisAddress = address.substring(0, 6) + '...' + address.substring(address
.length - 6,
address.length)
}
} else {
@ -207,7 +208,8 @@ let WalletUtil = {
console.log()
for (var k = 0, length = walletList.length; k < length; k++) {
if (walletList[k].address == address) {
walletList[k].ellipsisAddress = address.substring(0, 6) + '...' + address.substring(address.length - 6,
walletList[k].ellipsisAddress = address.substring(0, 6) + '...' + address.substring(address
.length - 6,
address.length)
uni.setStorageSync('wallet', walletList[k]);
break;
@ -238,12 +240,15 @@ let WalletUtil = {
wallet.balance = wallet.balance > 0 ? wallet.balance.toFixed(6) : wallet.balance
console.log("进来ETH", wallet.balance)
for (let i = 1; i < wallet.coinList.length; i++) {
wallet.coinList[i].balance = await EthUtil.getTokenBalance(wallet.address, wallet.coinList[i].contractAddress);
wallet.coinList[i].balance = await EthUtil.getTokenBalance(wallet.address, wallet.coinList[
i].contractAddress);
console.log("进来ETH", wallet.coinList[i].balance)
}
wallet.totalBalancePrice = wallet.coinList[1].balancePrice?wallet.coinList[1].balancePrice:0;
wallet.totalBalanceCnyPrice=wallet.coinList[1].balanceCnyPrice?wallet.coinList[1].balanceCnyPrice:0;
wallet.totalBalancePrice = wallet.coinList[1].balancePrice ? wallet.coinList[1].balancePrice :
0;
wallet.totalBalanceCnyPrice = wallet.coinList[1].balanceCnyPrice ? wallet.coinList[1]
.balanceCnyPrice : 0;
wallet.coinList[1].balancePrice = (wallet
.coinList[1].balance * usdtU.data.priceInUsd).toFixed(2);
wallet.coinList[1].balanceCnyPrice = (wallet
@ -256,12 +261,16 @@ let WalletUtil = {
params.chainName = wallet.type;
const tronCoin = await api.getBalance(params);
var newList = [];
newList.push(wallet.coinList[0])
newList.push(wallet.coinList[1])
newList[0].tokenType = "trc10"
newList[0].contractAddress='_';
for (let i = 1; i < tronCoin.data.length; i++) {
if (tronCoin.data[i].tokenAbbr === 'USDT') {
newList[1].balance = (Number(tronCoin.data[i].balance) / Math.pow(10, tronCoin
.data[i].tokenDecimal));
newList[1].tokenType = "trc20"
newList[1].balanceCnyPrice = (newList[1].balance * usdtU.data.priceCny).toFixed(2);
newList[1].balancePrice = (newList[1].balance * usdtU.data.priceInUsd).toFixed(2);
wallet.totalBalancePrice = newList[1].balancePrice
@ -275,13 +284,10 @@ let WalletUtil = {
balance: (Number(tronCoin.data[i].balance) / Math.pow(10, tronCoin.data[i]
.tokenDecimal)),
icon: tronCoin.data[i].tokenLogo,
}
if (tronCoin.data[i].tokenType === 'trc20') {
coin.contractAddress = tronCoin.data[i].tokenId
} else {
coin.contractAddress = tronCoin.data[i].owner_address
contractAddress: tronCoin.data[i].tokenId,
tokenType: tronCoin.data[i].tokenType
}
newList.push(coin)
}
@ -298,7 +304,8 @@ let WalletUtil = {
wallet.balancePrice = (wallet.balance * mainCoinP.data.priceInUsd).toFixed(2);
wallet.balanceCnyPrice = (wallet.balance * mainCoinP.data.priceCny).toFixed(2);
wallet.totalBalancePrice = (Number(wallet.totalBalancePrice) + Number(wallet.balancePrice)).toFixed(2);
wallet.totalBalanceCnyPrice=(Number(wallet.totalBalanceCnyPrice)+Number(wallet.balanceCnyPrice)).toFixed(2);
wallet.totalBalanceCnyPrice = (Number(wallet.totalBalanceCnyPrice) + Number(wallet.balanceCnyPrice))
.toFixed(2);
console.log("wallet.balancePrice", Number(wallet.totalBalancePrice))
console.log("wallet.balanceCnyPrice", wallet.totalBalancePrice)
wallet.coinList[0].balance = wallet.balance

1
utils/locales/en.js

@ -169,6 +169,7 @@ export default {
fingerprintidentification: 'This device does not support fingerprint identification',
notequipped: 'This device is not equipped with a password lock screen and cannot use fingerprint identification',
oninthesetting: 'There is no fingerprint entered in this device. Please turn it on in the setting',
addressFormatError:'Address format error',
// Add Token
AddToken: 'Add Token',
Hotassets: 'Hot assets',

1
utils/locales/zh-F.js

@ -168,6 +168,7 @@ export default {
fingerprintidentification: '此設備不支持指紋識別',
notequipped: '此設備未配備密碼鎖定荧幕,無法使用指紋識別',
oninthesetting: '此設備中沒有輸入指紋。 請在設定中打開它',
addressFormatError:'地址格式錯誤',
// Add Token
AddToken: '添加代幣',
Hotassets: '熱門資產',

1
utils/locales/zh.js

@ -166,6 +166,7 @@ export default {
fingerprintidentification: '此设备不支持指纹识别',
notequipped: '此设备未配备密码锁定屏幕,无法使用指纹识别',
oninthesetting: '此设备中没有输入指纹。请在设置中打开它',
addressFormatError:'地址格式错误',
// Add Token
AddToken: '添加代币',
Hotassets: '热门资产',

Loading…
Cancel
Save