Browse Source

代码

master
Dread 4 years ago
parent
commit
83df1e849b
  1. 7
      pages/menu/sendToken/enPassword/index.vue
  2. 4
      pages/menu/sendToken/transfer/index.vue
  3. 18
      pages/menu/transction/detail/index.vue
  4. 5
      pages/menu/wallet/index.vue
  5. 25
      unpackage/dist/dev/app-plus/app-service.js
  6. 10
      unpackage/dist/dev/app-plus/app-view.js
  7. 56
      utils/EthUtil.js
  8. 6
      utils/SystemConfiguration.js
  9. 2
      utils/TokenUtil.js
  10. 1
      utils/WalletUtil.js
  11. 1
      utils/axios.js
  12. 5
      utils/locales/zh-F.js
  13. 2
      utils/locales/zh.js

7
pages/menu/sendToken/enPassword/index.vue

@ -46,9 +46,11 @@
}
},
transaction() {
console.log(this.transInfoPass.privateKey)
let that=this
if (this.transInfoPass.type === 'ETH') {
this.$EthUtil.transaction(this.transInfoPass.fromAddress, this.transInfoPass.privateKey,
this.transInfoPass.toAddress, this.transInfoPass.amount, this.transInfoPass.contractAddress,
this.$EthUtil.transaction(this.transInfoPass.fromAddress,
this.transInfoPass.toAddress, this.transInfoPass.amount.toString(), this.transInfoPass.privateKey.substring(2,this.transInfoPass.privateKey.length), this.transInfoPass.contractAddress,
function(hash, err) {
if (!err) {
@ -64,7 +66,6 @@
})
}, 1000)
} else {
console.log(err, 'cuowu')
uni.showToast({

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

@ -444,7 +444,9 @@
this.$EthUtil.getGas().then((res) => {
console.log(res, 'ETH')
this.$EthUtil.getGas().then((res) => {
that.transInfoPass.fee = res * 61000 / Math.pow(10, 6)
that.transInfoPass.fee = res * 61000 / Math.pow(10, 18)
that.showBottom = true;
that.show = true;
})
})

18
pages/menu/transction/detail/index.vue

@ -72,7 +72,7 @@
</view>
</view>
</view>
<view class="item goto">
<view class="item goto" @click="toDetail">
{{i18n.moreinformation}}
</view>
<!-- <view class="sett" v-if="show">
@ -121,6 +121,22 @@
},
},
methods: {
toDetail(){
let url;
if(this.info.chainName=='TRX'){
url =this.$SystemConfiguration.constant.trxTransctionDetail +this.info.txid;
}else if(this.info.chainName=='ETH'){
url =this.$SystemConfiguration.constant.ethTransctionDetail +this.info.txid;
}
// #ifdef H5
window.location.href = url;
// #endif
// #ifdef APP-PLUS
plus.runtime.openURL(url)
// #endif
},
copyTextMethod(text) {
console.log(text)
// #ifdef H5

5
pages/menu/wallet/index.vue

@ -111,7 +111,9 @@
this.isStop = true
uni.setStorageSync('isWallet', false);
},
async onLoad() {
onLoad() {
let currency = uni.getStorageSync('currency');
if (currency) {
this.currency = currency;
@ -122,7 +124,6 @@
this.userObj = uni.getStorageSync('wallet');
console.log('eth有走这吗')
this.updateBalance();
uni.setStorageSync('isWallet', false);
// #ifdef APP-PLUS
//this.appVersion()
// #endif

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

File diff suppressed because one or more lines are too long

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

@ -20327,7 +20327,15 @@ var render = function() {
),
_c(
"v-uni-view",
{ staticClass: _vm._$g(34, "sc"), attrs: { _i: 34 } },
{
staticClass: _vm._$g(34, "sc"),
attrs: { _i: 34 },
on: {
click: function($event) {
return _vm.$handleViewEvent($event)
}
}
},
[_vm._v(_vm._$g(34, "t0-0"))]
)
],

56
utils/EthUtil.js

@ -13,6 +13,7 @@ if (typeof web3 !== 'undefined') {
let eth = {
// //获取主币eth余额
getBalance: async function(address) {
web3 = new Web3(new Web3.providers.HttpProvider(systemConfiguration.constant.ethNode));
console.log("查询余额:",address)
@ -32,6 +33,7 @@ let eth = {
// return Number(balance) / Math.pow(10, decimals);
// },
getGas: async function() {
web3 = new Web3(new Web3.providers.HttpProvider(systemConfiguration.constant.ethNode));
const gasPrice = await web3.eth.getGasPrice().then((v) => {
return v
});
@ -39,28 +41,28 @@ let eth = {
return gasPrice;
},
// //获取主币eth余额
// getBalance: async function(address) {
// web3 = new Web3();
// const data = {
// 'jsonrpc': '2.0',
// 'id': '1',
// 'method': 'eth_getBalance',
// 'params': [address, "latest"]
// };
// let res = await uni.request({
// url: systemConfiguration.constant.ethNode, //仅为示例,并非真实接口地址。
// method: 'POST',
// data: data,
// dataType: 'json'
// });
// try {
// let balance = Number(web3.utils.hexToNumberString(res[1].data.result)) / Math.pow(10, 18)
// return balance
// } catch (e) {
// return 0;
// }
// },
//获取主币eth余额
getBalance: async function(address) {
web3 = new Web3();
const data = {
'jsonrpc': '2.0',
'id': '1',
'method': 'eth_getBalance',
'params': [address, "latest"]
};
let res = await uni.request({
url: systemConfiguration.constant.ethNode, //仅为示例,并非真实接口地址。
method: 'POST',
data: data,
dataType: 'json'
});
try {
let balance = Number(web3.utils.hexToNumberString(res[1].data.result)) / Math.pow(10, 18)
return balance
} catch (e) {
return 0;
}
},
addPreZero: function(num) {
let t = (num + '').length,
s = '';
@ -101,25 +103,26 @@ let eth = {
sendTransaction: async function(fromAddress, toAddress, value, privateKey, success) {
var nonce = await web3.eth.getTransactionCount(fromAddress);
var gas = await web3.eth.estimateGas({
from: fromAddress
});
console.log(11111111111)
console.log(nonce)
console.log(fromAddress, toAddress, value, privateKey)
console.log(fromAddress, toAddress, value, privateKey,web3.eth.getGasPrice())
var txData = {
chainId: web3.utils.toHex(1899),
// nonce每次++,以免覆盖之前pending中的交易
nonce: web3.utils.toHex(nonce++),
// 设置gasLimit和gasPrice
gas: web3.utils.toHex(gas),
gasLimit: web3.utils.toHex(600000),
gasPrice: web3.utils.toHex(web3.eth.getGasPrice()),
// 要转账的哪个账号
to: toAddress,
// 从哪个账号转
from: fromAddress,
// 0.001 以太币
value: web3.utils.toHex(web3.utils.toWei(value, 'ether'))
value: web3.utils.toHex(web3.utils.toWei(value, 'ether')),
chainId:systemConfiguration.constant.ethChainId
}
@ -127,6 +130,7 @@ let eth = {
// 引入私钥,并转换为16进制
// 用私钥签署交易
console.log(txData,55555)
console.log(Buffer.from(privateKey).toString('hex'))
const tx = new Tx(txData);
tx.sign(Buffer.from(privateKey, 'hex'));

6
utils/SystemConfiguration.js

@ -5,11 +5,17 @@ const constant = isTest ? {
serverUrl: 'http://wallet-api.weirui0755.com',
coinTickerWs:'ws://wallet-quartz.weirui0755.com/websocket',
ethNode:'http://47.245.25.82:8545',
ethChainId:1,
ethTransctionDetail:'https://cn.etherscan.com/tx/',
trxTransctionDetail:'https://tronscan.io/#/transaction/'
} : {
//服务端连接
serverUrl: 'http://wallet-api.weirui0755.com',
coinTickerWs:'ws://wallet-quartz.weirui0755.com/websocket',
ethNode:'http://47.245.25.82:8545',
ethChainId:3,
ethTransctionDetail:'https://cn.etherscan.com/tx/',
trxTransctionDetail:'https://tronscan.io/#/transaction/'
}
export default {

2
utils/TokenUtil.js

@ -92,7 +92,7 @@ let token = {
let wallet = new ethers.Wallet(privateKey);
let address = wallet.address;
return {
'privateKey': privateKey,
'privateKey': wallet.privateKey,
'address': address
};
},

1
utils/WalletUtil.js

@ -235,6 +235,7 @@ let WalletUtil = {
case 'ETH':
console.log("进来ETH",wallet.balance )
wallet.balance = await EthUtil.getBalance(wallet.address);
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);

1
utils/axios.js

@ -16,7 +16,6 @@ service.interceptors.request.use(
console.log(config)
let isWallet= uni.getStorageSync('isWallet');
console.log(isWallet,55555)
if(!isWallet){
uni.showLoading({
title: 'loading',

5
utils/locales/zh-F.js

@ -141,8 +141,7 @@ export default {
// sendToken index
Receivingaddress: '接收地址',
ReceivingaddressError: '接收地址錯誤',
ScanQR: '掃描二維碼轉賬至資產',
ScanQR: '掃描二維碼以轉移到資產',
Copyaddress: '複製地址',
CopySuccessful: '複製地址成功!',
// transfer
@ -176,7 +175,7 @@ export default {
// backup5
Importviaprivatekey: '通過私鑰導入',
Privatekeyimportverification: '私鑰導入驗證',
privatekeyanddo: '請輸入您的私鑰,不要洩露給他人,外部地址無法通過助記詞恢復。請妥善保管',
privatekeyanddo: '請輸入您的私鑰,不要將其洩露給其他人外部地址無法通過助記鍵恢復。 請妥善保管',
enteryourprivatekey: '請輸入您的私鑰',
beempty: '不能為空',
beenimported: '錢包已經被導入',

2
utils/locales/zh.js

@ -139,7 +139,7 @@ export default {
// sendToken index
Receivingaddress: '接收地址',
ReceivingaddressError: '接收地址错误',
ScanQR: '扫描二维码转账至资产',
ScanQR: '扫描二维码以转移到资产',
Copyaddress: '复制地址',
CopySuccessful: '复制地址成功!',
// transfer

Loading…
Cancel
Save