on a54b5ac help sign in
bridge/src/lib/error.js
45 lines 1.5 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_MNEMONIC: new Error('no authentication mnemonic found'),
8 MISSING_URBIT_WALLET: new Error('no urbit wallet found'),
9 MISSING_POINT: new Error('no point found'),
10 INVALID_ROUTE: new Error('invalid route'),
11 INVALID_NETWORK_TYPE: new Error('invalid network type'),
12 INVALID_WALLET_TYPE: new Error('invalid wallet type'),
15const renderTxnError = (web3, msg) => {
16 const txnCost = (web3, msg) => {
17 const costWei = msg.match(/upfront cost is: ([0-9]+)/)
18 const costEth = web3.utils.fromWei(costWei[1], 'ether')
19 return parseFloat(costEth).toFixed(4)
20 }
22 const acctBalance = (web3, msg) => {
23 const balWei = msg.match(/sender's account only has: ([0-9]+)/)
24 const balEth = web3.utils.fromWei(balWei[1], 'ether')
25 return parseFloat(balEth).toFixed(4)
26 }
28 return (
29 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.`
35 : "You may want to verify that the account that has signed the " +
36 "transaction holds sufficient Ether to pay for the gas, and " +
37 "also that you haven't set the gas limit for the transaction " +
38 "too low."
39 )
42export {
43 BRIDGE_ERROR,
44 renderTxnError