-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Use rainbowkit simply wallet of example
- Loading branch information
Showing
7 changed files
with
458 additions
and
235 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,9 @@ | ||
import { | ||
BSC_CHAIN_ID, | ||
GREEN_CHAIN_ID, | ||
coinbaseWalletConnector, | ||
metaMaskWalletConnector, | ||
trustWalletConnector, | ||
} from '@/config'; | ||
import { | ||
useAccount, | ||
useBalance, | ||
useConnect, | ||
useDisconnect, | ||
useNetwork, | ||
useSwitchNetwork, | ||
} from 'wagmi'; | ||
import { ConnectButton } from '@rainbow-me/rainbowkit'; | ||
|
||
export const WalletInfo = () => { | ||
const { address, connector, isConnected } = useAccount(); | ||
const { connect: metaMaskConnect } = useConnect({ | ||
connector: metaMaskWalletConnector, | ||
}); | ||
const { connect: trustWalletConnect } = useConnect({ | ||
connector: trustWalletConnector, | ||
}); | ||
const { connect: coinbaseWalletConnect } = useConnect({ | ||
connector: coinbaseWalletConnector, | ||
}); | ||
|
||
const { disconnect } = useDisconnect(); | ||
const { chain } = useNetwork(); | ||
const { switchNetwork: switchToGreenField } = useSwitchNetwork({ | ||
chainId: GREEN_CHAIN_ID, | ||
}); | ||
|
||
const { switchNetwork: switchToBSC } = useSwitchNetwork({ | ||
chainId: BSC_CHAIN_ID, | ||
}); | ||
|
||
const balance = useBalance({ | ||
address, | ||
watch: true, | ||
}); | ||
|
||
if (!isConnected) { | ||
return ( | ||
<> | ||
<button onClick={() => metaMaskConnect()}>Connect MetaMask</button> | ||
<button onClick={() => trustWalletConnect()}>Connect trustWallet</button> | ||
<button onClick={() => coinbaseWalletConnect()}>Connect coinbase wallet</button> | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
<div> | ||
<h2>address : {address}</h2> | ||
<h2>connector: {connector?.name} </h2> | ||
<button onClick={() => disconnect()}>Disconnect</button> | ||
</div> | ||
|
||
<h2>change chain chainId {chain?.id}</h2> | ||
<h3>balance: {balance.data?.formatted}</h3> | ||
<button | ||
onClick={() => { | ||
switchToGreenField?.(GREEN_CHAIN_ID); | ||
}} | ||
> | ||
switch to green field | ||
</button> | ||
<br /> | ||
<button | ||
onClick={() => { | ||
switchToBSC?.(BSC_CHAIN_ID); | ||
}} | ||
> | ||
switch to bsc | ||
</button> | ||
<ConnectButton /> | ||
</div> | ||
); | ||
}; |
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,25 +1,43 @@ | ||
import { | ||
coinbaseWalletConnector, | ||
metaMaskWalletConnector, | ||
publicClient, | ||
trustWalletConnector, | ||
webSocketPublicClient, | ||
} from '@/config'; | ||
import { chains, publicClient, webSocketPublicClient } from '@/config'; | ||
import '@/styles/globals.css'; | ||
import { | ||
connectorsForWallets, | ||
getDefaultWallets, | ||
RainbowKitProvider, | ||
} from '@rainbow-me/rainbowkit'; | ||
import '@rainbow-me/rainbowkit/styles.css'; | ||
import { trustWallet } from '@rainbow-me/rainbowkit/wallets'; | ||
import type { AppProps } from 'next/app'; | ||
import { createConfig, WagmiConfig } from 'wagmi'; | ||
|
||
const projectId = ''; | ||
const { wallets } = getDefaultWallets({ | ||
projectId, | ||
appName: 'greenfield js sdk demo', | ||
chains, | ||
}); | ||
|
||
const connectors = connectorsForWallets([ | ||
...wallets, | ||
{ | ||
groupName: 'Recommended', | ||
wallets: [trustWallet({ projectId, chains })], | ||
}, | ||
]); | ||
|
||
const wagmiConfig = createConfig({ | ||
autoConnect: true, | ||
connectors: [metaMaskWalletConnector, trustWalletConnector, coinbaseWalletConnector], | ||
connectors, | ||
webSocketPublicClient, | ||
publicClient, | ||
}); | ||
|
||
export default function App({ Component, pageProps }: AppProps) { | ||
return ( | ||
<WagmiConfig config={wagmiConfig}> | ||
<Component {...pageProps} /> | ||
<RainbowKitProvider modalSize="compact" chains={chains}> | ||
<Component {...pageProps} /> | ||
</RainbowKitProvider> | ||
</WagmiConfig> | ||
); | ||
} |
Oops, something went wrong.