Identify the Safe web3 provider
This commit is contained in:
parent
a5db2d4ed6
commit
bbc738d29c
|
@ -12,6 +12,7 @@ export const ETHEREUM_NETWORK = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WALLET_PROVIDER = {
|
export const WALLET_PROVIDER = {
|
||||||
|
SAFE: 'SAFE',
|
||||||
METAMASK: 'METAMASK',
|
METAMASK: 'METAMASK',
|
||||||
PARITY: 'PARITY',
|
PARITY: 'PARITY',
|
||||||
REMOTE: 'REMOTE',
|
REMOTE: 'REMOTE',
|
||||||
|
@ -36,12 +37,23 @@ export const openTxInEtherScan = (tx: string, network: string) => `https://${net
|
||||||
export const getEtherScanLink = (address: string, network: string) => `https://${network}.etherscan.io/address/${address}`
|
export const getEtherScanLink = (address: string, network: string) => `https://${network}.etherscan.io/address/${address}`
|
||||||
|
|
||||||
let web3
|
let web3
|
||||||
export const getWeb3 = () => web3 || new Web3(window.web3.currentProvider)
|
export const getWeb3 = () => web3
|
||||||
|
|
||||||
const isMetamask: Function = (web3Provider): boolean => {
|
const getProviderName: Function = (web3Provider): boolean => {
|
||||||
const isMetamaskConstructor = web3Provider.currentProvider.constructor.name === 'MetamaskInpageProvider'
|
let name
|
||||||
|
|
||||||
return isMetamaskConstructor || web3Provider.currentProvider.isMetaMask
|
switch (web3Provider.currentProvider.constructor.name) {
|
||||||
|
case 'SafeWeb3Provider':
|
||||||
|
name = WALLET_PROVIDER.SAFE
|
||||||
|
break
|
||||||
|
case 'MetamaskInpageProvider':
|
||||||
|
name = WALLET_PROVIDER.METAMASK
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
name = 'UNKNOWN'
|
||||||
|
}
|
||||||
|
|
||||||
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAccountFrom: Function = async (web3Provider): Promise<string | null> => {
|
const getAccountFrom: Function = async (web3Provider): Promise<string | null> => {
|
||||||
|
@ -76,7 +88,7 @@ export const getProviderInfo: Function = async (): Promise<ProviderProps> => {
|
||||||
|
|
||||||
web3 = new Web3(web3Provider)
|
web3 = new Web3(web3Provider)
|
||||||
|
|
||||||
const name = isMetamask(web3) ? WALLET_PROVIDER.METAMASK : 'UNKNOWN'
|
const name = getProviderName(web3)
|
||||||
const account = await getAccountFrom(web3)
|
const account = await getAccountFrom(web3)
|
||||||
const network = await getNetworkIdFrom(web3)
|
const network = await getNetworkIdFrom(web3)
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,19 @@ const FrameDecorator = story => <div className={styles.frame}>{story()}</div>
|
||||||
|
|
||||||
storiesOf('Routes /welcome', module)
|
storiesOf('Routes /welcome', module)
|
||||||
.addDecorator(FrameDecorator)
|
.addDecorator(FrameDecorator)
|
||||||
|
.add('Welcome with Gnosis Safe connected', () => {
|
||||||
|
const provider = select('Status by Provider', ['', 'UNKNOWN', 'SAFE', 'METAMASK', 'PARITY'], 'SAFE')
|
||||||
|
return <Component provider={provider} fetchProvider={() => {}} />
|
||||||
|
})
|
||||||
.add('Welcome with Metamask connected', () => {
|
.add('Welcome with Metamask connected', () => {
|
||||||
const provider = select('Status by Provider', ['', 'UNKNOWN', 'METAMASK', 'PARITY'], 'METAMASK')
|
const provider = select('Status by Provider', ['', 'UNKNOWN', 'SAFE', 'METAMASK', 'PARITY'], 'METAMASK')
|
||||||
return <Component provider={provider} fetchProvider={() => {}} />
|
return <Component provider={provider} fetchProvider={() => {}} />
|
||||||
})
|
})
|
||||||
.add('Welcome with unknown wallet', () => {
|
.add('Welcome with unknown wallet', () => {
|
||||||
const provider = select('Status by Provider', ['', 'UNKNOWN', 'METAMASK', 'PARITY'], 'UNKNOWN')
|
const provider = select('Status by Provider', ['', 'UNKNOWN', 'SAFE', 'METAMASK', 'PARITY'], 'UNKNOWN')
|
||||||
return <Component provider={provider} fetchProvider={() => {}} />
|
return <Component provider={provider} fetchProvider={() => {}} />
|
||||||
})
|
})
|
||||||
.add('Welcome without wallet connected', () => {
|
.add('Welcome without wallet connected', () => {
|
||||||
const provider = select('Status by Provider', ['', 'UNKNOWN', 'METAMASK', 'PARITY'], '')
|
const provider = select('Status by Provider', ['', 'UNKNOWN', 'SAFE', 'METAMASK', 'PARITY'], '')
|
||||||
return <Component provider={provider} fetchProvider={() => {}} />
|
return <Component provider={provider} fetchProvider={() => {}} />
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue