|
1 | 1 | import Web3 from 'web3'
|
2 | 2 | import { fromWei, toHex } from 'web3-utils'
|
3 | 3 |
|
| 4 | +const updateTitle = (networkName = 'No chain specified') => { |
| 5 | + const defaultTitle = 'TokenBridge UI app' |
| 6 | + if (!process.env.REACT_APP_TITLE) { |
| 7 | + document.title = defaultTitle |
| 8 | + } |
| 9 | + else { |
| 10 | + const titleReplaceString = '%c' |
| 11 | + let appTitle = process.env.REACT_APP_TITLE || defaultTitle |
| 12 | + |
| 13 | + if (appTitle.indexOf(titleReplaceString) !== -1) { |
| 14 | + document.title = appTitle.replace(titleReplaceString, networkName) |
| 15 | + } |
| 16 | + else { |
| 17 | + document.title = appTitle |
| 18 | + } |
| 19 | + } |
| 20 | +} |
| 21 | + |
4 | 22 | const getWeb3 = () => {
|
5 | 23 | return new Promise(function (resolve, reject) {
|
6 | 24 | // Wait for loading completion to avoid race conditions with web3 injection timing.
|
7 | 25 | window.addEventListener('load',async function () {
|
8 | 26 | let web3 = window.web3
|
9 | 27 | const { ethereum } = window
|
10 | 28 |
|
| 29 | + updateTitle() |
| 30 | + |
11 | 31 | if (ethereum) {
|
12 | 32 | web3 = new Web3(ethereum)
|
13 | 33 | try {
|
@@ -80,13 +100,18 @@ export const estimateGas = async (web3, to, gasPrice, from, value, data) =>{
|
80 | 100 | const processWeb3 = async (web3, resolve, reject) => {
|
81 | 101 | const netId = await web3.eth.getChainId()
|
82 | 102 | const netIdName = getNetworkName(netId)
|
| 103 | + |
83 | 104 | console.log(`This is ${netIdName} network.`, netId)
|
84 |
| - document.title = `${netIdName} - Bridge UI dApp` |
| 105 | + |
85 | 106 | const accounts = await web3.eth.getAccounts()
|
86 | 107 | const defaultAccount = accounts[0] || null;
|
| 108 | + |
87 | 109 | if(defaultAccount === null){
|
88 | 110 | reject({ type: 'unlock', message: 'Please unlock your wallet and refresh the page' })
|
89 | 111 | }
|
| 112 | + |
| 113 | + updateTitle(netIdName) |
| 114 | + |
90 | 115 | const results = {
|
91 | 116 | web3Instance: new Web3(web3.currentProvider),
|
92 | 117 | netIdName,
|
|
0 commit comments