Skip to content

Commit 641e639

Browse files
committedMar 4, 2021
add current instance tx hash check, inform when mobile response is invalid
1 parent 6799a17 commit 641e639

File tree

8 files changed

+121
-10
lines changed

8 files changed

+121
-10
lines changed
 

‎CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### Release 2.1.23-beta.4
2+
- Add a current instance cache for transaction hashes to prevent multiple send attempts
3+
- Add notice when malformed response is received from mobile
4+
- Add a current instance timer to stop checking for transaction hash after 60 minutes
5+
6+
17
### Release 2.1.23-beta.3
28
- Fix EIP-1193 disconnect event name typo (disconnected -> disconnect)
39
- Add wallet connected checks for eth_signTransaction, eth_sendTransaction

‎example/app/src/App.vue

+79-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@
2525
</button>
2626
{{ signedTxNonStandard }}
2727
</li>
28+
<li>
29+
<hr />
30+
<h3>Send</h3>
31+
<label for="toAmount1">
32+
to amount
33+
<input
34+
id="toAmount1"
35+
v-model="toAmount"
36+
placeholder="amount"
37+
/> </label
38+
><br />
39+
<!-- <button v-show="userAddress !== ''" @click="sendTx">send</button>-->
40+
<button @click="sendTx">send</button>
41+
<h6>Sends to the connected wallet address</h6>
42+
<h3>Tx Hash:</h3>
43+
{{ txHash }}
44+
</li>
2845
<li>
2946
<hr />
3047
<h3>Send</h3>
@@ -35,9 +52,25 @@
3552
v-model="toAmount"
3653
placeholder="amount"
3754
/> </label
55+
>
56+
<label for="altNonce">
57+
alt nonce
58+
<input
59+
id="altNonce"
60+
v-model="altNonce"
61+
placeholder="altNonce"
62+
/> </label
63+
>
64+
<label for="altGasPrice">
65+
altGasPrice
66+
<input
67+
id="altGasPrice"
68+
v-model="altGasPrice"
69+
placeholder="altGasPrice"
70+
/> </label
3871
><br />
3972
<!-- <button v-show="userAddress !== ''" @click="sendTx">send</button>-->
40-
<button @click="sendTx">send</button>
73+
<button @click="sendTx2">send alt-nonce</button>
4174
<h6>Sends to the connected wallet address</h6>
4275
<h3>Tx Hash:</h3>
4376
{{ txHash }}
@@ -351,7 +384,9 @@ export default {
351384
fromAddressDetailed: '',
352385
thing: false,
353386
checker: false,
354-
checkOne: ''
387+
checkOne: '',
388+
altNonce: '',
389+
altGasPrice: ''
355390
};
356391
},
357392
mounted() {
@@ -367,10 +402,11 @@ export default {
367402
// 859569f6decc4446a5da1bb680e7e9cf
368403
this.connect = new mewConnect.Provider({
369404
windowClosedError: true,
370-
chainId: 1,
371-
// chainId: 3,
405+
// chainId: 1,
406+
chainId: 3,
372407
// rpcUrl: 'https://mainnet.infura.io/v3/' //'wss://mainnet.infura.io/ws/v3/'
373-
rpcUrl: 'HTTP://127.0.0.1:7545'
408+
// rpcUrl: 'HTTP://127.0.0.1:7545'
409+
rpcUrl: 'https://ropsten.infura.io/v3/c9b249497d074ab59c47a97bdfe6b401'
374410
// rpcUrl: 'ws://127.0.0.1:8545'
375411
// infuraId: '7d06294ad2bd432887eada360c5e1986'
376412
});
@@ -588,6 +624,44 @@ export default {
588624
});
589625
});
590626
},
627+
sendTx2() {
628+
this.web3.eth.getBalance(this.userAddress).then(bal => this.balance);
629+
this.web3.eth.getGasPrice().then(gasPrice => {
630+
if(this.altGasPrice !== '' ){
631+
gasPrice = this.altGasPrice
632+
}
633+
console.log('gasPrice', gasPrice); // todo remove dev item
634+
this.web3.eth.getTransactionCount(this.userAddress).then(nonce => {
635+
if(this.altNonce !== '' ){
636+
nonce = this.altNonce
637+
}
638+
console.log('nonce', nonce); // todo remove dev item
639+
this.web3.eth
640+
.sendTransaction({
641+
from: this.userAddress,
642+
to: this.userAddress,
643+
nonce,
644+
value: new BigNumber(this.toAmount)
645+
.times(new BigNumber(10).pow(18))
646+
.toFixed()
647+
/*gasPrice: gasPrice ,
648+
gasLimit: '0xa'// 21000*/
649+
})
650+
.once('transactionHash', hash => {
651+
console.log(['Hash', hash]);
652+
this.txHash = hash;
653+
})
654+
.once('receipt', res => {
655+
console.log(['Receipt', res]);
656+
})
657+
.on('error', err => {
658+
console.log(['Error', err]);
659+
})
660+
.then(txhash => console.log('THEN: ', txhash))
661+
.catch(err => console.error(err));
662+
});
663+
});
664+
},
591665
sendTxDetailed() {
592666
this.sendTxDetailed2()
593667
/* // this.web3.eth.getBalance(this.userAddress).then(bal => this.balance);

‎src/connectClient/WebRtcCommunication.js

+1
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ export default class WebRtcCommunication extends MewConnectCommon {
320320
});
321321
}
322322
} catch (e) {
323+
this.uiCommunicator(this.lifeCycle.decryptError);
323324
logger.error(e);
324325
debug('onData ERROR: data=', data);
325326
debug('onData ERROR: data.toString()=', data.toString());

‎src/connectClient/constants/constants.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ const lifeCycle = {
7171
attemptedDisconnectedSend: 'attemptedDisconnectedSend',
7272
connected: 'connected',
7373
disconnected: 'disconnected',
74-
ShowReload: 'ShowReload'
74+
ShowReload: 'ShowReload',
75+
decryptError: 'decryptError'
7576
};
7677

7778
const communicationTypes = {

‎src/connectProvider/index.js

+19
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export default class Integration extends EventEmitter {
184184
this.popUpHandler.showConnectedNotice();
185185
this.popUpHandler.hideNotifier();
186186
this.createDisconnectNotifier();
187+
this.createCommunicationError();
187188
debugConnectionState(MEWconnectWallet.getConnectionState());
188189
}
189190

@@ -345,6 +346,18 @@ export default class Integration extends EventEmitter {
345346
);
346347
}
347348

349+
createCommunicationError(){
350+
const connection = state.wallet.getConnection();
351+
connection.webRtcCommunication.on(
352+
connection.lifeCycle.decryptError,
353+
() => {
354+
this.popUpHandler.showNoticePersistentEnter(
355+
messageConstants.communicationError
356+
);
357+
}
358+
);
359+
}
360+
348361
disconnect() {
349362
try {
350363
if (this.runningInApp) {
@@ -375,6 +388,7 @@ export default class Integration extends EventEmitter {
375388
}
376389

377390
setupListeners() {
391+
const transactionCache = [];
378392
eventHub.on(EventNames.SHOW_TX_CONFIRM_MODAL, (tx, resolve) => {
379393
this.responseFunction = resolve;
380394
if (!state.wallet) {
@@ -387,8 +401,13 @@ export default class Integration extends EventEmitter {
387401
state.wallet
388402
.signTransaction(tx)
389403
.then(_response => {
404+
405+
if(!transactionCache.includes(_response.tx.hash)){
406+
transactionCache.push(_response.tx.hash)
407+
390408
this.popUpHandler.showNoticePersistentExit();
391409
resolve(_response);
410+
}
392411
})
393412
.catch(err => {
394413
this.popUpHandler.showNoticePersistentExit();

‎src/connectProvider/web3Provider/web3-provider/methods/eth_sendTransaction.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export default async (
6262
res(e);
6363
return;
6464
}
65+
debug('RAW TX', tx);
6566
getSanitizedTx(tx)
6667
.then(_tx => {
6768
debug('TX', _tx);
@@ -88,18 +89,25 @@ export default async (
8889
};
8990
if (store.noSubs) {
9091
const txHash = hash;
92+
const start = Date.now();
9193
const interval = setInterval(() => {
9294
store.state.web3.eth
9395
.getTransactionReceipt(txHash)
9496
.then(result => {
9597
if (result !== null) {
9698
clearInterval(interval);
9799
_promiObj.emit('receipt', res);
100+
return;
101+
}
102+
const cancelInterval =
103+
(Date.now() - start) / 1000 > 60 * 60;
104+
if (cancelInterval) {
105+
clearInterval(interval);
98106
}
99107
})
100108
.catch(err => {
101109
_promiObj.emit('error', err);
102-
})
110+
});
103111
}, 1000);
104112
}
105113
}

‎src/connectWindow/messageCreator.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export function getMessage(text, extra) {
22
const messages = {
3-
decline: 'User declined action in MEW wallet app',
3+
decline: 'User declined action in MEW wallet app',
44
approveTx: 'Check your phone to approve transaction ',
55
disconnect: 'Disconnected from MEW wallet',
66
complete: 'Transaction completed',
@@ -11,7 +11,8 @@ export function getMessage(text, extra) {
1111
notConnected:
1212
'Phone not connected. Please connect your phone and try again',
1313
defaultMessage: 'Check your phone to continue',
14-
error: 'An error occurred while preparing the last action'
14+
error: 'An error occurred while preparing the last action',
15+
communicationError: 'Could not complete last response from MEW wallet. Nothing was sent. Please try to send or sign again.'
1516
};
1617

1718
if (extra) {

‎src/messageConstants.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const messages = {
88
signMessage: 'signMessage',
99
error: 'error',
1010
notConnected: 'notConnected',
11-
declineMessage: 'declineSignMessage'
11+
declineMessage: 'declineSignMessage',
12+
communicationError: 'communicationError'
1213
};
1314

1415
export default messages;

0 commit comments

Comments
 (0)
Please sign in to comment.