Merge pull request #1434 from 0xProject/fix/instant/signature-denied
[instant] fix signature denial error message and add trust wallet detection
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
[
|
||||
{
|
||||
"version": "4.1.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add support for Trust Wallet signature denial error"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "4.1.3",
|
||||
"changes": [
|
||||
|
||||
@@ -14,5 +14,6 @@ export const constants = {
|
||||
ZERO_AMOUNT: new BigNumber(0),
|
||||
ONE_AMOUNT: new BigNumber(1),
|
||||
ETHER_TOKEN_DECIMALS: 18,
|
||||
USER_DENIED_SIGNATURE_PATTERN: 'User denied transaction signature',
|
||||
METAMASK_USER_DENIED_SIGNATURE_PATTERN: 'User denied transaction signature',
|
||||
TRUST_WALLET_USER_DENIED_SIGNATURE_PATTERN: 'cancelled',
|
||||
};
|
||||
|
||||
@@ -30,7 +30,10 @@ const schemaErrorTransformer = (error: Error) => {
|
||||
};
|
||||
|
||||
const signatureRequestErrorTransformer = (error: Error) => {
|
||||
if (_.includes(error.message, constants.USER_DENIED_SIGNATURE_PATTERN)) {
|
||||
if (
|
||||
_.includes(error.message, constants.METAMASK_USER_DENIED_SIGNATURE_PATTERN) ||
|
||||
_.includes(error.message, constants.TRUST_WALLET_USER_DENIED_SIGNATURE_PATTERN)
|
||||
) {
|
||||
const errMsg = ContractWrappersError.SignatureRequestDenied;
|
||||
return new Error(errMsg);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { WEB_3_WRAPPER_TRANSACTION_FAILED_ERROR_MSG_PREFIX } from '../constants'
|
||||
import { ColorOption } from '../style/theme';
|
||||
import { AffiliateInfo, Asset, ZeroExInstantError } from '../types';
|
||||
import { analytics } from '../util/analytics';
|
||||
import { errorReporter } from '../util/error_reporter';
|
||||
import { gasPriceEstimator } from '../util/gas_price_estimator';
|
||||
import { util } from '../util/util';
|
||||
|
||||
@@ -82,13 +83,18 @@ export class BuyButton extends React.Component<BuyButtonProps> {
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
if (e.message === AssetBuyerError.SignatureRequestDenied) {
|
||||
if (e.message === AssetBuyerError.TransactionValueTooLow) {
|
||||
analytics.trackBuySimulationFailed(buyQuote);
|
||||
this.props.onValidationFail(buyQuote, AssetBuyerError.TransactionValueTooLow);
|
||||
return;
|
||||
} else if (e.message === AssetBuyerError.SignatureRequestDenied) {
|
||||
analytics.trackBuySignatureDenied(buyQuote);
|
||||
this.props.onSignatureDenied(buyQuote);
|
||||
return;
|
||||
} else if (e.message === AssetBuyerError.TransactionValueTooLow) {
|
||||
analytics.trackBuySimulationFailed(buyQuote);
|
||||
this.props.onValidationFail(buyQuote, AssetBuyerError.TransactionValueTooLow);
|
||||
} else {
|
||||
errorReporter.report(e);
|
||||
analytics.trackBuyUnknownError(buyQuote, e.message);
|
||||
this.props.onValidationFail(buyQuote, ZeroExInstantError.CouldNotSubmitTransaction);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,5 +72,6 @@ export const PROVIDER_TYPE_TO_NAME: { [key in ProviderType]: string } = {
|
||||
[ProviderType.Mist]: 'Mist',
|
||||
[ProviderType.CoinbaseWallet]: 'Coinbase Wallet',
|
||||
[ProviderType.Parity]: 'Parity',
|
||||
[ProviderType.TrustWallet]: 'Trust Wallet',
|
||||
[ProviderType.Fallback]: 'Fallback',
|
||||
};
|
||||
|
||||
@@ -95,6 +95,9 @@ const mapDispatchToProps = (
|
||||
if (error === ZeroExInstantError.InsufficientETH) {
|
||||
const errorMessage = "You don't have enough ETH";
|
||||
errorFlasher.flashNewErrorMessage(dispatch, errorMessage);
|
||||
} else if (error === ZeroExInstantError.CouldNotSubmitTransaction) {
|
||||
const errorMessage = 'Could not submit transaction';
|
||||
errorFlasher.flashNewErrorMessage(dispatch, errorMessage);
|
||||
} else {
|
||||
errorFlasher.flashNewErrorMessage(dispatch);
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ export enum Network {
|
||||
export enum ZeroExInstantError {
|
||||
AssetMetaDataNotAvailable = 'ASSET_META_DATA_NOT_AVAILABLE',
|
||||
InsufficientETH = 'INSUFFICIENT_ETH',
|
||||
CouldNotSubmitTransaction = 'COULD_NOT_SUBMIT_TRANSACTION',
|
||||
}
|
||||
|
||||
export type SimpleHandler = () => void;
|
||||
@@ -181,6 +182,7 @@ export enum ProviderType {
|
||||
Mist = 'MIST',
|
||||
CoinbaseWallet = 'COINBASE_WALLET',
|
||||
Cipher = 'CIPHER',
|
||||
TrustWallet = 'TRUST_WALLET',
|
||||
Fallback = 'FALLBACK',
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ enum EventNames {
|
||||
BUY_STARTED = 'Buy - Started',
|
||||
BUY_SIGNATURE_DENIED = 'Buy - Signature Denied',
|
||||
BUY_SIMULATION_FAILED = 'Buy - Simulation Failed',
|
||||
BUY_UNKNOWN_ERROR = 'Buy - Unknown Error',
|
||||
BUY_TX_SUBMITTED = 'Buy - Tx Submitted',
|
||||
BUY_TX_SUCCEEDED = 'Buy - Tx Succeeded',
|
||||
BUY_TX_FAILED = 'Buy - Tx Failed',
|
||||
@@ -189,6 +190,11 @@ export const analytics = {
|
||||
trackingEventFnWithPayload(EventNames.BUY_SIGNATURE_DENIED)(buyQuoteEventProperties(buyQuote)),
|
||||
trackBuySimulationFailed: (buyQuote: BuyQuote) =>
|
||||
trackingEventFnWithPayload(EventNames.BUY_SIMULATION_FAILED)(buyQuoteEventProperties(buyQuote)),
|
||||
trackBuyUnknownError: (buyQuote: BuyQuote, errorMessage: string) =>
|
||||
trackingEventFnWithPayload(EventNames.BUY_UNKNOWN_ERROR)({
|
||||
...buyQuoteEventProperties(buyQuote),
|
||||
errorMessage,
|
||||
}),
|
||||
trackBuyTxSubmitted: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) =>
|
||||
trackingEventFnWithPayload(EventNames.BUY_TX_SUBMITTED)({
|
||||
...buyQuoteEventProperties(buyQuote),
|
||||
|
||||
@@ -44,6 +44,8 @@ export const envUtil = {
|
||||
getProviderType(provider: Provider): ProviderType | undefined {
|
||||
if (provider.constructor.name === 'EthereumProvider') {
|
||||
return ProviderType.Mist;
|
||||
} else if ((provider as any).isTrust) {
|
||||
return ProviderType.TrustWallet;
|
||||
} else if ((provider as any).isParity) {
|
||||
return ProviderType.Parity;
|
||||
} else if ((provider as any).isMetaMask) {
|
||||
|
||||
Reference in New Issue
Block a user