Skip to content

Commit

Permalink
Merge pull request #253 from reservoirprotocol/ted/grwth-2719-switch-…
Browse files Browse the repository at this point in the history
…to-viem-on-marketplace

Upgrade to wagmi v1
  • Loading branch information
ted-palmer committed Jun 12, 2023
2 parents efd6168 + 12d7c46 commit 5b7efdf
Show file tree
Hide file tree
Showing 29 changed files with 819 additions and 1,870 deletions.
9 changes: 7 additions & 2 deletions components/buttons/AcceptBid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import {
import { CSS } from '@stitches/react'
import { SWRResponse } from 'swr'
import { Button } from 'components/primitives'
import { useAccount, useNetwork, useSigner, useSwitchNetwork } from 'wagmi'
import {
useAccount,
useNetwork,
useWalletClient,
useSwitchNetwork,
} from 'wagmi'
import { useConnectModal } from '@rainbow-me/rainbowkit'
import { ToastContext } from '../../context/ToastContextProvider'
import { useMarketplaceChain } from 'hooks'
Expand Down Expand Up @@ -47,7 +52,7 @@ const AcceptBid: FC<Props> = ({
chainId: marketplaceChain.id,
})

const { data: signer } = useSigner()
const { data: signer } = useWalletClient()
const { chain: activeChain } = useNetwork()

const isInTheWrongNetwork = Boolean(
Expand Down
6 changes: 3 additions & 3 deletions components/buttons/Bid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
import { CSS } from '@stitches/react'
import { SWRResponse } from 'swr'
import {
mainnet,
useAccount,
useNetwork,
useSigner,
useWalletClient,
mainnet,
useSwitchNetwork,
} from 'wagmi'
import { useConnectModal } from '@rainbow-me/rainbowkit'
Expand Down Expand Up @@ -49,7 +49,7 @@ const Bid: FC<Props> = ({
chainId: marketplaceChain.id,
})

const { data: signer } = useSigner()
const { data: signer } = useWalletClient()
const { chain: activeChain } = useNetwork()

const isInTheWrongNetwork = Boolean(
Expand Down
4 changes: 2 additions & 2 deletions components/buttons/BuyNow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ComponentProps, FC, ReactNode } from 'react'
import { SWRResponse } from 'swr'
import { useNetwork, useSigner } from 'wagmi'
import { useNetwork, useWalletClient } from 'wagmi'
import { BuyModal, BuyStep, useTokens } from '@reservoir0x/reservoir-kit-ui'
import { useSwitchNetwork } from 'wagmi'
import { Button } from 'components/primitives'
Expand All @@ -27,7 +27,7 @@ const BuyNow: FC<Props> = ({
buttonProps = {},
buttonChildren,
}) => {
const { data: signer } = useSigner()
const { data: signer } = useWalletClient()
const { openConnectModal } = useConnectModal()
const { chain: activeChain } = useNetwork()
const marketplaceChain = useMarketplaceChain()
Expand Down
4 changes: 2 additions & 2 deletions components/buttons/CancelBid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useConnectModal } from '@rainbow-me/rainbowkit'
import { CancelBidModal, CancelBidStep } from '@reservoir0x/reservoir-kit-ui'
import { FC, ReactElement, cloneElement, useContext } from 'react'
import { SWRResponse } from 'swr'
import { useNetwork, useSigner, useSwitchNetwork } from 'wagmi'
import { useNetwork, useWalletClient, useSwitchNetwork } from 'wagmi'
import { ToastContext } from '../../context/ToastContextProvider'
import { useMarketplaceChain } from 'hooks'

Expand All @@ -21,7 +21,7 @@ const CancelBid: FC<Props> = ({ bidId, openState, trigger, mutate }) => {
chainId: marketplaceChain.id,
})

const { data: signer } = useSigner()
const { data: signer } = useWalletClient()
const { chain: activeChain } = useNetwork()

const isInTheWrongNetwork = Boolean(
Expand Down
4 changes: 2 additions & 2 deletions components/buttons/CancelListing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@reservoir0x/reservoir-kit-ui'
import { FC, ReactElement, useContext, cloneElement } from 'react'
import { SWRResponse } from 'swr'
import { useNetwork, useSigner, useSwitchNetwork } from 'wagmi'
import { useNetwork, useWalletClient, useSwitchNetwork } from 'wagmi'
import { ToastContext } from '../../context/ToastContextProvider'
import { useMarketplaceChain } from 'hooks'

Expand All @@ -29,7 +29,7 @@ const CancelListing: FC<Props> = ({
chainId: marketplaceChain.id,
})

const { data: signer } = useSigner()
const { data: signer } = useWalletClient()
const { chain: activeChain } = useNetwork()

const isInTheWrongNetwork = Boolean(
Expand Down
4 changes: 2 additions & 2 deletions components/buttons/CollectionOffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
mainnet,
useAccount,
useNetwork,
useSigner,
useWalletClient,
useSwitchNetwork,
} from 'wagmi'
import { useCollections } from '@reservoir0x/reservoir-kit-ui'
Expand Down Expand Up @@ -41,7 +41,7 @@ const CollectionOffer: FC<Props> = ({
const router = useRouter()
const marketplaceChain = useMarketplaceChain()
const [attribute, setAttribute] = useState<Trait>(undefined)
const { data: signer } = useSigner()
const { data: signer } = useWalletClient()
const { chain: activeChain } = useNetwork()
const { isDisconnected } = useAccount()
const { openConnectModal } = useConnectModal()
Expand Down
9 changes: 7 additions & 2 deletions components/buttons/EditBid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { Button } from 'components/primitives'
import { ToastContext } from 'context/ToastContextProvider'
import { useMarketplaceChain } from 'hooks'
import { cloneElement, ComponentProps, FC, ReactNode, useContext } from 'react'
import { useAccount, useNetwork, useSigner, useSwitchNetwork } from 'wagmi'
import {
useAccount,
useNetwork,
useWalletClient,
useSwitchNetwork,
} from 'wagmi'
import { CSS } from '@stitches/react'
import { SWRResponse } from 'swr'
import { EditBidModal, EditBidStep } from '@reservoir0x/reservoir-kit-ui'
Expand Down Expand Up @@ -39,7 +44,7 @@ const EditBid: FC<Props> = ({
chainId: marketplaceChain.id,
})

const { data: signer } = useSigner()
const { data: signer } = useWalletClient()
const { chain: activeChain } = useNetwork()

const isInTheWrongNetwork = Boolean(
Expand Down
9 changes: 7 additions & 2 deletions components/buttons/EditListing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { Button } from 'components/primitives'
import { ToastContext } from 'context/ToastContextProvider'
import { useMarketplaceChain } from 'hooks'
import { cloneElement, ComponentProps, FC, ReactNode, useContext } from 'react'
import { useAccount, useNetwork, useSigner, useSwitchNetwork } from 'wagmi'
import {
useAccount,
useNetwork,
useWalletClient,
useSwitchNetwork,
} from 'wagmi'
import { CSS } from '@stitches/react'
import { SWRResponse } from 'swr'
import {
Expand Down Expand Up @@ -42,7 +47,7 @@ const EditListing: FC<Props> = ({
chainId: marketplaceChain.id,
})

const { data: signer } = useSigner()
const { data: signer } = useWalletClient()
const { chain: activeChain } = useNetwork()

const isInTheWrongNetwork = Boolean(
Expand Down
10 changes: 5 additions & 5 deletions components/buttons/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import {
import { CSS } from '@stitches/react'
import { SWRResponse } from 'swr'
import {
mainnet,
useAccount,
useNetwork,
useSigner,
useWalletClient,
mainnet,
useSwitchNetwork,
} from 'wagmi'
import { useConnectModal } from '@rainbow-me/rainbowkit'
import { ToastContext } from 'context/ToastContextProvider'
import { useMarketplaceChain } from 'hooks'
import { constants } from 'ethers'
import { zeroAddress } from 'viem'

type ListingCurrencies = ComponentPropsWithoutRef<
typeof ListModal
Expand Down Expand Up @@ -50,7 +50,7 @@ const List: FC<Props> = ({
chainId: marketplaceChain.id,
})

const { data: signer } = useSigner()
const { data: signer } = useWalletClient()
const { chain: activeChain } = useNetwork()

const isInTheWrongNetwork = Boolean(
Expand All @@ -62,7 +62,7 @@ const List: FC<Props> = ({
if (marketplaceChain.id === mainnet.id) {
listingCurrencies = [
{
contract: constants.AddressZero,
contract: zeroAddress,
symbol: 'ETH',
coinGeckoId: 'ethereum',
},
Expand Down
4 changes: 2 additions & 2 deletions components/buttons/Sweep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { ComponentProps, FC, ReactNode } from 'react'
import { useConnectModal } from '@rainbow-me/rainbowkit'
import { SweepModal, SweepStep } from '@reservoir0x/reservoir-kit-ui'
import { useMarketplaceChain } from 'hooks'
import { useNetwork, useSigner, useSwitchNetwork } from 'wagmi'
import { useNetwork, useWalletClient, useSwitchNetwork } from 'wagmi'
import { CSS } from '@stitches/react'
import { Button } from 'components/primitives'
import { SWRResponse } from 'swr'
Expand All @@ -22,7 +22,7 @@ const Sweep: FC<Props> = ({
buttonChildren,
mutate,
}) => {
const { data: signer } = useSigner()
const { data: signer } = useWalletClient()
const { openConnectModal } = useConnectModal()
const { chain: activeChain } = useNetwork()
const marketplaceChain = useMarketplaceChain()
Expand Down
13 changes: 5 additions & 8 deletions components/common/ActivityTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useIntersectionObserver } from 'usehooks-ts'
import Link from 'next/link'
import Image from 'next/image'
import { useENSResolver, useMarketplaceChain, useTimeSince } from 'hooks'
import { constants } from 'ethers'
import { zeroAddress } from 'viem'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import {
faExternalLink,
Expand Down Expand Up @@ -290,8 +290,7 @@ const ActivityTableRow: FC<ActivityTableRowProps> = ({ activity }) => {
>
From
</Text>
{activity.fromAddress &&
activity.fromAddress !== constants.AddressZero ? (
{activity.fromAddress && activity.fromAddress !== zeroAddress ? (
<Link href={`/portfolio/${activity.fromAddress}`}>
<Text
style="subtitle3"
Expand All @@ -314,8 +313,7 @@ const ActivityTableRow: FC<ActivityTableRowProps> = ({ activity }) => {
>
to
</Text>
{activity.toAddress &&
activity.toAddress !== constants.AddressZero ? (
{activity.toAddress && activity.toAddress !== zeroAddress ? (
<Link href={`/portfolio/${activity.toAddress}`}>
<Text
style="subtitle3"
Expand Down Expand Up @@ -424,8 +422,7 @@ const ActivityTableRow: FC<ActivityTableRowProps> = ({ activity }) => {
)}
</TableCell>
<TableCell css={{ minWidth: 0 }}>
{activity.fromAddress &&
activity.fromAddress !== constants.AddressZero ? (
{activity.fromAddress && activity.fromAddress !== zeroAddress ? (
<Flex direction="column" align="start">
<Text style="subtitle3" color="subtle">
From
Expand Down Expand Up @@ -459,7 +456,7 @@ const ActivityTableRow: FC<ActivityTableRowProps> = ({ activity }) => {
)}
</TableCell>
<TableCell css={{ minWidth: 0 }}>
{activity.toAddress && activity.toAddress !== constants.AddressZero ? (
{activity.toAddress && activity.toAddress !== zeroAddress ? (
<Flex direction="column" align="start">
<Text style="subtitle3" color="subtle">
To
Expand Down
27 changes: 14 additions & 13 deletions components/navbar/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import {
} from 'components/primitives'
import { mainnet, polygon, optimism } from 'wagmi/chains'
import { useAccount, useContractReads, erc20ABI, useBalance } from 'wagmi'
import { BigNumber, BigNumberish, constants } from 'ethers'
import useCoinConversion from 'hooks/useCoinConversion'
import { useMemo, useState } from 'react'
import { formatUnits } from 'ethers/lib/utils.js'
import { zeroAddress, formatUnits } from 'viem'

//CONFIGURABLE: Here you may configure currencies that you want to display in the wallet menu. Native currencies,
//like ETH/MATIC etc need to be fetched in a different way. Configure them below
const currencies = [
{
address: constants.AddressZero,
address: zeroAddress,
symbol: 'ETH',
decimals: mainnet.nativeCurrency.decimals,
chain: {
Expand All @@ -38,7 +37,7 @@ const currencies = [
coinGeckoId: 'weth',
},
{
address: constants.AddressZero,
address: zeroAddress,
symbol: 'MATIC',
decimals: polygon.nativeCurrency.decimals,
chain: {
Expand Down Expand Up @@ -71,11 +70,11 @@ const currencies = [

type EnhancedCurrency = (typeof currencies)[0] & {
usdPrice: number
balance: BigNumberish
balance: string | number | bigint
}

const nonNativeCurrencies = currencies.filter(
(currency) => currency.address !== constants.AddressZero
(currency) => currency.address !== zeroAddress
)

const currencySymbols = currencies.map((currency) => currency.symbol).join(',')
Expand All @@ -96,6 +95,7 @@ const Wallet = () => {
})),
watch: true,
enabled: address ? true : false,
allowFailure: false,
})

//CONFIGURABLE: Configure these by just changing the chainId to fetch native balance info, in addition to changing this
Expand Down Expand Up @@ -123,16 +123,16 @@ const Wallet = () => {
}, {} as Record<string, (typeof usdConversions)[0]>)

return currencies.map((currency, i) => {
let balance: BigNumberish = 0
if (currency.address === constants.AddressZero) {
let balance: string | number | bigint = 0n
if (currency.address === zeroAddress) {
//CONFIGURABLE: Configure these to show the fetched balance results configured above in the useBalance hooks
switch (currency.chain.id) {
case polygon.id: {
balance = maticBalance.data?.value || 0
balance = maticBalance.data?.value || 0n
break
}
case mainnet.id: {
balance = ethBalance.data?.value || 0
balance = ethBalance.data?.value || 0n
break
}
}
Expand All @@ -145,8 +145,8 @@ const Wallet = () => {
)
balance =
nonNativeBalances && nonNativeBalances[index]
? (nonNativeBalances[index] as BigNumberish)
: 0
? (nonNativeBalances[index] as string | number | bigint)
: 0n
}

const conversion =
Expand All @@ -156,7 +156,8 @@ const Wallet = () => {
: currency.symbol.toLowerCase()
]
const usdPrice =
+formatUnits(BigNumber.from(balance)) * (conversion?.price || 0)
Number(formatUnits(BigInt(balance), currency?.decimals || 18)) *
(conversion?.price || 0)
return {
...currency,
usdPrice,
Expand Down

2 comments on commit 5b7efdf

@vercel
Copy link

@vercel vercel bot commented on 5b7efdf Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

artblocks-v2 – ./

artblocks-v2.vercel.app
artblocks-v2-git-main-unevenlabs.vercel.app
artblocks-v2-unevenlabs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 5b7efdf Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.