-
Notifications
You must be signed in to change notification settings - Fork 57
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 #44 from NearSocial/support-ethers-js
- Support `ethers.js` based on NearSocial/viewer#130 - Expose `Ethers` and `ethers` in the global scope. - Add custom `Web3Connect` component that renders Web3 connect/disconnect button. Currently, the API is heavily influenced by Web3Onboard API. - VM now exports `EthersProviderContext` React context type. A gateway that wants to support Ethers.js should wrap the app with `EthersProviderContext.Provider` component with the object value `{provider}`. Provider is Web3 provider that can be used to create an Ethers.js provider.
- Loading branch information
Showing
10 changed files
with
502 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { useContext } from "react"; | ||
|
||
export const EthersProviderContext = React.createContext(null); | ||
|
||
export const Web3ConnectButton = (props) => { | ||
const ethersProviderContext = useContext(EthersProviderContext); | ||
const [{ wallet, connecting }, connect, disconnect] = | ||
ethersProviderContext?.useConnectWallet | ||
? ethersProviderContext?.useConnectWallet() | ||
: [{}]; | ||
|
||
return ( | ||
<button | ||
className={`btn ${props.className} ${ | ||
connecting || wallet ? "btn-outline-secondary" : "btn-outline-primary" | ||
}`} | ||
disabled={(wallet ? !disconnect : !connect) || connecting} | ||
onClick={() => (wallet ? disconnect?.(wallet) : connect?.())} | ||
> | ||
{connecting | ||
? props.connectingLabel ?? "Connecting" | ||
: wallet | ||
? props.disconnectLabel ?? "Disconnect Web3 Wallet" | ||
: props.connectLabel ?? "Connect Web3 Wallet"} | ||
</button> | ||
); | ||
}; |
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.