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