-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from nemmtor/feature/migrate-to-wallet-connect
feat: migrate to wallet connect modal sdk
- Loading branch information
Showing
13 changed files
with
2,394 additions
and
1,217 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 was deleted.
Oops, something went wrong.
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,28 @@ | ||
import { createModal } from "./modal"; | ||
import { | ||
type CombinedProvider, | ||
type Provider, | ||
} from "@web3modal/scaffold-utils/ethers"; | ||
|
||
const modal = createModal(); | ||
|
||
export async function getProvider() { | ||
// web3modal sdk "caches" the connection but we disconnect user on purpose every time he re-visits the page | ||
if (modal.getIsConnected()) { | ||
modal.disconnect(); | ||
} | ||
modal.open(); | ||
|
||
// await for provider event | ||
// TODO: add some timeout so it's not a never ending promise | ||
const provider: CombinedProvider | Provider = await new Promise((res) => { | ||
modal.subscribeProvider((providerEvent) => { | ||
if (providerEvent.isConnected && providerEvent.provider) { | ||
return res(providerEvent.provider); | ||
} | ||
}); | ||
}); | ||
|
||
modal.close(); | ||
return provider; | ||
} |
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,7 @@ | ||
// This file declares types for global variables injected via webpack | ||
// Add more variables here when migrating other files to typescript and seeing type errors. | ||
// TODO: implement better way for injecting environment variables | ||
declare const POLYGON_CHAIN_ID: string; | ||
declare const POLYGON_BLOCK_EXPLORER_ADDRESS: string; | ||
declare const POLYGON_RPC_ENDPOINT: string; | ||
declare const WALLET_CONNECT_ID: string; |
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,25 @@ | ||
// Required by web3modal, it is also visible in Metamask mobile app in confirmation popups etc. | ||
export const metadata = { | ||
name: "IDriss", | ||
description: "IDriss", | ||
url: "https://idriss.xyz/", | ||
icons: ["https://www.idriss.xyz/static/images/IDriss_Logo.svg"], | ||
}; | ||
|
||
// we don't allow to switch chains anyway because the modal is only used for connection purposes but the library still requires at least 1 chain, chain switching is handled internally in our code. | ||
export const chains = [ | ||
{ | ||
chainId: Number(POLYGON_CHAIN_ID), | ||
name: "Polygon", | ||
currency: "MATIC", | ||
explorerUrl: POLYGON_BLOCK_EXPLORER_ADDRESS, | ||
rpcUrl: POLYGON_RPC_ENDPOINT, | ||
}, | ||
]; | ||
|
||
export const desktopFeaturedWalletIds = [ | ||
"cf14642fb8736a99b733ada71863241c823743b16e2a822b3dba24e2fa25014d", | ||
"fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa", | ||
"971e689d0a5be527bac79629b4ee9b925e82208e5168b733496a09c0faed0709", | ||
]; | ||
export const mobileFeaturedWalletIds = []; |
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 @@ | ||
export { createModal } from "./modal"; |
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,15 @@ | ||
import { defaultConfig, createWeb3Modal } from "@web3modal/ethers5"; | ||
|
||
import { metadata, chains } from "./constants"; | ||
import { getFeaturedWalletIds } from "./utils" | ||
|
||
export const createModal = () => { | ||
return createWeb3Modal({ | ||
ethersConfig: defaultConfig({ | ||
metadata, | ||
}), | ||
chains, | ||
featuredWalletIds: getFeaturedWalletIds(), | ||
projectId: WALLET_CONNECT_ID, | ||
}); | ||
}; |
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,7 @@ | ||
import { isDesktop } from "../utils"; | ||
|
||
import { desktopFeaturedWalletIds, mobileFeaturedWalletIds } from "./constants"; | ||
|
||
export const getFeaturedWalletIds = () => { | ||
return isDesktop() ? desktopFeaturedWalletIds : mobileFeaturedWalletIds; | ||
}; |
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.