forked from terra-money/wormhole
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I3075380313f10fdb579a4b777e0f10506e7e1ede
- Loading branch information
Showing
18 changed files
with
2,151 additions
and
275 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -1,59 +1,34 @@ | ||
import Wallet from "@project-serum/sol-wallet-adapter"; | ||
import React, { | ||
ReactChildren, | ||
useCallback, | ||
useContext, | ||
useMemo, | ||
useState, | ||
} from "react"; | ||
import { SOLANA_HOST } from "../utils/consts"; | ||
import { WalletDialogProvider } from "@solana/wallet-adapter-material-ui"; | ||
import { useWallet, WalletProvider } from "@solana/wallet-adapter-react"; | ||
import { | ||
getPhantomWallet, | ||
getSolletWallet, | ||
} from "@solana/wallet-adapter-wallets"; | ||
import React, { FC, useMemo } from "react"; | ||
|
||
interface ISolanaWalletContext { | ||
connect(): void; | ||
disconnect(): void; | ||
connected: boolean; | ||
wallet: Wallet | undefined; | ||
} | ||
|
||
const SolanaWalletContext = React.createContext<ISolanaWalletContext>({ | ||
connect: () => {}, | ||
disconnect: () => {}, | ||
connected: false, | ||
wallet: undefined, | ||
}); | ||
export const SolanaWalletProvider = ({ | ||
children, | ||
}: { | ||
children: ReactChildren; | ||
}) => { | ||
const [wallet, setWallet] = useState<Wallet | undefined>(undefined); | ||
const [connected, setConnected] = useState(false); | ||
const connect = useCallback(() => { | ||
const wallet = new Wallet("https://www.sollet.io", SOLANA_HOST); | ||
setWallet(wallet); | ||
wallet.on("connect", () => { | ||
setConnected(true); | ||
}); | ||
wallet.on("disconnect", () => { | ||
console.log("disconnected"); | ||
setConnected(false); | ||
setWallet(undefined); | ||
}); | ||
wallet.connect(); | ||
export const SolanaWalletProvider: FC = (props) => { | ||
// @solana/wallet-adapter-wallets includes all the adapters but supports tree shaking -- | ||
// Only the wallets you want to instantiate here will be compiled into your application | ||
const wallets = useMemo(() => { | ||
console.log("running wallets memo again"); | ||
return [ | ||
getPhantomWallet(), | ||
// getSolflareWallet(), | ||
// getTorusWallet({ | ||
// options: { clientId: 'Go to https://developer.tor.us and create a client ID' } | ||
// }), | ||
// getLedgerWallet(), | ||
// getSolongWallet(), | ||
// getMathWallet(), | ||
getSolletWallet(), | ||
]; | ||
}, []); | ||
const disconnect = useCallback(() => { | ||
wallet?.disconnect(); | ||
}, [wallet]); | ||
const contextValue = useMemo( | ||
() => ({ connect, disconnect, connected, wallet }), | ||
[connect, disconnect, wallet, connected] | ||
); | ||
|
||
return ( | ||
<SolanaWalletContext.Provider value={contextValue}> | ||
{children} | ||
</SolanaWalletContext.Provider> | ||
<WalletProvider wallets={wallets}> | ||
<WalletDialogProvider>{props.children}</WalletDialogProvider> | ||
</WalletProvider> | ||
); | ||
}; | ||
export const useSolanaWallet = () => { | ||
return useContext(SolanaWalletContext); | ||
}; | ||
|
||
export const useSolanaWallet = useWallet; |
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.