Add flash message instructing user to confirm tx on Ledger

This commit is contained in:
Fabio Berger 2018-01-29 12:45:50 +01:00
parent 52394884da
commit 609342be7a

View File

@ -247,6 +247,7 @@ export class Blockchain {
utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses); utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses);
utils.assert(!_.isUndefined(this._zeroEx), 'ZeroEx must be instantiated.'); utils.assert(!_.isUndefined(this._zeroEx), 'ZeroEx must be instantiated.');
this._showFlashMessageIfLedger();
const txHash = await this._zeroEx.token.setProxyAllowanceAsync( const txHash = await this._zeroEx.token.setProxyAllowanceAsync(
token.address, token.address,
this._userAddress, this._userAddress,
@ -256,6 +257,7 @@ export class Blockchain {
const allowance = amountInBaseUnits; const allowance = amountInBaseUnits;
} }
public async transferAsync(token: Token, toAddress: string, amountInBaseUnits: BigNumber): Promise<void> { public async transferAsync(token: Token, toAddress: string, amountInBaseUnits: BigNumber): Promise<void> {
this._showFlashMessageIfLedger();
const txHash = await this._zeroEx.token.transferAsync( const txHash = await this._zeroEx.token.transferAsync(
token.address, token.address,
this._userAddress, this._userAddress,
@ -312,6 +314,7 @@ export class Blockchain {
const shouldThrowOnInsufficientBalanceOrAllowance = true; const shouldThrowOnInsufficientBalanceOrAllowance = true;
this._showFlashMessageIfLedger();
const txHash = await this._zeroEx.exchange.fillOrderAsync( const txHash = await this._zeroEx.exchange.fillOrderAsync(
signedOrder, signedOrder,
fillTakerTokenAmount, fillTakerTokenAmount,
@ -327,6 +330,7 @@ export class Blockchain {
return filledTakerTokenAmount; return filledTakerTokenAmount;
} }
public async cancelOrderAsync(signedOrder: SignedOrder, cancelTakerTokenAmount: BigNumber): Promise<BigNumber> { public async cancelOrderAsync(signedOrder: SignedOrder, cancelTakerTokenAmount: BigNumber): Promise<BigNumber> {
this._showFlashMessageIfLedger();
const txHash = await this._zeroEx.exchange.cancelOrderAsync(signedOrder, cancelTakerTokenAmount); const txHash = await this._zeroEx.exchange.cancelOrderAsync(signedOrder, cancelTakerTokenAmount);
const receipt = await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash); const receipt = await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash);
const logs: Array<LogWithDecodedArgs<ExchangeContractEventArgs>> = receipt.logs as any; const logs: Array<LogWithDecodedArgs<ExchangeContractEventArgs>> = receipt.logs as any;
@ -399,6 +403,7 @@ export class Blockchain {
if (_.isUndefined(makerAddress)) { if (_.isUndefined(makerAddress)) {
throw new Error('Tried to send a sign request but user has no associated addresses'); throw new Error('Tried to send a sign request but user has no associated addresses');
} }
this._showFlashMessageIfLedger();
const ecSignature = await this._zeroEx.signOrderHashAsync(orderHash, makerAddress); const ecSignature = await this._zeroEx.signOrderHashAsync(orderHash, makerAddress);
const signatureData = _.extend({}, ecSignature, { const signatureData = _.extend({}, ecSignature, {
hash: orderHash, hash: orderHash,
@ -410,6 +415,7 @@ export class Blockchain {
utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses); utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses);
const mintableContract = await this._instantiateContractIfExistsAsync(MintableArtifacts, token.address); const mintableContract = await this._instantiateContractIfExistsAsync(MintableArtifacts, token.address);
this._showFlashMessageIfLedger();
await mintableContract.mint(constants.MINT_AMOUNT, { await mintableContract.mint(constants.MINT_AMOUNT, {
from: this._userAddress, from: this._userAddress,
}); });
@ -423,6 +429,7 @@ export class Blockchain {
utils.assert(!_.isUndefined(this._zeroEx), 'ZeroEx must be instantiated.'); utils.assert(!_.isUndefined(this._zeroEx), 'ZeroEx must be instantiated.');
utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses); utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses);
this._showFlashMessageIfLedger();
const txHash = await this._zeroEx.etherToken.depositAsync(etherTokenAddress, amount, this._userAddress); const txHash = await this._zeroEx.etherToken.depositAsync(etherTokenAddress, amount, this._userAddress);
await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash); await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash);
} }
@ -430,6 +437,7 @@ export class Blockchain {
utils.assert(!_.isUndefined(this._zeroEx), 'ZeroEx must be instantiated.'); utils.assert(!_.isUndefined(this._zeroEx), 'ZeroEx must be instantiated.');
utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses); utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses);
this._showFlashMessageIfLedger();
const txHash = await this._zeroEx.etherToken.withdrawAsync(etherTokenAddress, amount, this._userAddress); const txHash = await this._zeroEx.etherToken.withdrawAsync(etherTokenAddress, amount, this._userAddress);
await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash); await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash);
} }
@ -766,4 +774,9 @@ export class Blockchain {
} }
} }
} }
private _showFlashMessageIfLedger() {
if (!_.isUndefined(this._ledgerSubprovider)) {
this._dispatcher.showFlashMessage('Confirm the transaction on your Ledger Nano S');
}
}
} // tslint:disable:max-file-line-count } // tslint:disable:max-file-line-count