diff --git a/apps/gallery/package.json b/apps/gallery/package.json index 3b4602fb1f..585a1a1bb5 100644 --- a/apps/gallery/package.json +++ b/apps/gallery/package.json @@ -1,6 +1,6 @@ { "name": "@apps/gallery", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "private": true, "main": "index.js", "scripts": { @@ -9,7 +9,7 @@ "lint": "eslint . --ext .js,.jsx,.ts,.tsx" }, "dependencies": { - "@web3modal/ui": "3.0.0-alpha.5", + "@web3modal/ui": "3.0.0-73ed03f2", "lit": "2.8.0", "storybook": "7.4.0" }, diff --git a/apps/gallery/stories/composites/wui-connect-button.stories.ts b/apps/gallery/stories/composites/wui-connect-button.stories.ts index 0482714d53..19019e3c7b 100644 --- a/apps/gallery/stories/composites/wui-connect-button.stories.ts +++ b/apps/gallery/stories/composites/wui-connect-button.stories.ts @@ -9,18 +9,13 @@ export default { title: 'Composites/wui-connect-button', args: { size: 'md', - disabled: false, - loading: false, - text: 'Connect Wallet' + loading: false }, argTypes: { size: { options: ['sm', 'md'], control: { type: 'select' } }, - disabled: { - control: { type: 'boolean' } - }, loading: { control: { type: 'boolean' } } @@ -28,11 +23,9 @@ export default { } as Component export const Default: Component = { - render: args => - html`` + render: args => html` + + ${args.loading ? 'Connecting...' : 'Connect Wallet'} + + ` } diff --git a/apps/laboratory/package.json b/apps/laboratory/package.json index 1e905e4a20..97fd70e426 100644 --- a/apps/laboratory/package.json +++ b/apps/laboratory/package.json @@ -1,6 +1,6 @@ { "name": "@apps/laboratory", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "private": true, "scripts": { "dev:laboratory": "next dev", @@ -11,9 +11,9 @@ "@chakra-ui/react": "2.8.0", "@emotion/react": "11.11.1", "@emotion/styled": "11.11.0", - "@sentry/browser": "7.66.0", - "@sentry/react": "7.66.0", - "@web3modal/wagmi": "3.0.0-alpha.5", + "@sentry/browser": "7.67.0", + "@sentry/react": "7.67.0", + "@web3modal/wagmi": "3.0.0-73ed03f2", "framer-motion": "10.16.4", "next": "13.4.19", "react-icons": "4.10.1", diff --git a/apps/laboratory/src/components/ConnectButton.tsx b/apps/laboratory/src/components/ConnectButton.tsx index ebf437abd9..f9d87c4d15 100644 --- a/apps/laboratory/src/components/ConnectButton.tsx +++ b/apps/laboratory/src/components/ConnectButton.tsx @@ -1,13 +1,10 @@ import { Button, useToast } from '@chakra-ui/react' -import { useWeb3Modal } from '@web3modal/wagmi/react' -import { useAccount, useDisconnect, useSignMessage } from 'wagmi' +import { useAccount, useSignMessage } from 'wagmi' export function ConnectButton() { const toast = useToast() - const { isConnected, address } = useAccount() - const { disconnect } = useDisconnect() + const { isConnected } = useAccount() const { signMessageAsync } = useSignMessage({ message: 'Hello Web3Modal!' }) - const modal = useWeb3Modal() async function onSignMessage() { try { @@ -23,13 +20,10 @@ export function ConnectButton() { } } - return isConnected ? ( + return ( <> - - - + + {isConnected ? : null} - ) : ( - ) } diff --git a/apps/laboratory/src/components/NetworksButton.tsx b/apps/laboratory/src/components/NetworksButton.tsx index 4d6eed1cdf..3a9dfe7fd2 100644 --- a/apps/laboratory/src/components/NetworksButton.tsx +++ b/apps/laboratory/src/components/NetworksButton.tsx @@ -1,12 +1,3 @@ -import { Button } from '@chakra-ui/react' -import { useWeb3Modal } from '@web3modal/wagmi/react' -import { useNetwork } from 'wagmi' - export function NetworksButton() { - const { chain } = useNetwork() - const modal = useWeb3Modal() - - return ( - - ) + return } diff --git a/apps/laboratory/src/pages/index.tsx b/apps/laboratory/src/pages/index.tsx index 4a8cbb8136..91cefec869 100644 --- a/apps/laboratory/src/pages/index.tsx +++ b/apps/laboratory/src/pages/index.tsx @@ -46,7 +46,8 @@ export const wagmiConfig = defaultWagmiConfig({ chains, projectId, appName: 'Web export const modal = createWeb3Modal({ wagmiConfig, projectId, - chains + chains, + defaultChain: zora }) export default function HomePage() { diff --git a/examples/react-wagmi/index.html b/examples/react-wagmi/index.html index 38475e5b67..5b772285a8 100644 --- a/examples/react-wagmi/index.html +++ b/examples/react-wagmi/index.html @@ -7,6 +7,6 @@
- + diff --git a/examples/react-wagmi/package.json b/examples/react-wagmi/package.json index 6f3d3af1f0..aadb740a32 100644 --- a/examples/react-wagmi/package.json +++ b/examples/react-wagmi/package.json @@ -1,13 +1,13 @@ { "name": "@examples/react-wagmi", "private": true, - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "scripts": { "dev:example": "vite --port 3001", - "build:example": "vite build" + "build:examples": "vite build" }, "dependencies": { - "@web3modal/wagmi": "3.0.0-alpha.5" + "@web3modal/wagmi": "3.0.0-73ed03f2" }, "devDependencies": { "@vitejs/plugin-react": "4.0.4" diff --git a/examples/react-wagmi/src/App.jsx b/examples/react-wagmi/src/App.tsx similarity index 69% rename from examples/react-wagmi/src/App.jsx rename to examples/react-wagmi/src/App.tsx index 33ac6d5472..c3961f7ffd 100644 --- a/examples/react-wagmi/src/App.jsx +++ b/examples/react-wagmi/src/App.tsx @@ -2,7 +2,7 @@ import { createWeb3Modal, defaultWagmiConfig, useWeb3Modal } from '@web3modal/wa import { WagmiConfig } from 'wagmi' import { arbitrum, mainnet } from 'wagmi/chains' -// 1. Get projectId +// @ts-expect-error 1. Get projectId const projectId = import.meta.env.VITE_PROJECT_ID if (!projectId) { throw new Error('VITE_PROJECT_ID is not set') @@ -20,7 +20,7 @@ createWeb3Modal({ themeMode: 'light', themeVariables: { '--w3m-color-mix': '#00DCFF', - '--w3m-color-mix-strength': 50 + '--w3m-color-mix-strength': 20 } }) @@ -30,8 +30,13 @@ export default function App() { return ( - - + + + + + + + ) } diff --git a/examples/react-wagmi/src/main.jsx b/examples/react-wagmi/src/main.tsx similarity index 100% rename from examples/react-wagmi/src/main.jsx rename to examples/react-wagmi/src/main.tsx diff --git a/examples/react-wagmi/tsconfig.json b/examples/react-wagmi/tsconfig.json new file mode 100644 index 0000000000..df10d65521 --- /dev/null +++ b/examples/react-wagmi/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "jsx": "preserve", + "noEmit": true, + "incremental": true + }, + "include": ["src"] +} diff --git a/examples/vue-wagmi/package.json b/examples/vue-wagmi/package.json index a837a8c8a3..d729022ffd 100644 --- a/examples/vue-wagmi/package.json +++ b/examples/vue-wagmi/package.json @@ -1,13 +1,13 @@ { "name": "@examples/vue-wagmi", "private": true, - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "scripts": { "dev:example": "vite --port 3002", - "build:example": "vite build" + "build:examples": "vite build" }, "dependencies": { - "@web3modal/wagmi": "3.0.0-alpha.5" + "@web3modal/wagmi": "3.0.0-73ed03f2" }, "devDependencies": { "@vitejs/plugin-vue": "4.3.4" diff --git a/examples/vue-wagmi/src/App.vue b/examples/vue-wagmi/src/App.vue index 9045009e0a..5f3c325294 100644 --- a/examples/vue-wagmi/src/App.vue +++ b/examples/vue-wagmi/src/App.vue @@ -1,8 +1,8 @@ diff --git a/lerna.json b/lerna.json index d51972dd2c..f806816827 100644 --- a/lerna.json +++ b/lerna.json @@ -9,6 +9,6 @@ "apps/*", "examples/*" ], - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/package-lock.json b/package-lock.json index 5b0a6f21eb..d53c76f4e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,9 +40,9 @@ }, "apps/gallery": { "name": "@apps/gallery", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "dependencies": { - "@web3modal/ui": "3.0.0-alpha.5", + "@web3modal/ui": "3.0.0-73ed03f2", "lit": "2.8.0", "storybook": "7.4.0" }, @@ -68,14 +68,14 @@ }, "apps/laboratory": { "name": "@apps/laboratory", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "dependencies": { "@chakra-ui/react": "2.8.0", "@emotion/react": "11.11.1", "@emotion/styled": "11.11.0", - "@sentry/browser": "7.66.0", - "@sentry/react": "7.66.0", - "@web3modal/wagmi": "3.0.0-alpha.5", + "@sentry/browser": "7.67.0", + "@sentry/react": "7.67.0", + "@web3modal/wagmi": "3.0.0-73ed03f2", "framer-motion": "10.16.4", "next": "13.4.19", "react-icons": "4.10.1", @@ -108,9 +108,9 @@ }, "examples/react-wagmi": { "name": "@examples/react-wagmi", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "dependencies": { - "@web3modal/wagmi": "3.0.0-alpha.5" + "@web3modal/wagmi": "3.0.0-73ed03f2" }, "devDependencies": { "@vitejs/plugin-react": "4.0.4" @@ -118,9 +118,9 @@ }, "examples/vue-wagmi": { "name": "@examples/vue-wagmi", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "dependencies": { - "@web3modal/wagmi": "3.0.0-alpha.5" + "@web3modal/wagmi": "3.0.0-73ed03f2" }, "devDependencies": { "@vitejs/plugin-vue": "4.3.4" @@ -6614,13 +6614,13 @@ } }, "node_modules/@sentry-internal/tracing": { - "version": "7.66.0", - "resolved": "https://registry.npmjs.org/@sentry-internal/tracing/-/tracing-7.66.0.tgz", - "integrity": "sha512-3vCgC2hC3T45pn53yTDVcRpHoJTBxelDPPZVsipAbZnoOVPkj7n6dNfDhj3I3kwWCBPahPkXmE+R4xViR8VqJg==", + "version": "7.67.0", + "resolved": "https://registry.npmjs.org/@sentry-internal/tracing/-/tracing-7.67.0.tgz", + "integrity": "sha512-+3wpnzW2HczPlZsp1pWtdOavBKLK/tu1qDEg+blqLfW7b/qZZ8hqQ+A+2mEWRLgWfIoGZ8t4U84nN4tzDXv+nQ==", "dependencies": { - "@sentry/core": "7.66.0", - "@sentry/types": "7.66.0", - "@sentry/utils": "7.66.0", + "@sentry/core": "7.67.0", + "@sentry/types": "7.67.0", + "@sentry/utils": "7.67.0", "tslib": "^2.4.1 || ^1.9.3" }, "engines": { @@ -6628,15 +6628,15 @@ } }, "node_modules/@sentry/browser": { - "version": "7.66.0", - "resolved": "https://registry.npmjs.org/@sentry/browser/-/browser-7.66.0.tgz", - "integrity": "sha512-rW037rf8jkhyykG38+HUdwkRCKHJEMM5NkCqPIO5zuuxfLKukKdI2rbvgJ93s3/9UfsTuDFcKFL1u43mCn6sDw==", - "dependencies": { - "@sentry-internal/tracing": "7.66.0", - "@sentry/core": "7.66.0", - "@sentry/replay": "7.66.0", - "@sentry/types": "7.66.0", - "@sentry/utils": "7.66.0", + "version": "7.67.0", + "resolved": "https://registry.npmjs.org/@sentry/browser/-/browser-7.67.0.tgz", + "integrity": "sha512-5J7QUGJVKiltVJPSHwlBu/xmicNB7g5ARcgH8YEyu2LoxjLvZPUqWRD/zTWVYyW20sbgExrB39oyRwmkzN449A==", + "dependencies": { + "@sentry-internal/tracing": "7.67.0", + "@sentry/core": "7.67.0", + "@sentry/replay": "7.67.0", + "@sentry/types": "7.67.0", + "@sentry/utils": "7.67.0", "tslib": "^2.4.1 || ^1.9.3" }, "engines": { @@ -6644,12 +6644,12 @@ } }, "node_modules/@sentry/core": { - "version": "7.66.0", - "resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.66.0.tgz", - "integrity": "sha512-WMAEPN86NeCJ1IT48Lqiz4MS5gdDjBwP4M63XP4msZn9aujSf2Qb6My5uT87AJr9zBtgk8MyJsuHr35F0P3q1w==", + "version": "7.67.0", + "resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.67.0.tgz", + "integrity": "sha512-apk0WHnFJTHX86TvN4LOa2GBfguKwvV94WsssyizMi4qurGN2V0I8ZUmlypjBxvMY9MOBZ/2LwgYPf3U1QeE5g==", "dependencies": { - "@sentry/types": "7.66.0", - "@sentry/utils": "7.66.0", + "@sentry/types": "7.67.0", + "@sentry/utils": "7.67.0", "tslib": "^2.4.1 || ^1.9.3" }, "engines": { @@ -6657,13 +6657,13 @@ } }, "node_modules/@sentry/react": { - "version": "7.66.0", - "resolved": "https://registry.npmjs.org/@sentry/react/-/react-7.66.0.tgz", - "integrity": "sha512-TC7kCkLoo+Klp9uywdV6tg8DDyn1CrTdndJghO6PoGz6sCa9k+t7K+z4E7MlgDoh3wiZwS2G2zhkT/xVeDRvJA==", + "version": "7.67.0", + "resolved": "https://registry.npmjs.org/@sentry/react/-/react-7.67.0.tgz", + "integrity": "sha512-qgEi2umAszEmipUAYf2fVaBXaSgZCp5IEBRw8onYrdxCEu980QA9zbPnnA0pij24tm2UNc8ca3nZrDy6xQjeSQ==", "dependencies": { - "@sentry/browser": "7.66.0", - "@sentry/types": "7.66.0", - "@sentry/utils": "7.66.0", + "@sentry/browser": "7.67.0", + "@sentry/types": "7.67.0", + "@sentry/utils": "7.67.0", "hoist-non-react-statics": "^3.3.2", "tslib": "^2.4.1 || ^1.9.3" }, @@ -6675,32 +6675,32 @@ } }, "node_modules/@sentry/replay": { - "version": "7.66.0", - "resolved": "https://registry.npmjs.org/@sentry/replay/-/replay-7.66.0.tgz", - "integrity": "sha512-5Y2SlVTOFTo3uIycv0mRneBakQtLgWkOnsJaC5LB0Ip0TqVKiMCbQ578vvXp+yvRj4LcS1gNd98xTTNojBoQNg==", + "version": "7.67.0", + "resolved": "https://registry.npmjs.org/@sentry/replay/-/replay-7.67.0.tgz", + "integrity": "sha512-PGFt281hV4W1BFCY09JQmwdQXvI9rhiqIIOGHviyH7GrHBwWLxF1iRuBS8RUMFYt9ZHFq5oDt6M2z3qBQOZGLQ==", "dependencies": { - "@sentry/core": "7.66.0", - "@sentry/types": "7.66.0", - "@sentry/utils": "7.66.0" + "@sentry/core": "7.67.0", + "@sentry/types": "7.67.0", + "@sentry/utils": "7.67.0" }, "engines": { "node": ">=12" } }, "node_modules/@sentry/types": { - "version": "7.66.0", - "resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.66.0.tgz", - "integrity": "sha512-uUMSoSiar6JhuD8p7ON/Ddp4JYvrVd2RpwXJRPH1A4H4Bd4DVt1mKJy1OLG6HdeQv39XyhB1lPZckKJg4tATPw==", + "version": "7.67.0", + "resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.67.0.tgz", + "integrity": "sha512-GV/Hxdsp/hes1YQGPGgSUG1IHRNQVJMnCfYcpuZtZI6CvNJ+7qNOLkdmC/xGFwfpYH9kYsFBvmGsmeC6yUENYA==", "engines": { "node": ">=8" } }, "node_modules/@sentry/utils": { - "version": "7.66.0", - "resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.66.0.tgz", - "integrity": "sha512-9GYUVgXjK66uXXcLXVMXVzlptqMtq1eJENCuDeezQiEFrNA71KkLDg00wESp+LL+bl3wpVTBApArpbF6UEG5hQ==", + "version": "7.67.0", + "resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.67.0.tgz", + "integrity": "sha512-OstjIfAD0xPWVnIRzoAtFBW+YTmxix4h3ehgtFxhA4VJHkC9KXchaTNwk+nlRy/nx4phx5vW9p7YWhO3kJBJmA==", "dependencies": { - "@sentry/types": "7.66.0", + "@sentry/types": "7.67.0", "tslib": "^2.4.1 || ^1.9.3" }, "engines": { @@ -23557,7 +23557,7 @@ }, "packages/core": { "name": "@web3modal/core", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "license": "Apache-2.0", "dependencies": { "valtio": "1.11.2" @@ -23589,7 +23589,7 @@ }, "packages/polyfills": { "name": "@web3modal/polyfills", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "license": "Apache-2.0", "dependencies": { "buffer": "6.0.3" @@ -23620,11 +23620,11 @@ }, "packages/scaffold": { "name": "@web3modal/scaffold", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "license": "Apache-2.0", "dependencies": { - "@web3modal/core": "3.0.0-alpha.5", - "@web3modal/ui": "3.0.0-alpha.5", + "@web3modal/core": "3.0.0-73ed03f2", + "@web3modal/ui": "3.0.0-73ed03f2", "lit": "2.8.0" } }, @@ -23640,7 +23640,7 @@ }, "packages/ui": { "name": "@web3modal/ui", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "license": "Apache-2.0", "dependencies": { "lit": "2.8.0", @@ -23665,11 +23665,11 @@ }, "packages/wagmi": { "name": "@web3modal/wagmi", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "license": "Apache-2.0", "dependencies": { - "@web3modal/polyfills": "3.0.0-alpha.5", - "@web3modal/scaffold": "3.0.0-alpha.5" + "@web3modal/polyfills": "3.0.0-73ed03f2", + "@web3modal/scaffold": "3.0.0-73ed03f2" }, "peerDependencies": { "@wagmi/core": ">=1", diff --git a/package.json b/package.json index de87fd298d..bdd8e5a5ba 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "examples": "turbo run dev:example --parallel", "build:gallery": "turbo run build:gallery", "build:laboratory": "turbo run build:laboratory", + "build:examples": "turbo run build:examples", "test": "turbo run test --parallel", "typecheck": "turbo run typecheck --parallel", "lint": "turbo run lint --parallel", diff --git a/packages/core/package.json b/packages/core/package.json index 53c4ae4ec6..5722d72105 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@web3modal/core", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "type": "module", "main": "./dist/esm/index.js", "types": "./dist/types/index.d.ts", diff --git a/packages/core/src/controllers/AssetController.ts b/packages/core/src/controllers/AssetController.ts index a228603c4e..f3ada0f29c 100644 --- a/packages/core/src/controllers/AssetController.ts +++ b/packages/core/src/controllers/AssetController.ts @@ -1,3 +1,4 @@ +import { subscribe as sub } from 'valtio' import { subscribeKey as subKey } from 'valtio/utils' import { proxy } from 'valtio/vanilla' @@ -23,6 +24,10 @@ const state = proxy({ export const AssetController = { state, + subscribeNetworkImages(callback: (value: AssetControllerState['networkImages']) => void) { + return sub(state.networkImages, () => callback(state.networkImages)) + }, + subscribeKey(key: K, callback: (value: AssetControllerState[K]) => void) { return subKey(state, key, callback) }, diff --git a/packages/core/src/utils/CoreHelperUtil.ts b/packages/core/src/utils/CoreHelperUtil.ts index a4106fa236..b7349706f4 100644 --- a/packages/core/src/utils/CoreHelperUtil.ts +++ b/packages/core/src/utils/CoreHelperUtil.ts @@ -112,5 +112,19 @@ export const CoreHelperUtil = { }) return Promise.race([imagePromise, CoreHelperUtil.wait(2000)]) + }, + + formatBalance(balance: string | undefined, symbol: string | undefined) { + let formattedBalance = undefined + + if (balance === '0.0') { + formattedBalance = '0' + } else if (typeof balance === 'string' && balance.length > 6) { + formattedBalance = balance.substring(0, 6) + } else if (typeof balance === 'string') { + formattedBalance = balance + } + + return formattedBalance ? `${formattedBalance} ${symbol}` : '0.0000' } } diff --git a/packages/polyfills/package.json b/packages/polyfills/package.json index 641e81ce03..f94ba17c4b 100644 --- a/packages/polyfills/package.json +++ b/packages/polyfills/package.json @@ -1,6 +1,6 @@ { "name": "@web3modal/polyfills", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "type": "module", "main": "./dist/esm/index.js", "types": "./dist/types/index.d.ts", diff --git a/packages/scaffold/index.ts b/packages/scaffold/index.ts index 4ea64dfe8d..58cb6ff7f8 100644 --- a/packages/scaffold/index.ts +++ b/packages/scaffold/index.ts @@ -1,4 +1,8 @@ +export * from './src/modal/w3m-account-button/index.js' +export * from './src/modal/w3m-button/index.js' +export * from './src/modal/w3m-connect-button/index.js' export * from './src/modal/w3m-modal/index.js' +export * from './src/modal/w3m-network-button/index.js' export * from './src/modal/w3m-router/index.js' export * from './src/views/w3m-account-view/index.js' diff --git a/packages/scaffold/package.json b/packages/scaffold/package.json index 2bc08708ac..fe1b9b5545 100644 --- a/packages/scaffold/package.json +++ b/packages/scaffold/package.json @@ -1,6 +1,6 @@ { "name": "@web3modal/scaffold", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "type": "module", "main": "./dist/esm/index.js", "types": "./dist/types/index.d.ts", @@ -15,8 +15,8 @@ "lint": "eslint . --ext .js,.jsx,.ts,.tsx" }, "dependencies": { - "@web3modal/core": "3.0.0-alpha.5", - "@web3modal/ui": "3.0.0-alpha.5", + "@web3modal/core": "3.0.0-73ed03f2", + "@web3modal/ui": "3.0.0-73ed03f2", "lit": "2.8.0" }, "keywords": [ diff --git a/packages/scaffold/src/modal/w3m-account-button/index.ts b/packages/scaffold/src/modal/w3m-account-button/index.ts new file mode 100644 index 0000000000..a3a3ab0fbe --- /dev/null +++ b/packages/scaffold/src/modal/w3m-account-button/index.ts @@ -0,0 +1,96 @@ +import { + AccountController, + AssetController, + CoreHelperUtil, + ModalController, + NetworkController +} from '@web3modal/core' +import type { WuiAccountButton } from '@web3modal/ui' +import { LitElement, html } from 'lit' +import { customElement, property, state } from 'lit/decorators.js' +import { ifDefined } from 'lit/directives/if-defined.js' + +@customElement('w3m-account-button') +export class W3mAccountButton extends LitElement { + // -- Members ------------------------------------------- // + private unsubscribe: (() => void)[] = [] + + private readonly networkImages = AssetController.state.networkImages + + // -- State & Properties -------------------------------- // + @property({ type: Boolean }) public disabled?: WuiAccountButton['disabled'] = false + + @property() public balance?: 'show' | 'hide' = 'show' + + @state() private address = AccountController.state.address + + @state() private balanceVal = AccountController.state.balance + + @state() private balanceSymbol = AccountController.state.balanceSymbol + + @state() private profileName = AccountController.state.profileName + + @state() private profileImage = AccountController.state.profileImage + + @state() private network = NetworkController.state.caipNetwork + + // -- Lifecycle ----------------------------------------- // + public constructor() { + super() + this.unsubscribe.push( + ...[ + AccountController.subscribe(val => { + if (val.isConnected) { + this.address = val.address + this.balanceVal = val.balance + this.profileName = val.profileName + this.profileImage = val.profileImage + this.balanceSymbol = val.balanceSymbol + } else { + this.address = '' + this.balanceVal = '' + this.profileName = '' + this.profileImage = '' + this.balanceSymbol = '' + } + }), + NetworkController.subscribeKey('caipNetwork', val => (this.network = val)) + ] + ) + } + + public override disconnectedCallback() { + this.unsubscribe.forEach(unsubscribe => unsubscribe()) + } + + // -- Render -------------------------------------------- // + public override render() { + const networkImage = this.networkImages[this.network?.imageId ?? ''] + const showBalance = this.balance === 'show' + + return html` + + + ` + } + + // -- Private ------------------------------------------- // + private onClick() { + ModalController.open() + } +} + +declare global { + interface HTMLElementTagNameMap { + 'w3m-account-button': W3mAccountButton + } +} diff --git a/packages/scaffold/src/modal/w3m-button/index.ts b/packages/scaffold/src/modal/w3m-button/index.ts new file mode 100644 index 0000000000..b9716b0d02 --- /dev/null +++ b/packages/scaffold/src/modal/w3m-button/index.ts @@ -0,0 +1,64 @@ +import { AccountController } from '@web3modal/core' +import { LitElement, html } from 'lit' +import { customElement, property, state } from 'lit/decorators.js' +import { ifDefined } from 'lit/directives/if-defined.js' +import type { W3mAccountButton } from '../w3m-account-button/index.js' +import type { W3mConnectButton } from '../w3m-connect-button/index.js' + +@customElement('w3m-button') +export class W3mButton extends LitElement { + // -- Members ------------------------------------------- // + private unsubscribe: (() => void)[] = [] + + // -- State & Properties -------------------------------- // + @property({ type: Boolean }) public disabled?: W3mAccountButton['disabled'] = false + + @property() public balance?: W3mAccountButton['balance'] = undefined + + @property() public size?: W3mConnectButton['size'] = undefined + + @property() public label?: W3mConnectButton['label'] = undefined + + @property() public loadingLabel?: W3mConnectButton['loadingLabel'] = undefined + + @state() private isAccount = AccountController.state.isConnected + + // -- Lifecycle ----------------------------------------- // + public constructor() { + super() + this.unsubscribe.push( + AccountController.subscribeKey('isConnected', val => { + this.isAccount = val + }) + ) + } + + public override disconnectedCallback() { + this.unsubscribe.forEach(unsubscribe => unsubscribe()) + } + + // -- Render -------------------------------------------- // + public override render() { + return this.isAccount + ? html` + + + ` + : html` + + ` + } +} + +declare global { + interface HTMLElementTagNameMap { + 'w3m-button': W3mButton + } +} diff --git a/packages/scaffold/src/modal/w3m-connect-button/index.ts b/packages/scaffold/src/modal/w3m-connect-button/index.ts new file mode 100644 index 0000000000..b0c3885e34 --- /dev/null +++ b/packages/scaffold/src/modal/w3m-connect-button/index.ts @@ -0,0 +1,58 @@ +import { ModalController } from '@web3modal/core' +import type { WuiConnectButton } from '@web3modal/ui' +import { LitElement, html } from 'lit' +import { customElement, property, state } from 'lit/decorators.js' +import { ifDefined } from 'lit/directives/if-defined.js' + +@customElement('w3m-connect-button') +export class W3mConnectButton extends LitElement { + // -- Members ------------------------------------------- // + private unsubscribe: (() => void)[] = [] + + // -- State & Properties -------------------------------- // + @property() size?: WuiConnectButton['size'] = 'md' + + @property() label? = 'Connect Wallet' + + @property() loadingLabel? = 'Connecting...' + + @state() private open = ModalController.state.open + + // -- Lifecycle ----------------------------------------- // + public constructor() { + super() + this.unsubscribe.push(ModalController.subscribeKey('open', val => (this.open = val))) + } + + public override disconnectedCallback() { + this.unsubscribe.forEach(unsubscribe => unsubscribe()) + } + + // -- Render -------------------------------------------- // + public override render() { + return html` + + ${this.open ? this.loadingLabel : this.label} + + ` + } + + // -- Private ------------------------------------------- // + private onClick() { + if (this.open) { + ModalController.close() + } else { + ModalController.open() + } + } +} + +declare global { + interface HTMLElementTagNameMap { + 'w3m-connect-button': W3mConnectButton + } +} diff --git a/packages/scaffold/src/modal/w3m-network-button/index.ts b/packages/scaffold/src/modal/w3m-network-button/index.ts new file mode 100644 index 0000000000..2f5948eb86 --- /dev/null +++ b/packages/scaffold/src/modal/w3m-network-button/index.ts @@ -0,0 +1,63 @@ +import { + AccountController, + AssetController, + ModalController, + NetworkController +} from '@web3modal/core' +import type { WuiNetworkButton } from '@web3modal/ui' +import { LitElement, html } from 'lit' +import { customElement, property, state } from 'lit/decorators.js' +import { ifDefined } from 'lit/directives/if-defined.js' + +@customElement('w3m-network-button') +export class W3mNetworkButton extends LitElement { + // -- Members ------------------------------------------- // + private unsubscribe: (() => void)[] = [] + + // -- State & Properties -------------------------------- // + @property() public variant?: WuiNetworkButton['variant'] = 'fill' + + @state() private networkImages = AssetController.state.networkImages + + @state() private network = NetworkController.state.caipNetwork + + @state() private connected = AccountController.state.isConnected + + // -- Lifecycle ----------------------------------------- // + public constructor() { + super() + this.unsubscribe.push( + ...[ + NetworkController.subscribeKey('caipNetwork', val => (this.network = val)), + AccountController.subscribeKey('isConnected', val => (this.connected = val)), + AssetController.subscribeNetworkImages(val => (this.networkImages = { ...val })) + ] + ) + } + + public override disconnectedCallback() { + this.unsubscribe.forEach(unsubscribe => unsubscribe()) + } + + // -- Render -------------------------------------------- // + public override render() { + const networkImage = this.networkImages[this.network?.imageId ?? ''] + + return html` + + ${this.network?.name ?? (this.connected ? 'Unknown Network' : 'Select Network')} + + ` + } + + // -- Private ------------------------------------------- // + private onClick() { + ModalController.open({ view: 'Networks' }) + } +} + +declare global { + interface HTMLElementTagNameMap { + 'w3m-network-button': W3mNetworkButton + } +} diff --git a/packages/scaffold/src/utils/w3m-connecting-widget/index.ts b/packages/scaffold/src/utils/w3m-connecting-widget/index.ts index 92d81a079d..3bffbbf04a 100644 --- a/packages/scaffold/src/utils/w3m-connecting-widget/index.ts +++ b/packages/scaffold/src/utils/w3m-connecting-widget/index.ts @@ -137,7 +137,7 @@ export class W3mConnectingWidget extends LitElement { diff --git a/packages/scaffold/src/views/w3m-account-view/index.ts b/packages/scaffold/src/views/w3m-account-view/index.ts index 800084549d..82c416fac8 100644 --- a/packages/scaffold/src/views/w3m-account-view/index.ts +++ b/packages/scaffold/src/views/w3m-account-view/index.ts @@ -100,7 +100,9 @@ export class W3mAccountView extends LitElement { > - ${this.showBalance()} + + ${CoreHelperUtil.formatBalance(this.balance, this.balanceSymbol)} + Block Explorer @@ -173,20 +175,6 @@ export class W3mAccountView extends LitElement { } } - private showBalance() { - let formattedBalance = undefined - - if (this.balance === '0.0') { - formattedBalance = '0' - } else if (typeof this.balance === 'string' && this.balance.length > 6) { - formattedBalance = this.balance.substring(0, 6) - } else if (typeof this.balance === 'string') { - formattedBalance = this.balance - } - - return formattedBalance ? `${formattedBalance} ${this.balanceSymbol}` : '_._' - } - private onExplorer() { const { addressExplorerUrl } = AccountController.state if (addressExplorerUrl) { diff --git a/packages/ui/package.json b/packages/ui/package.json index 55db40353c..4b57d73cc9 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -1,6 +1,6 @@ { "name": "@web3modal/ui", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "type": "module", "main": "./dist/esm/index.js", "types": "./dist/types/index.d.ts", diff --git a/packages/ui/src/composites/wui-connect-button/index.ts b/packages/ui/src/composites/wui-connect-button/index.ts index d865699250..b506003c51 100644 --- a/packages/ui/src/composites/wui-connect-button/index.ts +++ b/packages/ui/src/composites/wui-connect-button/index.ts @@ -14,26 +14,17 @@ export class WuiConnectButton extends LitElement { // -- State & Properties -------------------------------- // @property() public size: Exclude = 'md' - @property({ type: Boolean }) public disabled = false - @property({ type: Boolean }) public loading = false - @property() public text = 'Connect Wallet' - // -- Render -------------------------------------------- // public override render() { const textVariant = this.size === 'md' ? 'paragraph-600' : 'small-600' return html` - ` diff --git a/packages/ui/src/composites/wui-connect-button/styles.ts b/packages/ui/src/composites/wui-connect-button/styles.ts index 5efc8cce91..e917006954 100644 --- a/packages/ui/src/composites/wui-connect-button/styles.ts +++ b/packages/ui/src/composites/wui-connect-button/styles.ts @@ -69,10 +69,6 @@ export default css` padding-left: var(--wui-spacing-3xs); } - button.loading > wui-text { - color: var(--wui-color-accent-100); - } - wui-loading-spinner { width: 14px; height: 14px; diff --git a/packages/ui/src/composites/wui-network-button/index.ts b/packages/ui/src/composites/wui-network-button/index.ts index 5ff2450ab3..e0be5415fc 100644 --- a/packages/ui/src/composites/wui-network-button/index.ts +++ b/packages/ui/src/composites/wui-network-button/index.ts @@ -22,7 +22,9 @@ export class WuiNetworkButton extends LitElement { return html` ` } diff --git a/packages/wagmi/exports/react.tsx b/packages/wagmi/exports/react.tsx index 5ede440b73..67514c6944 100644 --- a/packages/wagmi/exports/react.tsx +++ b/packages/wagmi/exports/react.tsx @@ -1,5 +1,11 @@ 'use client' +import type { + W3mAccountButton, + W3mButton, + W3mConnectButton, + W3mNetworkButton +} from '@web3modal/scaffold' import { useEffect, useState } from 'react' import type { Web3ModalOptions } from '../src/client.js' import { Web3Modal } from '../src/client.js' @@ -7,14 +13,27 @@ import { VERSION } from '../src/utils/constants.js' // -- Types ------------------------------------------------------------------- export type { Web3ModalOptions } from '../src/client.js' + type OpenOptions = Parameters[0] + type ThemeModeOptions = Parameters[0] + type ThemeVariablesOptions = Parameters[0] +declare global { + namespace JSX { + interface IntrinsicElements { + 'w3m-connect-button': Pick + 'w3m-account-button': Pick + 'w3m-network-button': Pick + 'w3m-button': Pick + } + } +} + // -- Setup ------------------------------------------------------------------- let modal: Web3Modal | undefined = undefined -// -- Lib --------------------------------------------------------------------- export function createWeb3Modal(options: Web3ModalOptions) { if (!modal) { modal = new Web3Modal({ ...options, _sdkVersion: `react-wagmi-${VERSION}` }) @@ -23,6 +42,9 @@ export function createWeb3Modal(options: Web3ModalOptions) { return modal } +export { defaultWagmiConfig } from '../src/utils/defaultWagmiReactConfig.js' + +// -- Hooks ------------------------------------------------------------------- export function useWeb3ModalTheme() { if (!modal) { throw new Error('Please call "createWeb3Modal" before using "useWeb3ModalTheme" hook') @@ -73,5 +95,3 @@ export function useWeb3Modal() { return { open, close } } - -export { defaultWagmiConfig } from '../src/utils/defaultWagmiReactConfig.js' diff --git a/packages/wagmi/exports/vue.ts b/packages/wagmi/exports/vue.ts index f7df1db1cd..12d39de165 100644 --- a/packages/wagmi/exports/vue.ts +++ b/packages/wagmi/exports/vue.ts @@ -1,4 +1,11 @@ -import type { ThemeMode, ThemeVariables } from '@web3modal/scaffold' +import type { + ThemeMode, + ThemeVariables, + W3mAccountButton, + W3mButton, + W3mConnectButton, + W3mNetworkButton +} from '@web3modal/scaffold' import { onUnmounted, ref } from 'vue' import type { Web3ModalOptions } from '../src/client.js' import { Web3Modal } from '../src/client.js' @@ -6,14 +13,25 @@ import { VERSION } from '../src/utils/constants.js' // -- Types ------------------------------------------------------------------- export type { Web3ModalOptions } from '../src/client.js' + type OpenOptions = Parameters[0] + type ThemeModeOptions = Parameters[0] + type ThemeVariablesOptions = Parameters[0] +declare module '@vue/runtime-core' { + export interface ComponentCustomProperties { + W3mConnectButton: Pick + W3mAccountButton: Pick + W3mNetworkButton: Pick + W3mButton: Pick + } +} + // -- Setup ------------------------------------------------------------------- let modal: Web3Modal | undefined = undefined -// -- Lib --------------------------------------------------------------------- export function createWeb3Modal(options: Web3ModalOptions) { if (!modal) { modal = new Web3Modal({ ...options, _sdkVersion: `vue-wagmi-${VERSION}` }) @@ -22,6 +40,9 @@ export function createWeb3Modal(options: Web3ModalOptions) { return modal } +export { defaultWagmiConfig } from '../src/utils/defaultWagmiCoreConfig.js' + +// -- Composites -------------------------------------------------------------- export function useWeb3ModalTheme() { if (!modal) { throw new Error('Please call "createWeb3Modal" before using "useWeb3ModalTheme" hook') @@ -73,5 +94,3 @@ export function useWeb3Modal() { close }) } - -export { defaultWagmiConfig } from '../src/utils/defaultWagmiCoreConfig.js' diff --git a/packages/wagmi/package.json b/packages/wagmi/package.json index 8cb1939112..b2fb66aa2c 100644 --- a/packages/wagmi/package.json +++ b/packages/wagmi/package.json @@ -1,6 +1,6 @@ { "name": "@web3modal/wagmi", - "version": "3.0.0-alpha.5", + "version": "3.0.0-73ed03f2", "type": "module", "main": "./dist/esm/exports/index.js", "types": "./dist/types/exports/index.d.ts", @@ -39,8 +39,8 @@ "lint": "eslint . --ext .js,.jsx,.ts,.tsx" }, "dependencies": { - "@web3modal/polyfills": "3.0.0-alpha.5", - "@web3modal/scaffold": "3.0.0-alpha.5" + "@web3modal/polyfills": "3.0.0-73ed03f2", + "@web3modal/scaffold": "3.0.0-73ed03f2" }, "peerDependencies": { "@wagmi/core": ">=1", diff --git a/turbo.json b/turbo.json index 37751caab5..bb305ca1e0 100644 --- a/turbo.json +++ b/turbo.json @@ -17,6 +17,10 @@ "dependsOn": ["build", "^build:laboratory"], "outputs": ["out/**", ".next/**", "!.next/cache/**"] }, + "build:examples": { + "dependsOn": ["build", "^build:examples"], + "outputs": ["dist/**"] + }, "typecheck": { "dependsOn": ["^typecheck"], "cache": false