Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

Include token information in signTx request to MEWconnect #2200

Merged
merged 8 commits into from
Jan 8, 2019
13 changes: 12 additions & 1 deletion app/scripts/staticJS/mewConnectEth.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class MewConnectEth {
this.comm.sendRtcMessage('signMessage', hashToSign);
}

signTransaction(eTx, rawTx, txData) {
signTransaction(eTx, rawTx, tokenDetails) {
const sendTxData = {
nonce: rawTx.nonce,
gasPrice: rawTx.gasPrice,
Expand All @@ -92,6 +92,17 @@ class MewConnectEth {
chainId: rawTx.chainId,
gas: rawTx.gasLimit
};

if (tokenDetails !== 'otherType') {
sendTxData.currency = {
symbol: tokenDetails ? tokenDetails.symbol : 'ETH',
decimals: tokenDetails ? tokenDetails.decimal : 18
};
if (tokenDetails) {
if(tokenDetails.address) sendTxData.currency.address = tokenDetails.address;
}
}

this.comm.sendRtcMessage('signTx', JSON.stringify(sendTxData));
}

Expand Down
18 changes: 16 additions & 2 deletions app/scripts/uiFuncs.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,23 @@ uiFuncs.signTxSecalot = function(eTx, rawTx, txData, callback) {
//= ================ Mew Connect (begin)==============================
uiFuncs.signTxMewConnect = function (eTx, rawTx, txData, callback) {
// uiFuncs.notifier.info("Tap a touch button on your device to confirm signing.");
var tokenDetails, tokenInfo;
var storedTokens = globalFuncs.localStorage.getItem('localTokens', null) != null ? JSON.parse(globalFuncs.localStorage.getItem('localTokens', null)) : [];
var defaultTokens = globalFuncs.getDefaultTokensAndNetworkType().defaultTokens;
if(rawTx.data.slice(0,10) === '0xa9059cbb'){
tokenInfo = storedTokens.find(entry => entry.contractAddress === rawTx.to);
tokenInfo = tokenInfo || defaultTokens.find(entry => entry.address === rawTx.to);
if(tokenInfo){
tokenDetails = {};
tokenDetails.symbol = tokenInfo.symbol
tokenDetails.decimal = tokenInfo.decimal
tokenDetails.address = tokenInfo.address || tokenInfo.contractAddress
}
} else if(rawTx.data.length > 2){
tokenDetails = 'otherType';
}

var app = new MewConnectEth()
// var mewConnect = MewConnect.instance
var mewConnect = globalFuncs.MEWconnectStatus.MEWconnect;
app.setMewConnect(mewConnect)
mewConnect.once('signTx', function(data) {
Expand All @@ -155,7 +169,7 @@ uiFuncs.signTxMewConnect = function (eTx, rawTx, txData, callback) {
if (callback !== undefined) callback(rawTx)
})

app.signTransaction(eTx, rawTx, txData)
app.signTransaction(eTx, rawTx, tokenDetails)
//= ================ Mew Connect (end)==============================
}
uiFuncs.generateTx = function(txData, callback) {
Expand Down
Loading