generated from edenia/webapp-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a fail over endpoint for the nodeos
- Loading branch information
Showing
4 changed files
with
89 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,20 @@ | ||
import { Scatter } from 'ual-scatter' | ||
import { Ledger } from 'ual-ledger' | ||
import { Lynx } from 'ual-lynx' | ||
import { TokenPocket } from 'ual-token-pocket' | ||
import { MeetOne } from 'ual-meetone' | ||
import { Anchor } from 'ual-anchor' | ||
|
||
const appName = process.env.REACT_APP_EOS_APP_NAME || 'evodex.io' | ||
const network = { | ||
export const ualConfig = { | ||
appName: process.env.REACT_APP_EOS_APP_NAME || 'evodex.io', | ||
blockExplorerUrl: process.env.REACT_APP_EOS_BLOCK_EXPLORER_URL, | ||
chainId: | ||
process.env.REACT_APP_EOS_CHAIN_ID || | ||
'e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473', | ||
rpcEndpoints: [ | ||
{ | ||
blockchain: 'eos', | ||
protocol: process.env.REACT_APP_EOS_API_PROTOCOL || 'https', | ||
host: process.env.REACT_APP_EOS_API_HOST || 'jungle.eosio.cr', | ||
port: parseInt(process.env.REACT_APP_EOS_API_PORT || '443') | ||
} | ||
] | ||
} | ||
const authenticators = [ | ||
new Lynx([network]), | ||
new Ledger([network]), | ||
new Scatter([network], { appName }), | ||
new TokenPocket([network.chainId]), | ||
new MeetOne([network.chainId]), | ||
new Anchor([network], { appName }) | ||
] | ||
|
||
export const ualConfig = { | ||
appName, | ||
network, | ||
authenticators, | ||
blockExplorerUrl: process.env.REACT_APP_EOS_BLOCK_EXPLORER_URL | ||
'2a02a0053e5a8cf73a56ba0fda11e4d92e0238a4a2aa74fccf46d5a910746840', | ||
api: { | ||
blockchain: 'eos', | ||
protocol: process.env.REACT_APP_EOS_API_PROTOCOL || 'https', | ||
host: process.env.REACT_APP_EOS_API_HOST || 'jungle.eosio.cr', | ||
port: parseInt(process.env.REACT_APP_EOS_API_PORT || '443') | ||
}, | ||
apiFailover: { | ||
blockchain: 'eos', | ||
protocol: process.env.REACT_APP_EOS_API_PROTOCOL_FAILOVER || 'https', | ||
host: | ||
process.env.REACT_APP_EOS_API_HOST_FAILOVER || 'jungle.eosargentina.io', | ||
port: parseInt(process.env.REACT_APP_EOS_API_PORT_FAILOVER || '443') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Scatter } from 'ual-scatter' | ||
import { Ledger } from 'ual-ledger' | ||
import { Lynx } from 'ual-lynx' | ||
import { TokenPocket } from 'ual-token-pocket' | ||
import { MeetOne } from 'ual-meetone' | ||
import { Anchor } from 'ual-anchor' | ||
|
||
import { ualConfig } from './config' | ||
|
||
export default { | ||
useFailover: false, | ||
init: async function () { | ||
try { | ||
const response = await fetch( | ||
`${ualConfig.api.protocol}://${ualConfig.api.host}/v1/chain/get_info` | ||
) | ||
this.useFailover = response.status !== 200 | ||
} catch (error) { | ||
this.useFailover = true | ||
console.error(error) | ||
} | ||
}, | ||
get appName() { | ||
return ualConfig.appName | ||
}, | ||
get chainId() { | ||
return ualConfig.chainId | ||
}, | ||
get network() { | ||
return { | ||
chainId: this.chainId, | ||
rpcEndpoints: [this.useFailover ? ualConfig.apiFailover : ualConfig.api] | ||
} | ||
}, | ||
get chains() { | ||
return [this.network] | ||
}, | ||
get authenticators() { | ||
return [ | ||
new Lynx([this.network]), | ||
new Ledger([this.network]), | ||
new Scatter([this.network], { appName: this.appName }), | ||
new TokenPocket([this.network.chainId]), | ||
new MeetOne([this.network.chainId]), | ||
new Anchor([this.network], { appName: this.appName }) | ||
] | ||
} | ||
} |