Skip to content

Commit

Permalink
Update wagmi, viem, and @tanstack/react-query (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook authored Apr 24, 2024
1 parent d62916e commit 893cbff
Show file tree
Hide file tree
Showing 34 changed files with 1,826 additions and 1,839 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Build

on: [push]

jobs:
build:
runs-on: ubuntu-latest
name: Build
steps:
- name: git-checkout
uses: actions/checkout@v4

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Typecheck
run: pnpm typecheck

- name: Build
run: pnpm build && pnpm build:react

- name: Test
run: pnpm test
4 changes: 2 additions & 2 deletions .github/workflows/build.yml → .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build dapp
name: Deploy Example

on:
push:
Expand All @@ -8,7 +8,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest
name: Build and Push
name: Deploy Example
steps:
- name: git-checkout
uses: actions/checkout@v4
Expand Down
31 changes: 1 addition & 30 deletions examples/react-waas/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
## react-waas
6 changes: 3 additions & 3 deletions examples/react-waas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"dependencies": {
"0xsequence": "^1.9.19",
"@0xsequence/kit": "workspace:*",
"@tanstack/react-query": "^4.36.1",
"@tanstack/react-query": "^5.32.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"viem": "^2.5.7",
"wagmi": "^2.5.7"
"viem": "^2.9.26",
"wagmi": "^2.5.20"
},
"devDependencies": {
"@types/react": "^18.2.79",
Expand Down
14 changes: 6 additions & 8 deletions examples/react-waas/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { sequence } from '0xsequence'
import { formatUnits } from 'viem'
import { useEffect, useState } from 'react'

function App() {
export const App = () => {
const { setOpenConnectModal } = useOpenConnectModal()
const { disconnect } = useDisconnect()
const { data: walletClient } = useWalletClient()
Expand Down Expand Up @@ -88,7 +88,7 @@ function App() {
// Sending txn
const [lastTxnDataHash, setLastTxnDataHash] = useState<string | undefined>()

const { data: txnData, sendTransaction, isLoading } = useSendTransaction()
const { data: txnData, sendTransaction, isPending } = useSendTransaction()
const runSendTransaction = async () => {
if (!walletClient) {
return
Expand Down Expand Up @@ -137,16 +137,16 @@ function App() {

<div className="card">
<p>Network: {networkForCurrentChainId?.name}</p>
<button onClick={() => switchNetwork()} disabled={isLoading}>
<button onClick={() => switchNetwork()} disabled={isPending}>
Switch network
</button>
</div>
<div className="card">
<button onClick={() => runSendTransaction()} disabled={isLoading}>
<button onClick={() => runSendTransaction()} disabled={isPending}>
Send transaction
</button>

{isLoading && <p>Transaction is pending...</p>}
{isPending && <p>Transaction is pending...</p>}

{lastTxnDataHash && (
<div>
Expand Down Expand Up @@ -181,7 +181,7 @@ function App() {
<div className="card">
<p>Sign message</p>
<p>Message: {messageToSign}</p>
<button onClick={signMessage} disabled={isLoading}>
<button onClick={signMessage} disabled={isPending}>
Sign message
</button>

Expand All @@ -201,5 +201,3 @@ function App() {
</div>
)
}

export default App
2 changes: 1 addition & 1 deletion examples/react-waas/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import { App } from './App.tsx'
import './index.css'

import { WagmiProvider, createConfig, http } from 'wagmi'
Expand Down
6 changes: 3 additions & 3 deletions examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
"@0xsequence/kit-connectors": "workspace:*",
"@0xsequence/kit-wallet": "workspace:*",
"@0xsequence/network": "^1.9.19",
"@tanstack/react-query": "^4.36.1",
"@tanstack/react-query": "^5.32.0",
"@vanilla-extract/css": "^1.14.2",
"ethers": "^5.7.2",
"framer-motion": "^8.5.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^5.4.5",
"viem": "^2.5.7",
"wagmi": "^2.5.7"
"viem": "^2.9.26",
"wagmi": "^2.5.20"
},
"devDependencies": {
"@types/node": "^20.12.7",
Expand Down
6 changes: 2 additions & 4 deletions examples/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ThemeProvider } from '@0xsequence/design-system'
import { KitProvider } from '@0xsequence/kit'
import { KitWalletProvider } from '@0xsequence/kit-wallet'
import { KitCheckoutProvider } from '@0xsequence/kit-checkout'
import Homepage from './components/Homepage'
import { Homepage } from './components/Homepage'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { WagmiProvider } from 'wagmi'

Expand All @@ -11,7 +11,7 @@ import { kitConfig, wagmiConfig } from './config'

const queryClient = new QueryClient()

function App() {
export const App = () => {
return (
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
Expand All @@ -30,5 +30,3 @@ function App() {
</WagmiProvider>
)
}

export default App
28 changes: 11 additions & 17 deletions examples/react/src/components/Homepage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ import {
import { allNetworks } from '@0xsequence/network'
import { Footer } from './Footer'
import { messageToSign } from '../constants'
import { formatAddress, getCheckoutSettings } from '../utils'
import abi from '../constants/nft-abi'
import { delay, formatAddress, getCheckoutSettings } from '../utils'
import { abi } from '../constants/nft-abi'
import { ethers } from 'ethers'
import { Alert, AlertProps } from './Alert'

// append ?debug to url to enable debug mode
const searchParams = new URLSearchParams(location.search)
const isDebugMode = searchParams.has('debug')

function Homepage() {
export const Homepage = () => {
const { theme, setTheme } = useTheme()
const { setTheme: setKitTheme } = useKitTheme()
const { address, connector, isConnected } = useAccount()
Expand All @@ -66,8 +66,8 @@ function Homepage() {

const isMobile = useMediaQuery('isMobile')

const { data: txnData, sendTransaction, isLoading: isSendTxnLoading, error } = useSendTransaction()
const { data: txnData2, isLoading: isMintTxnLoading, writeContract } = useWriteContract()
const { data: txnData, sendTransaction, isPending: isPendingSendTxn, error } = useSendTransaction()
const { data: txnData2, isPending: isPendingMintTxn, writeContract } = useWriteContract()

const [isSigningMessage, setIsSigningMessage] = React.useState(false)
const [isMessageValid, setIsMessageValid] = React.useState<boolean | undefined>()
Expand Down Expand Up @@ -280,11 +280,11 @@ function Homepage() {
title: string
description: string
disabled?: boolean
isLoading?: boolean
isPending?: boolean
onClick: () => void
}

const ClickableCard = ({ title, description, disabled, isLoading, onClick }: ClickableCardProps) => {
const ClickableCard = ({ title, description, disabled, isPending, onClick }: ClickableCardProps) => {
return (
<Card
style={{ width: '332px' }}
Expand All @@ -300,7 +300,7 @@ function Homepage() {
{description}
</Text>
</Box>
{isLoading && <Spinner marginTop="3" size="sm" color="text100" />}
{isPending && <Spinner marginTop="3" size="sm" color="text100" />}
</Card>
)
}
Expand Down Expand Up @@ -364,7 +364,7 @@ function Homepage() {
<ClickableCard
title="Send transaction"
description="Send a transaction with your wallet"
isLoading={isSendTxnLoading}
isPending={isPendingSendTxn}
onClick={runSendTransaction}
/>

Expand All @@ -385,7 +385,7 @@ function Homepage() {
title="Sign message"
description="Sign a message with your wallet"
onClick={signMessage}
isLoading={isSigningMessage}
isPending={isSigningMessage}
/>
{isMessageValid && (
<Card style={{ width: '332px' }} color={'text100'} flexDirection={'column'} gap={'2'}>
Expand All @@ -404,7 +404,7 @@ function Homepage() {
<ClickableCard
title="Mint an NFT"
description="Test minting an NFT to your wallet"
isLoading={isMintTxnLoading}
isPending={isPendingMintTxn}
onClick={runMintNFT}
/>
{lastTxnDataHash2 && (txnData2?.chainId === chainId || txnData2) && (
Expand Down Expand Up @@ -583,9 +583,3 @@ function Homepage() {
</Box>
)
}

function delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms))
}

export default Homepage
4 changes: 1 addition & 3 deletions examples/react/src/constants/nft-abi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const abi = [
export const abi = [
{ inputs: [], stateMutability: 'nonpayable', type: 'constructor' },
{
inputs: [
Expand Down Expand Up @@ -192,5 +192,3 @@ const abi = [
type: 'function'
}
]

export default abi
2 changes: 1 addition & 1 deletion examples/react/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import './index.css'
import App from './App'
import { App } from './App'

console.log('VERSION:', process.env.PACKAGE_VERSION)

Expand Down
4 changes: 4 additions & 0 deletions examples/react/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ export const truncateAtMiddle = (text: string, truncateAt: number) => {
export const formatAddress = (text: string) => {
return `0x${truncateAtMiddle(text?.substring(2) || '', 8)}`
}

export const delay = (ms: number) => {
return new Promise(resolve => setTimeout(resolve, ms))
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "pnpm dev && pnpm typecheck && preconstruct build",
"watch": "preconstruct watch",
"clean": "rimraf ./node_modules",
"clean": "rimraf -g ./**/node_modules",
"changeset": "changeset",
"version-packages": "changeset version",
"release": "pnpm build && changeset publish",
Expand Down Expand Up @@ -53,7 +53,7 @@
"react-dom": "^18.2.0",
"rimraf": "^5.0.5",
"typescript": "~5.4.5",
"wagmi": "^2.5.7"
"wagmi": "^2.5.20"
},
"resolutions": {},
"workspaces": [
Expand Down
4 changes: 2 additions & 2 deletions packages/checkout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@0xsequence/metadata": "^1.9.19",
"@0xsequence/network": "^1.9.19",
"@paperxyz/react-client-sdk": "^1.1.3",
"@tanstack/react-query": "^4.29.5",
"@tanstack/react-query": "^5.32.0",
"react-copy-to-clipboard": "^5.1.0"
},
"peerDependencies": {
Expand All @@ -44,7 +44,7 @@
"framer-motion": "^8.5.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"wagmi": "^2.5.7"
"wagmi": "^2.5.20"
},
"files": [
"src",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ interface OrderSummaryItem {

export const OrderSummaryItem = ({ contractAddress, tokenId, quantityRaw, chainId }: OrderSummaryItem) => {
const { chains } = useConfig()
const { data: tokenMetadata, isLoading: isTokenMetadataLoading } = useTokenMetadata({
const { data: tokenMetadata, isPending: isPendingTokenMetadata } = useTokenMetadata({
chainId,
contractAddress,
tokenId
})

const { data: contractInfo, isLoading: isContractInfoLoading } = useContractInfo({
const { data: contractInfo, isPending: isPendingContractInfo } = useContractInfo({
chainID: String(chainId),
contractAddress
})

const isLoading = isTokenMetadataLoading || isContractInfoLoading
const isPending = isPendingTokenMetadata || isPendingContractInfo

if (isLoading) {
if (isPending) {
return <OrderSummarySkeleton />
}

Expand Down
Loading

0 comments on commit 893cbff

Please sign in to comment.