Skip to content

Commit

Permalink
feat: Update all networks' chain and genesis hash when NetworkService
Browse files Browse the repository at this point in the history
starts up
  • Loading branch information
ashchan committed Nov 15, 2019
1 parent 1979e8a commit a3ccf2d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/neuron-wallet/src/services/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ export default class NetworksService extends Store {
currentNetworkList,
})
Promise.all(currentNetworkList.map(n => {
const core = new Core(n.remote)
return core.rpc
.getBlockchainInfo()
.then(info => info.chain)
.catch(() => '')
.then(chain => ({
if (n.type == NetworkType.Default) {
return n
} else {
const core = new Core(n.remote)
return Promise.all([
core.rpc.getBlockchainInfo(),
core.rpc.getBlockHash('0x0')
]).then(([info, genesisHash]) => ({
...n,
chain,
chain: info.chain,
genesisHash
}))
}
})).then(networkList => {
this.updateAll(networkList)
}).catch((err: Error) => {
Expand Down

0 comments on commit a3ccf2d

Please sign in to comment.