From c85c82381230a8a10ab6995ee587e08629c1b680 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 1 Nov 2023 14:22:43 +0000 Subject: [PATCH] switch to swr --- package-lock.json | 36 ++++++++--------- package.json | 2 +- .../Web3/components/Conversion/Conversion.tsx | 7 ++-- src/features/Web3/components/Form/index.tsx | 11 ++++-- .../Web3/components/Input/InputGroup.tsx | 1 - .../Web3/components/Send/SendErc20.tsx | 5 +-- .../components/TokenSelect/TokenSelect.tsx | 37 ++++++------------ src/features/Web3/hooks/useTokens/index.ts | 2 + .../tokens => hooks/useTokens}/types.ts | 0 .../Web3/hooks/useTokens/useTokens.tsx | 39 +++++++++++++++++++ src/features/Web3/hooks/useTokensStore.tsx | 34 ---------------- src/features/Web3/stores/tokens/fetcher.ts | 12 ------ src/features/Web3/stores/tokens/index.ts | 3 -- .../Web3/stores/tokens/selectedToken.ts | 21 ---------- src/features/Web3/stores/tokens/tokens.ts | 12 ------ src/stores/fetcher.ts | 8 +++- 16 files changed, 89 insertions(+), 141 deletions(-) create mode 100644 src/features/Web3/hooks/useTokens/index.ts rename src/features/Web3/{stores/tokens => hooks/useTokens}/types.ts (100%) create mode 100644 src/features/Web3/hooks/useTokens/useTokens.tsx delete mode 100644 src/features/Web3/hooks/useTokensStore.tsx delete mode 100644 src/features/Web3/stores/tokens/fetcher.ts delete mode 100644 src/features/Web3/stores/tokens/index.ts delete mode 100644 src/features/Web3/stores/tokens/selectedToken.ts delete mode 100644 src/features/Web3/stores/tokens/tokens.ts diff --git a/package-lock.json b/package-lock.json index 7315ce97..b25a4f6e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,6 @@ "@astrojs/rss": "^3.0.0", "@astrojs/sitemap": "^3.0.2", "@coingecko/cryptoformat": "^0.6.0", - "@nanostores/persistent": "^0.9.1", "@nanostores/query": "^0.2.4", "@nanostores/react": "^0.7.1", "@radix-ui/react-select": "^2.0.0", @@ -34,6 +33,7 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "slugify": "^1.6.6", + "swr": "^2.2.4", "use-debounce": "^9.0.4", "viem": "^1.18.0", "wagmi": "^1.4.5" @@ -2016,23 +2016,6 @@ "tslib": "^2.3.1" } }, - "node_modules/@nanostores/persistent": { - "version": "0.9.1", - "resolved": "https://registry.npmjs.org/@nanostores/persistent/-/persistent-0.9.1.tgz", - "integrity": "sha512-ow57Hxm5VMaI5GHET/cVk8hX/iKMmbhcGrB9owfN8p8OHiiJgUlYxe1giacwlAALJXAh2t8bxXh42hHb64BCEA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/ai" - } - ], - "engines": { - "node": "^16.0.0 || ^18.0.0 || >=20.0.0" - }, - "peerDependencies": { - "nanostores": "^0.9.0" - } - }, "node_modules/@nanostores/query": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/@nanostores/query/-/query-0.2.4.tgz", @@ -6184,6 +6167,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/client-only": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz", + "integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==" + }, "node_modules/cliui": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", @@ -17926,6 +17914,18 @@ "node": ">= 10" } }, + "node_modules/swr": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/swr/-/swr-2.2.4.tgz", + "integrity": "sha512-njiZ/4RiIhoOlAaLYDqwz5qH/KZXVilRLvomrx83HjzCWTfa+InyfAjv05PSFxnmLzZkNO9ZfvgoqzAaEI4sGQ==", + "dependencies": { + "client-only": "^0.0.1", + "use-sync-external-store": "^1.2.0" + }, + "peerDependencies": { + "react": "^16.11.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/symbol-tree": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", diff --git a/package.json b/package.json index 5b107ae7..6547449b 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "@astrojs/rss": "^3.0.0", "@astrojs/sitemap": "^3.0.2", "@coingecko/cryptoformat": "^0.6.0", - "@nanostores/persistent": "^0.9.1", "@nanostores/query": "^0.2.4", "@nanostores/react": "^0.7.1", "@radix-ui/react-select": "^2.0.0", @@ -73,6 +72,7 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "slugify": "^1.6.6", + "swr": "^2.2.4", "use-debounce": "^9.0.4", "viem": "^1.18.0", "wagmi": "^1.4.5" diff --git a/src/features/Web3/components/Conversion/Conversion.tsx b/src/features/Web3/components/Conversion/Conversion.tsx index 3236c786..1e1b9323 100644 --- a/src/features/Web3/components/Conversion/Conversion.tsx +++ b/src/features/Web3/components/Conversion/Conversion.tsx @@ -1,10 +1,9 @@ import { useEffect, type ReactElement, useState } from 'react' import styles from './Conversion.module.css' -import { $selectedToken } from '../../stores/tokens/selectedToken' -import { useStore } from '@nanostores/react' +import { useTokens } from '@features/Web3/hooks/useTokens' export function Conversion({ amount }: { amount: string }): ReactElement { - const selectedToken = useStore($selectedToken) + const { selectedToken } = useTokens() const [dollar, setDollar] = useState('0.00') const [euro, setEuro] = useState('0.00') @@ -22,7 +21,7 @@ export function Conversion({ amount }: { amount: string }): ReactElement { const euro = eur ? (Number(amount) * eur).toFixed(2) : '0.00' setDollar(dollar) setEuro(euro) - }, [selectedToken?.price, amount]) + }, [selectedToken, amount]) return (
- {message ? ( + {message && message.status !== 'error' ? ( ) : ( )} + {message && message?.status === 'error' ? ( + + ) : null} + {selectedToken?.address === '0x0' ? ( setAmount(e.target.value)} className={styles.inputInput} - disabled={isDisabled} />