Skip to content

Commit

Permalink
chore: update snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Mar 13, 2022
1 parent 099d5d0 commit 8b18e66
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 59 deletions.
8 changes: 2 additions & 6 deletions packages/core/src/actions/accounts/fetchBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BigNumber, Contract } from 'ethers/lib/ethers'
import { formatUnits } from 'ethers/lib/utils'

import { client } from '../../client'
import { defaultChains, defaultL2Chains, erc20ABI } from '../../constants'
import { allChains, erc20ABI } from '../../constants'
import { Unit } from '../../types'

export type FetchBalanceArgs = {
Expand Down Expand Up @@ -43,11 +43,7 @@ export async function fetchBalance({
}
}

const chains = [
...(client.connector?.chains ?? []),
...defaultChains,
...defaultL2Chains,
]
const chains = [...(client.connector?.chains ?? []), ...allChains]
const value = await client.provider.getBalance(addressOrName)
const chain = chains.find((x) => x.id === client.provider.network.chainId)
return {
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import * as Exports from './'
it('should expose correct exports', () => {
expect(Object.keys(Exports)).toMatchInlineSnapshot(`
[
"Connector",
"InjectedConnector",
"connect",
"disconnect",
"fetchBalance",
Expand Down Expand Up @@ -40,14 +38,18 @@ it('should expose correct exports', () => {
"watchSigner",
"watchToken",
"writeContract",
"createClient",
"createWagmiClient",
"Client",
"WagmiClient",
"Connector",
"InjectedConnector",
"allChains",
"chain",
"defaultChains",
"erc1155ABI",
"erc20ABI",
"erc721ABI",
"chain",
"allChains",
"defaultChains",
"defaultL2Chains",
"developmentChains",
"units",
"AddChainError",
"ChainNotConfiguredError",
Expand All @@ -56,11 +58,9 @@ it('should expose correct exports', () => {
"SwitchChainError",
"SwitchChainNotSupportedError",
"UserRejectedRequestError",
"createWagmiClient",
"WagmiClient",
"createStorage",
"createWagmiStorage",
"normalizeChainId",
"verifyEIP1271Signature",
]
`)
})
2 changes: 1 addition & 1 deletion packages/react/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const Provider = ({
<Context.Provider value={client}>
<QueryClientProvider client={queryClient}>
{children}
{/* Automatically removed during production builds */}
{/* Automatically removed for production build */}
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</Context.Provider>
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/hooks/accounts/useAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type UseAccountConfig = {
ens?: boolean | { avatar?: boolean; name?: boolean }
}

export const queryKey = 'account' as const
export const queryKey = () => [{ entity: 'account' }] as const

export const useAccount = ({ ens }: UseAccountConfig = {}) => {
const client = useClient()
Expand All @@ -28,9 +28,9 @@ export const useAccount = ({ ens }: UseAccountConfig = {}) => {
isLoading,
status,
...accountQueryResult
} = useQuery(queryKey, async () => {
} = useQuery(queryKey(), async () => {
const { address, connector } = getAccount()
const cachedAccount = queryClient.getQueryData<GetAccountResult>(queryKey)
const cachedAccount = queryClient.getQueryData<GetAccountResult>(queryKey())
return address
? { address, connector }
: cachedAccount || { address: undefined, connector: undefined }
Expand All @@ -48,7 +48,7 @@ export const useAccount = ({ ens }: UseAccountConfig = {}) => {

React.useEffect(() => {
const unwatch = watchAccount(({ address, connector }) =>
queryClient.setQueryData<GetAccountResult>(queryKey, () => ({
queryClient.setQueryData<GetAccountResult>(queryKey(), () => ({
address,
connector,
})),
Expand Down
10 changes: 4 additions & 6 deletions packages/react/src/hooks/accounts/useBalance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { BigNumber, ethers, utils } from 'ethers'
import { Unit, defaultChains, defaultL2Chains, erc20ABI } from '@wagmi/core'
import { Unit, allChains, erc20ABI } from '@wagmi/core'

import { useClient } from '../../context'
import { useProvider } from '../providers'
Expand Down Expand Up @@ -95,11 +95,9 @@ export const useBalance = ({
}
} else {
const value = await provider.getBalance(config_.addressOrName)
const chain = [
...(connector?.chains ?? []),
...defaultChains,
...defaultL2Chains,
].find((x) => x.id === provider.network.chainId)
const chain = [...(connector?.chains ?? []), ...allChains].find(
(x) => x.id === provider.network.chainId,
)
balance = {
decimals: chain?.nativeCurrency?.decimals ?? 18,
formatted: utils.formatUnits(value, formatUnits_),
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/hooks/accounts/useConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export type UseConnectConfig = {
onSettled?: MutationOptions['onSettled']
}

export const connectMutationKey = 'connect' as const
export const mutationKey = 'connect' as const

const connectMutationFn = (connector: Connector) => connect(connector)
const mutationFn = (connector: Connector) => connect(connector)

export function useConnect({
onConnect,
Expand All @@ -31,7 +31,7 @@ export function useConnect({
mutate,
status,
variables: activeConnector,
} = useMutation(connectMutationKey, connectMutationFn, {
} = useMutation(mutationKey, mutationFn, {
onError,
onSettled,
onSuccess: onConnect,
Expand Down
37 changes: 9 additions & 28 deletions packages/react/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,27 @@ it('should expose correct exports', () => {
[
"Provider",
"WagmiProvider",
"useContext",
"Context",
"useClient",
"useWagmiClient",
"useAccount",
"useBalance",
"useBlockNumber",
"useConnect",
"useContract",
"useContractEvent",
"useContractRead",
"useContractWrite",
"useEnsAvatar",
"useEnsLookup",
"useEnsResolveName",
"useEnsResolver",
"useFeeData",
"useNetwork",
"useProvider",
"useSigner",
"useSignMessage",
"useToken",
"useTransaction",
"useWaitForTransaction",
"useWebSocketProvider",
"Client",
"Connector",
"InjectedConnector",
"chain",
"WagmiClient",
"allChains",
"chain",
"createClient",
"createStorage",
"createWagmiClient",
"createWagmiStorage",
"defaultChains",
"defaultL2Chains",
"developmentChains",
"erc1155ABI",
"erc20ABI",
"erc721ABI",
"normalizeChainId",
"AddChainError",
"ChainNotConfiguredError",
"ConnectorAlreadyConnectedError",
"ConnectorNotFoundError",
"SwitchChainError",
"UserRejectedRequestError",
]
`)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/utils/safe-stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ function replaceGetterValues(replacer) {
}
}

module.exports = stringify
export default stringify

0 comments on commit 8b18e66

Please sign in to comment.