on 363a711 help sign in
bridge/src/lib/error.js
40 lines 1.6 kB history raw
1const BRIDGE_ERROR = {
2 MISSING_WEB3: 'no web3 object found',
3 MISSING_WALLET: 'no wallet found',
4 MISSING_TXN: 'no transaction found',
5 MISSING_CONTRACTS: 'no contracts found',
6 MISSING_KEYSTORE: 'no keystore text found',
7 MISSING_MNEMONIC: 'no authentication mnemonic found',
8 MISSING_URBIT_WALLET: 'no urbit wallet found',
9 MISSING_POINT: 'no point found',
10 MISSING_AUTH_MNEMONIC: 'no mnemonic found',
11 MISSING_POINT_DETAILS: 'no details of point found',
12 INVALID_ROUTE: 'invalid route',
13 INVALID_NETWORK_TYPE: 'invalid network type',
14 INVALID_WALLET_TYPE: 'invalid wallet type',
15};
17const renderTxnError = (web3, msg) => {
18 const txnCost = (web3, msg) => {
19 const costWei = msg.match(/upfront cost is: ([0-9]+)/);
20 const costEth = web3.utils.fromWei(costWei[1], 'ether');
21 return parseFloat(costEth).toFixed(4);
22 };
24 const acctBalance = (web3, msg) => {
25 const balWei = msg.match(/sender's account only has: ([0-9]+)/);
26 const balEth = web3.utils.fromWei(balWei[1], 'ether');
27 return parseFloat(balEth).toFixed(4);
28 };
30 return msg.includes("doesn't have enough funds")
31 ? "The account doesn't have enough Ether. " +
32 `The up-front transaction cost is ${txnCost(web3, msg)} ETH, but the ` +
33 `account only holds ${acctBalance(web3, msg)} ETH.`
34 : 'You may want to verify that the account that has signed the ' +
35 'transaction holds sufficient Ether to pay for the gas, and ' +
36 "also that you haven't set the gas limit for the transaction " +
37 'too low.';
38};
40export { BRIDGE_ERROR, renderTxnError };