From afdba2e302d01bea305f0751d6a236b49fd27e26 Mon Sep 17 00:00:00 2001 From: Hoang Dinh Date: Wed, 27 Nov 2024 13:43:38 +1000 Subject: [PATCH 1/9] examples --- examples/production_react/package.json | 25 +++++---- examples/production_react/src/App.tsx | 51 +++++++++---------- examples/production_react/src/Home.tsx | 2 +- .../src/components/Account.tsx | 2 +- .../src/components/ConnectWallet.tsx | 34 ++++++------- .../src/components/Transact.tsx | 8 +-- .../src/utils/ellipseAddress.ts | 4 +- 7 files changed, 63 insertions(+), 63 deletions(-) diff --git a/examples/production_react/package.json b/examples/production_react/package.json index 88c0ef2..7581554 100644 --- a/examples/production_react/package.json +++ b/examples/production_react/package.json @@ -13,34 +13,35 @@ }, "devDependencies": { "@algorandfoundation/algokit-client-generator": "^4.0.0", + "@playwright/test": "^1.35.0", + "@types/jest": "29.5.2", "@types/node": "^18.17.14", "@types/react": "^18.2.11", "@types/react-dom": "^18.2.4", + "@typescript-eslint/eslint-plugin": "^7.0.2", + "@typescript-eslint/parser": "^7.0.2", "@vitejs/plugin-react": "^4.2.1", "autoprefixer": "^10.4.14", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", - "@typescript-eslint/eslint-plugin": "^7.0.2", - "@typescript-eslint/parser": "^7.0.2", + "playwright": "^1.35.0", "postcss": "^8.4.24", "tailwindcss": "3.3.2", "ts-jest": "^29.1.1", - "@types/jest": "29.5.2", "ts-node": "^10.9.1", "typescript": "^5.1.6", - "@playwright/test": "^1.35.0", - "playwright": "^1.35.0", "vite": "^5.0.0", "vite-plugin-node-polyfills": "^0.22.0" }, "dependencies": { - "@algorandfoundation/algokit-utils": "^7.0.0", + "@algorandfoundation/algokit-utils": "^8.0.0", "@blockshake/defly-connect": "^1.1.6", "@daffiwallet/connect": "^1.0.3", - "@perawallet/connect": "^1.3.4", - "@txnlab/use-wallet": "^2.8.2", - "algosdk": ">=2.9.0 <3.0", + "@perawallet/connect": "^1.3.5", + "@txnlab/use-wallet": "^4.0.0-beta.2", + "@txnlab/use-wallet-react": "^4.0.0-beta.2", + "algosdk": "^3.0.0", "daisyui": "^4.0.0", "notistack": "^3.0.1", "react": "^18.2.0", @@ -55,7 +56,8 @@ "playwright:test": "playwright test", "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "lint:fix": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --fix", - "preview": "vite preview" + "preview": "vite preview", + "check-types": "tsc --noEmit" }, "eslintConfig": { "extends": [ @@ -76,6 +78,7 @@ ] }, "overrides": { - "ws@>7.0.0 <7.5.9": "7.5.10" + "ws@>7.0.0 <7.5.9": "7.5.10", + "algosdk@<3.0.0": "3.0.0" } } diff --git a/examples/production_react/src/App.tsx b/examples/production_react/src/App.tsx index 58feddf..5ed374e 100644 --- a/examples/production_react/src/App.tsx +++ b/examples/production_react/src/App.tsx @@ -1,33 +1,26 @@ -import { DeflyWalletConnect } from '@blockshake/defly-connect' -import { DaffiWalletConnect } from '@daffiwallet/connect' -import { PeraWalletConnect } from '@perawallet/connect' -import { PROVIDER_ID, ProvidersArray, WalletProvider, useInitializeProviders } from '@txnlab/use-wallet' -import algosdk from 'algosdk' +import { SupportedWallet, WalletId, WalletManager, WalletProvider } from '@txnlab/use-wallet-react' import { SnackbarProvider } from 'notistack' import Home from './Home' import { getAlgodConfigFromViteEnvironment, getKmdConfigFromViteEnvironment } from './utils/network/getAlgoClientConfigs' -let providersArray: ProvidersArray -if (import.meta.env.VITE_ALGOD_NETWORK === '') { +let supportedWallets: SupportedWallet[] +if (import.meta.env.VITE_ALGOD_NETWORK === 'localnet') { const kmdConfig = getKmdConfigFromViteEnvironment() - providersArray = [ + supportedWallets = [ { - id: PROVIDER_ID.KMD, - clientOptions: { - wallet: kmdConfig.wallet, - password: kmdConfig.password, - host: kmdConfig.server, + id: WalletId.KMD, + options: { + baseServer: kmdConfig.server, token: String(kmdConfig.token), port: String(kmdConfig.port), }, }, ] } else { - providersArray = [ - { id: PROVIDER_ID.DEFLY, clientStatic: DeflyWalletConnect }, - { id: PROVIDER_ID.PERA, clientStatic: PeraWalletConnect }, - { id: PROVIDER_ID.DAFFI, clientStatic: DaffiWalletConnect }, - { id: PROVIDER_ID.EXODUS }, + supportedWallets = [ + { id: WalletId.DEFLY }, + { id: WalletId.PERA }, + { id: WalletId.EXODUS }, // If you are interested in WalletConnect v2 provider // refer to https://github.com/TxnLab/use-wallet for detailed integration instructions ] @@ -36,20 +29,24 @@ if (import.meta.env.VITE_ALGOD_NETWORK === '') { export default function App() { const algodConfig = getAlgodConfigFromViteEnvironment() - const walletProviders = useInitializeProviders({ - providers: providersArray, - nodeConfig: { - network: algodConfig.network, - nodeServer: algodConfig.server, - nodePort: String(algodConfig.port), - nodeToken: String(algodConfig.token), + const walletManager = new WalletManager({ + wallets: supportedWallets, + defaultNetwork: algodConfig.network, + networks: { + [algodConfig.network]: { + name: algodConfig.network, + algod: { + baseServer: algodConfig.server, + port: algodConfig.port, + token: String(algodConfig.token), + }, + }, }, - algosdkStatic: algosdk, }) return ( - + diff --git a/examples/production_react/src/Home.tsx b/examples/production_react/src/Home.tsx index 42128d8..1fd37a1 100644 --- a/examples/production_react/src/Home.tsx +++ b/examples/production_react/src/Home.tsx @@ -1,5 +1,5 @@ // src/components/Home.tsx -import { useWallet } from '@txnlab/use-wallet' +import { useWallet } from '@txnlab/use-wallet-react' import React, { useState } from 'react' import ConnectWallet from './components/ConnectWallet' import Transact from './components/Transact' diff --git a/examples/production_react/src/components/Account.tsx b/examples/production_react/src/components/Account.tsx index 8324312..081ce47 100644 --- a/examples/production_react/src/components/Account.tsx +++ b/examples/production_react/src/components/Account.tsx @@ -1,4 +1,4 @@ -import { useWallet } from '@txnlab/use-wallet' +import { useWallet } from '@txnlab/use-wallet-react' import { useMemo } from 'react' import { ellipseAddress } from '../utils/ellipseAddress' import { getAlgodConfigFromViteEnvironment } from '../utils/network/getAlgoClientConfigs' diff --git a/examples/production_react/src/components/ConnectWallet.tsx b/examples/production_react/src/components/ConnectWallet.tsx index c4225bc..8ff01dc 100644 --- a/examples/production_react/src/components/ConnectWallet.tsx +++ b/examples/production_react/src/components/ConnectWallet.tsx @@ -1,4 +1,4 @@ -import { Provider, useWallet } from '@txnlab/use-wallet' +import { useWallet, Wallet, WalletId } from '@txnlab/use-wallet-react' import Account from './Account' interface ConnectWalletInterface { @@ -7,9 +7,9 @@ interface ConnectWalletInterface { } const ConnectWallet = ({ openModal, closeModal }: ConnectWalletInterface) => { - const { providers, activeAddress } = useWallet() + const { wallets, activeAddress } = useWallet() - const isKmd = (provider: Provider) => provider.metadata.name.toLowerCase() === 'kmd' + const isKmd = (wallet: Wallet) => wallet.id === WalletId.KMD return ( @@ -25,23 +25,23 @@ const ConnectWallet = ({ openModal, closeModal }: ConnectWalletInterface) => { )} {!activeAddress && - providers?.map((provider) => ( + wallets?.map((wallet) => ( ))} @@ -60,16 +60,16 @@ const ConnectWallet = ({ openModal, closeModal }: ConnectWalletInterface) => { ))} @@ -60,16 +60,16 @@ const ConnectWallet = ({ openModal, closeModal }: ConnectWalletInterface) => { ))} @@ -60,16 +60,16 @@ const ConnectWallet = ({ openModal, closeModal }: ConnectWalletInterface) => { ))} @@ -60,16 +60,16 @@ const ConnectWallet = ({ openModal, closeModal }: ConnectWalletInterface) => { ))} @@ -60,16 +60,16 @@ const ConnectWallet = ({ openModal, closeModal }: ConnectWalletInterface) => { ))} @@ -60,16 +60,16 @@ const ConnectWallet = ({ openModal, closeModal }: ConnectWalletInterface) => { ))} @@ -60,16 +60,16 @@ const ConnectWallet = ({ openModal, closeModal }: ConnectWalletInterface) => {