-
Notifications
You must be signed in to change notification settings - Fork 5
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 #437 from galacticcouncil/master
master -> rococo
- Loading branch information
Showing
26 changed files
with
1,291 additions
and
76 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
73 changes: 73 additions & 0 deletions
73
src/components/WalletConnectProvider/WalletConnectProvider.tsx
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,73 @@ | ||
import { createContext, useContext, useEffect, useState } from "react" | ||
import { | ||
BaseWallet, | ||
WalletAggregator, | ||
WalletConnect, | ||
} from "utils/walletConnect" | ||
|
||
const walletConnectParams = { | ||
projectId: import.meta.env.VITE_WC_PROJECT_ID, | ||
relayUrl: "wss://relay.walletconnect.com", | ||
metadata: { | ||
name: "Basilisk", | ||
description: "Basilisk", | ||
url: import.meta.env.VITE_DOMAIN_URL, | ||
icons: ["https://walletconnect.com/walletconnect-logo.png"], | ||
}, | ||
} | ||
|
||
const walletAggregator = new WalletAggregator( | ||
new WalletConnect(walletConnectParams, "Basilisk"), | ||
) | ||
|
||
type OnboardProviderProps = { children: JSX.Element } | ||
|
||
interface PolkadotWalletsContextProviderProps { | ||
children: JSX.Element | ||
walletAggregator: WalletAggregator | ||
initialWaitMs?: number | ||
} | ||
|
||
interface PolkadotWalletsContextProps { | ||
wallet: BaseWallet | undefined | ||
} | ||
|
||
const PolkadotWalletsContext = createContext<PolkadotWalletsContextProps>({ | ||
wallet: undefined, | ||
}) | ||
|
||
export const useWalletConnect = () => useContext(PolkadotWalletsContext) | ||
|
||
const PolkadotWalletsContextProvider = ({ | ||
children, | ||
walletAggregator, | ||
initialWaitMs = 5 /* the default is set to 5ms to give extensions enough lead time to inject their providers */, | ||
}: PolkadotWalletsContextProviderProps) => { | ||
const [wallet, setWallet] = useState<BaseWallet | undefined>() | ||
|
||
useEffect(() => { | ||
const timeoutId = setTimeout(async () => { | ||
const wallet = walletAggregator.getWallet() | ||
const isWalletConnected = walletAggregator.getWallet().isConnected() | ||
|
||
if (!isWalletConnected) wallet.autoConnect() | ||
|
||
setWallet(wallet) | ||
}, initialWaitMs) | ||
return () => clearTimeout(timeoutId) | ||
}, [walletAggregator, initialWaitMs]) | ||
|
||
return ( | ||
<PolkadotWalletsContext.Provider value={{ wallet }}> | ||
{children} | ||
</PolkadotWalletsContext.Provider> | ||
) | ||
} | ||
|
||
export const WalletConnectProvider = ({ children }: OnboardProviderProps) => { | ||
return ( | ||
<PolkadotWalletsContextProvider walletAggregator={walletAggregator}> | ||
{children} | ||
</PolkadotWalletsContextProvider> | ||
) | ||
} |
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
Oops, something went wrong.