-
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.
- Loading branch information
simodrws
committed
Apr 26, 2024
1 parent
e603c11
commit c9d50b1
Showing
15 changed files
with
1,259 additions
and
302 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React, { ReactNode } from 'react'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { WagmiProvider } from 'wagmi'; | ||
import * as all from 'wagmi/chains'; | ||
import { getDefaultConfig, RainbowKitProvider } from '@rainbow-me/rainbowkit'; | ||
import { SupportedNetworks } from '@masa-finance/masa-sdk'; | ||
import { arbitrumNova } from '@wagmi/chains'; | ||
import { | ||
masaChain, | ||
masaTestnetChain, | ||
} from './wallet-client/helpers/get-masa-chains'; | ||
|
||
const { | ||
goerli, | ||
sepolia, | ||
bsc, | ||
bscTestnet, | ||
opBNB, | ||
opBNBTestnet, | ||
polygonAmoy, | ||
polygonMumbai, | ||
celo, | ||
celoAlfajores, | ||
base, | ||
baseGoerli, | ||
baseSepolia, | ||
scroll, | ||
scrollSepolia, | ||
mainnet: ethereum, | ||
|
||
polygon, | ||
} = all; | ||
|
||
console.log({ all, SupportedNetworks }); | ||
|
||
const test = Object.values(SupportedNetworks).map((sn) => sn.networkName); | ||
const secondOne = test.map((sn) => all[sn]); | ||
console.log({ test, secondOne }); | ||
const config = getDefaultConfig({ | ||
appName: 'RainbowKit App', | ||
projectId: 'YOUR_PROJECT_ID', | ||
chains: [ | ||
masaChain, | ||
masaTestnetChain, | ||
ethereum, | ||
goerli, | ||
polygon, | ||
bsc, | ||
bscTestnet, | ||
opBNB, | ||
opBNBTestnet, | ||
polygonAmoy, | ||
polygonMumbai, | ||
celo, | ||
celoAlfajores, | ||
base, | ||
baseGoerli, | ||
baseSepolia, | ||
scroll, | ||
scrollSepolia, | ||
], | ||
ssr: true, | ||
}); | ||
const client = new QueryClient(); | ||
|
||
console.log({ masaChain }); | ||
|
||
const MasaUpdatedProvider = ({ children }: { children: ReactNode }) => { | ||
return ( | ||
<WagmiProvider config={config}> | ||
<QueryClientProvider client={client}> | ||
<RainbowKitProvider>{children} </RainbowKitProvider> | ||
</QueryClientProvider> | ||
</WagmiProvider> | ||
); | ||
}; | ||
|
||
export default MasaUpdatedProvider; |
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,9 +1,10 @@ | ||
import React, { ReactNode } from 'react'; | ||
import WagmiRainbowkitProvider from '../wallet-client/wagmi-rainbowkit-provider'; | ||
|
||
import WalletClientProvider from '../wallet-client/wallet-client-provider'; | ||
import MasaUpdatedProvider from '../MasaUpdatedProvider'; | ||
|
||
export const MasaWalletProvider = ({ children }: { children: ReactNode }) => ( | ||
<WagmiRainbowkitProvider> | ||
<MasaUpdatedProvider> | ||
<WalletClientProvider>{children}</WalletClientProvider> | ||
</WagmiRainbowkitProvider> | ||
</MasaUpdatedProvider> | ||
); |
File renamed without changes.
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,55 @@ | ||
import type { Args, Meta } from '@storybook/react'; | ||
|
||
import React from 'react'; | ||
import '../ui/styles.scss'; | ||
import './stories.scss'; | ||
import 'react-json-view-lite/dist/index.css'; | ||
import '@rainbow-me/rainbowkit/styles.css'; | ||
|
||
import MasaUpdatedProvider from '../MasaUpdatedProvider'; | ||
import { ConnectButton } from '@rainbow-me/rainbowkit'; | ||
|
||
const meta: Meta = { | ||
title: 'Wallet And Network', | ||
component: () => <div />, | ||
argTypes: { | ||
children: { | ||
control: { | ||
type: 'text', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
const NetworkInfo = () => { | ||
return ( | ||
<> | ||
<h1>Viem Wagmi Update</h1> | ||
|
||
<ul> | ||
<ConnectButton /> | ||
</ul> | ||
</> | ||
); | ||
}; | ||
|
||
const Component = (): JSX.Element => { | ||
return ( | ||
// skipcq: JS-0415 | ||
<section> | ||
<NetworkInfo /> | ||
</section> | ||
); | ||
}; | ||
|
||
const TemplateNewMasaState = (props: Args) => ( | ||
<MasaUpdatedProvider> | ||
<Component {...props} /> | ||
</MasaUpdatedProvider> | ||
); | ||
|
||
export const WagmiUpdate = TemplateNewMasaState.bind({ | ||
options: { scope: [] }, | ||
}); |
File renamed without changes.
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,3 +1,5 @@ | ||
.sme-class { | ||
border: 2px solid red; | ||
} | ||
|
||
@import '~@rainbow-me/rainbowkit/styles.css'; |
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,59 @@ | ||
import { SupportedNetworks, addresses } from '@masa-finance/masa-sdk'; | ||
import { Chain } from '@rainbow-me/rainbowkit'; | ||
|
||
const { masa, masatest } = SupportedNetworks; | ||
const masaContracts = Object.entries(addresses!.masa!) | ||
.map(([key, value]) => ({ | ||
[key]: { address: value }, | ||
})) | ||
.reduce((acc, val) => ({ ...acc, ...val }), {}); | ||
const masaTestnetContracts = Object.entries(addresses!.masatest!) | ||
.map(([key, value]) => ({ | ||
[key]: { address: value }, | ||
})) | ||
.reduce((acc, val) => ({ ...acc, ...val }), {}); | ||
|
||
export const masaChain = { | ||
id: masa!.chainId, | ||
name: masa!.chainName, | ||
iconUrl: undefined, | ||
iconBackground: '#fff', | ||
nativeCurrency: { | ||
name: masa!.nativeCurrency?.name as string, | ||
symbol: masa!.nativeCurrency?.symbol as string, | ||
decimals: masa!.nativeCurrency?.decimals as number, | ||
}, | ||
rpcUrls: { | ||
default: { http: ['https://subnets.avax.network/masanetwork/mainnet/rpc'] }, | ||
}, | ||
blockExplorers: { | ||
default: { name: 'Avalanche', url: 'https://subnets.avax.network/masa' }, | ||
}, | ||
contracts: { | ||
...masaContracts, | ||
}, | ||
} as const satisfies Chain; | ||
|
||
export const masaTestnetChain = { | ||
id: masatest!.chainId, | ||
name: masatest!.chainName, | ||
iconUrl: undefined, | ||
iconBackground: '#fff', | ||
nativeCurrency: { | ||
name: masatest!.nativeCurrency?.name as string, | ||
symbol: masatest!.nativeCurrency?.symbol as string, | ||
decimals: masatest!.nativeCurrency?.decimals as number, | ||
}, | ||
rpcUrls: { | ||
default: { http: ['https://subnets.avax.network/masatestne/testnet/rpc'] }, | ||
}, | ||
blockExplorers: { | ||
default: { | ||
name: 'Avalanche', | ||
url: 'https://subnets-test.avax.network/masatestnet', | ||
}, | ||
}, | ||
contracts: { | ||
...masaTestnetContracts, | ||
}, | ||
} as const satisfies Chain; |
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,66 @@ | ||
import { Signer, providers } from 'ethers'; | ||
import { useMemo } from 'react'; | ||
import type { Account, Chain, Client, Transport } from 'viem'; | ||
import { Config, useClient, useConnectorClient } from 'wagmi'; | ||
|
||
export function clientToProvider(client: Client<Transport, Chain>) { | ||
const { chain, transport } = client; | ||
const network = { | ||
chainId: chain.id, | ||
name: chain.name, | ||
ensAddress: chain.contracts?.ensRegistry?.address, | ||
}; | ||
if (transport.type === 'fallback') | ||
return new providers.FallbackProvider( | ||
(transport.transports as ReturnType<Transport>[]).map( | ||
({ value }) => new providers.JsonRpcProvider(value?.url, network) | ||
) | ||
); | ||
return new providers.JsonRpcProvider(transport.url, network); | ||
} | ||
|
||
/** Hook to convert a viem Client to an ethers.js Provider. */ | ||
export function useEthersProvider({ | ||
chainId, | ||
}: { chainId?: number | undefined } = {}) { | ||
const client = useClient<Config>({ chainId }); | ||
return useMemo( | ||
() => clientToProvider(client as Client<Transport, Chain>), | ||
[client] | ||
); | ||
} | ||
|
||
export function clientToSigner(client: Client<Transport, Chain, Account>) { | ||
const { account, chain, transport } = client; | ||
const network = { | ||
chainId: chain.id, | ||
name: chain.name, | ||
ensAddress: chain.contracts?.ensRegistry?.address, | ||
}; | ||
const provider = new providers.Web3Provider(transport, network); | ||
const signer = provider.getSigner(account.address); | ||
return signer; | ||
} | ||
|
||
/** Hook to convert a Viem Client to an ethers.js Signer. */ | ||
export function useEthersSigner({ chainId }: { chainId?: number } = {}) { | ||
const { | ||
data: client, | ||
isLoading, | ||
error, | ||
} = useConnectorClient<Config>({ chainId }); | ||
const signer = useMemo( | ||
() => (client ? clientToSigner(client) : undefined), | ||
[client] | ||
); | ||
|
||
return { | ||
data: signer, | ||
isLoading, | ||
error, | ||
} as { | ||
data?: Signer; | ||
isLoading?: boolean; | ||
error?: Error | null; | ||
}; | ||
} |
Oops, something went wrong.