This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use previously supported wallets (#2166)
* testing * Enable Coinbase Wallet (wallet-link) (#2353) * enable walletlink and upgrade package * Limiting the supported networks for CoinbaseWallet * Adding setDefaultInjected provider * Enable Formatic wallet (#2388) * Activate formatic wallet * Adding reconnect Uninjected Provider * Adding connecting web3Status after refresh * Upgrade fortmatic to v2.2.1 * Mute unnecessary Overlay useEffect * Adding new API 🔑 * Adding custom src/custom/connectors/Fortmaitc.ts * merger conflict resolution * set api key according to environment (#2422) * Change clickable, fortmatic supportedChains, enum DefaultInjected * Change CW deeplink * Testing walletLink on mobile (cherry picked from commit e88eb5e)
- Loading branch information
1 parent
670ecf3
commit ffbbda9
Showing
13 changed files
with
190 additions
and
61 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
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
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
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,56 @@ | ||
import { FortmaticConnector as FortmaticConnectorCore } from '@web3-react/fortmatic-connector' | ||
import { isProd, isBarn } from 'utils/environments' | ||
import { SupportedChainId } from 'constants/chains' | ||
|
||
export const OVERLAY_READY = 'OVERLAY_READY' | ||
|
||
type FormaticSupportedChains = SupportedChainId.MAINNET | SupportedChainId.RINKEBY | ||
|
||
const CHAIN_ID_NETWORK_ARGUMENT: Partial<Record<SupportedChainId, string | undefined>> = { | ||
[SupportedChainId.MAINNET]: undefined, | ||
[SupportedChainId.RINKEBY]: 'rinkeby', | ||
} | ||
|
||
export class FortmaticConnector extends FortmaticConnectorCore { | ||
async activate() { | ||
if (!this.fortmatic) { | ||
const { default: Fortmatic } = await import('fortmatic') | ||
|
||
const { apiKey, chainId } = this as any | ||
if (chainId in CHAIN_ID_NETWORK_ARGUMENT) { | ||
this.fortmatic = new Fortmatic(apiKey, CHAIN_ID_NETWORK_ARGUMENT[chainId as FormaticSupportedChains]) | ||
} else { | ||
throw new Error(`Unsupported network ID: ${chainId}`) | ||
} | ||
} | ||
|
||
const provider = this.fortmatic.getProvider() | ||
|
||
// It is no longer necessary | ||
// const pollForOverlayReady = new Promise<void>((resolve) => { | ||
// const interval = setInterval(() => { | ||
// if (provider.overlay.overlayReady) { | ||
// clearInterval(interval) | ||
// this.emit(OVERLAY_READY) | ||
// resolve() | ||
// } | ||
// }, 200) | ||
// }) | ||
|
||
const account = await provider.enable().then((accounts: string[]) => accounts[0]) | ||
|
||
return { provider: this.fortmatic.getProvider(), chainId: (this as any).chainId, account } | ||
} | ||
} | ||
|
||
// Allows to select fortmatic envvar according to prod, barn or test environment | ||
export function getFortmaticApiKey(): string | undefined { | ||
let apiKey = process.env.REACT_APP_FORTMATIC_KEY | ||
if (isProd) { | ||
apiKey = process.env.REACT_APP_FORTMATIC_KEY_PROD | ||
} else if (isBarn) { | ||
apiKey = process.env.REACT_APP_FORTMATIC_KEY_BARN | ||
} | ||
|
||
return apiKey | ||
} |
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
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
Oops, something went wrong.