Skip to content

Commit 6e94065

Browse files
authored
Merge pull request #169 from poanetwork/develop-1.x
Merge the develop-1.x branch to the master-1.x branch
2 parents 9651de4 + 449a5cb commit 6e94065

File tree

5 files changed

+43
-26
lines changed

5 files changed

+43
-26
lines changed

src/components/Bridge.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ export class Bridge extends React.Component {
187187
await this._sendToHome(amount)
188188
}
189189
} catch(e) {
190-
alertStore.setLoading(false)
190+
if(!e.message.includes('not mined within 50 blocks') && !e.message.includes('Failed to subscribe to new newBlockHeaders')) {
191+
alertStore.setLoading(false)
192+
}
191193
}
192194
}
193195

src/components/Loading.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class Loading extends React.Component {
1919
stroke={ 4 }
2020
progress={progress}
2121
confirmationNumber={blockConfirmations}
22+
hideConfirmationNumber={loadingStepIndex > 1}
2223
/>}
2324
{loadingStepIndex === 0 && (<img className="loading" src={loadingLogo} alt="loading"/>)}
2425
{loadingStepIndex === 0 && <div className="loading-i" />}

src/components/ProgressRing.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ export class ProgressRing extends Component {
77
}
88

99
render() {
10-
const { radius, stroke, progress, confirmationNumber } = this.props
10+
const { radius, stroke, progress, confirmationNumber, hideConfirmationNumber } = this.props
1111
const { circumference, normalizedRadius } = this.state
1212
const strokeDashoffset = circumference - progress / 100 * circumference
13+
const confirmations = hideConfirmationNumber ? '' : `${confirmationNumber}/8`
1314
return (
1415
<svg
1516
height={radius * 2}
@@ -36,7 +37,7 @@ export class ProgressRing extends Component {
3637
cy={ radius }
3738
/>
3839
<text x="28" y="47" fontFamily="Nunito" fontSize="18" fill="white">
39-
{confirmationNumber}/8
40+
{confirmations}
4041
</text>
4142
</svg>
4243
);

src/stores/TxStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TxStore {
3939
addPendingTransaction()
4040
this.getTxReceipt(hash)
4141
}).on('error', (e) => {
42-
if(!e.message.includes('not mined within 50 blocks')){
42+
if(!e.message.includes('not mined within 50 blocks') && !e.message.includes('Failed to subscribe to new newBlockHeaders')){
4343
this.alertStore.setLoading(false)
4444
this.alertStore.pushError('Transaction rejected on Metamask');
4545
}

src/stores/utils/web3.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,24 @@ import Web3Utils from 'web3-utils'
44
const getWeb3 = () => {
55
return new Promise(function (resolve, reject) {
66
// Wait for loading completion to avoid race conditions with web3 injection timing.
7-
window.addEventListener('load', function () {
7+
window.addEventListener('load',async function () {
88
let web3 = window.web3
9+
const { ethereum } = window
910

10-
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
11-
if (typeof web3 !== 'undefined') {
12-
// Use Mist/MetaMask's provider.
11+
if (ethereum) {
12+
web3 = new window.Web3(ethereum)
13+
try {
14+
// Request account access
15+
await ethereum.enable()
16+
processWeb3(web3, resolve, reject)
17+
} catch (error) {
18+
console.log(error)
19+
const errorMsg = `Wallet account rejected by user`
20+
reject({message: errorMsg})
21+
}
22+
} else if (typeof web3 !== 'undefined') {
1323
web3 = new window.Web3(web3.currentProvider)
14-
web3.version.getNetwork((err, netId) => {
15-
const netIdName = getNetworkName(netId)
16-
console.log(`This is ${netIdName} network.`, netId)
17-
document.title = `${netIdName} - Bridge UI dApp`
18-
const defaultAccount = web3.eth.defaultAccount || null;
19-
if(defaultAccount === null){
20-
reject({message: 'Please unlock your metamask and refresh the page'})
21-
}
22-
const results = {
23-
web3Instance: new Web3(web3.currentProvider),
24-
netIdName,
25-
netId,
26-
injectedWeb3: true,
27-
defaultAccount
28-
}
29-
resolve(results)
30-
})
31-
24+
processWeb3(web3, resolve, reject)
3225
} else {
3326
// Fallback to localhost if no web3 injection.
3427
const errorMsg = `Metamask is not installed. Please go to
@@ -94,3 +87,23 @@ export const estimateGas = async (web3, to, gasPrice, from, value, data) =>{
9487
}
9588

9689
export const getGasPrices = () => fetch('https://gasprice.poa.network/').then(response => response.json())
90+
91+
const processWeb3 = (web3, resolve, reject) => {
92+
web3.version.getNetwork((err, netId) => {
93+
const netIdName = getNetworkName(netId)
94+
console.log(`This is ${netIdName} network.`, netId)
95+
document.title = `${netIdName} - Bridge UI dApp`
96+
const defaultAccount = web3.eth.defaultAccount || null;
97+
if(defaultAccount === null){
98+
reject({message: 'Please unlock your wallet and refresh the page'})
99+
}
100+
const results = {
101+
web3Instance: new Web3(web3.currentProvider),
102+
netIdName,
103+
netId,
104+
injectedWeb3: true,
105+
defaultAccount
106+
}
107+
resolve(results)
108+
})
109+
}

0 commit comments

Comments
 (0)