diff --git a/.github/workflows/publish-wallet-kit.yaml b/.github/workflows/publish-wallet-kit.yaml new file mode 100644 index 00000000..257fc4bb --- /dev/null +++ b/.github/workflows/publish-wallet-kit.yaml @@ -0,0 +1,34 @@ +name: Publish NPM package + +on: + push: + tags: + - '*' + +permissions: + contents: read + packages: write + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + matrix: + package: [ wallet-kit,react-wallet-kit,wallet-connect,vanilla-wallet-kit ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + registry-url: https://npm.pkg.github.com/ + - run: yarn install:all + - run: yarn build + - run: | + cd packages/${{ matrix.package }} + yarn version --no-git-tag-version --new-version ${{ github.ref_name }} + yarn publish + env: + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/apps/sample-react-app/package.json b/apps/sample-react-app/package.json index 9e5cb767..7615fe61 100644 --- a/apps/sample-react-app/package.json +++ b/apps/sample-react-app/package.json @@ -43,11 +43,11 @@ "@vechain/hardhat-vechain": "^0.1.4", "@vechain/hardhat-web3": "^0.1.4", "@vechain/picasso": "^2.1.1", - "@vechain/react-wallet-kit": "*", - "@vechain/vanilla-wallet-kit": "*", - "@vechain/wallet-connect": "*", - "@vechain/wallet-kit": "*", "@vechain/web3-providers-connex": "^1.1.2", + "@vechainfoundation/react-wallet-kit": "*", + "@vechainfoundation/vanilla-wallet-kit": "*", + "@vechainfoundation/wallet-connect": "*", + "@vechainfoundation/wallet-kit": "*", "buffer": "^6.0.3", "crypto-browserify": "^3.12.0", "framer-motion": "3.10.6", diff --git a/apps/sample-react-app/src/App.tsx b/apps/sample-react-app/src/App.tsx index bee5c233..e001d0c9 100644 --- a/apps/sample-react-app/src/App.tsx +++ b/apps/sample-react-app/src/App.tsx @@ -1,8 +1,8 @@ import type { JSX } from 'react'; import React from 'react'; import type { Options } from '@vechain/connex'; -import type { WalletConnectOptions } from '@vechain/wallet-connect'; -import { ConnexProvider } from '@vechain/react-wallet-kit'; +import type { WalletConnectOptions } from '@vechainfoundation/wallet-connect'; +import { ConnexProvider } from '@vechainfoundation/react-wallet-kit'; import { ChakraProvider } from '@chakra-ui/react'; import { NavBar, StyledContainer } from './Components/layout'; import { Homepage } from './Screens/Homepage'; diff --git a/apps/sample-react-app/src/Components/AccountDetailBody.tsx b/apps/sample-react-app/src/Components/AccountDetailBody.tsx index b97b5708..bd761de8 100644 --- a/apps/sample-react-app/src/Components/AccountDetailBody.tsx +++ b/apps/sample-react-app/src/Components/AccountDetailBody.tsx @@ -1,6 +1,6 @@ import { Button, HStack, Image, Text, VStack } from '@chakra-ui/react'; import React, { useMemo } from 'react'; -import type { WalletSource } from '@vechain/wallet-kit'; +import type { WalletSource } from '@vechainfoundation/wallet-kit'; import { WalletSources } from '../Constants'; import { AddressButton } from './AddressButton'; diff --git a/apps/sample-react-app/src/Components/AccountDetailModal.tsx b/apps/sample-react-app/src/Components/AccountDetailModal.tsx index 91a7bc27..1055c61e 100644 --- a/apps/sample-react-app/src/Components/AccountDetailModal.tsx +++ b/apps/sample-react-app/src/Components/AccountDetailModal.tsx @@ -1,6 +1,6 @@ import { HStack, Text } from '@chakra-ui/react'; -import type { WalletSource } from '@vechain/wallet-kit'; -import { useWallet } from '@vechain/react-wallet-kit'; +import type { WalletSource } from '@vechainfoundation/wallet-kit'; +import { useWallet } from '@vechainfoundation/react-wallet-kit'; import React, { useCallback } from 'react'; import { getPicassoImgSrc } from '../Utils/AccountUtils'; import { Dialog } from './shared'; diff --git a/apps/sample-react-app/src/Components/SwitchWalletButton.tsx b/apps/sample-react-app/src/Components/SwitchWalletButton.tsx index ea0a034f..39bd163e 100644 --- a/apps/sample-react-app/src/Components/SwitchWalletButton.tsx +++ b/apps/sample-react-app/src/Components/SwitchWalletButton.tsx @@ -1,7 +1,10 @@ import type { HTMLChakraProps } from '@chakra-ui/react'; import { useDisclosure } from '@chakra-ui/react'; import React from 'react'; -import { ConnectWalletButton, useWallet } from '@vechain/react-wallet-kit'; +import { + ConnectWalletButton, + useWallet, +} from '@vechainfoundation/react-wallet-kit'; import { AccountDetailModal } from './AccountDetailModal'; import { AddressButton } from './AddressButton'; diff --git a/apps/sample-react-app/src/Components/layout/NavBar.tsx b/apps/sample-react-app/src/Components/layout/NavBar.tsx index 432bf320..ef178b5d 100644 --- a/apps/sample-react-app/src/Components/layout/NavBar.tsx +++ b/apps/sample-react-app/src/Components/layout/NavBar.tsx @@ -17,7 +17,7 @@ import { import type { JSX } from 'react'; import React from 'react'; import { Bars3Icon } from '@heroicons/react/24/solid'; -import { useWallet } from '@vechain/react-wallet-kit'; +import { useWallet } from '@vechainfoundation/react-wallet-kit'; import { AccountDetailBody } from '../AccountDetailBody'; import { SwitchWalletButton } from '../SwitchWalletButton'; diff --git a/apps/sample-react-app/src/Constants/Constants.ts b/apps/sample-react-app/src/Constants/Constants.ts index 601e2a47..ec293611 100644 --- a/apps/sample-react-app/src/Constants/Constants.ts +++ b/apps/sample-react-app/src/Constants/Constants.ts @@ -1,4 +1,4 @@ -import type { WalletSource } from '@vechain/wallet-kit'; +import type { WalletSource } from '@vechainfoundation/wallet-kit'; export const NODE_URL = 'https://testnet.vechain.org/'; export const NODE_NETWORK = 'test'; diff --git a/apps/sample-react-app/src/Hooks/useCounter.ts b/apps/sample-react-app/src/Hooks/useCounter.ts index f4f8708b..6a9cec50 100644 --- a/apps/sample-react-app/src/Hooks/useCounter.ts +++ b/apps/sample-react-app/src/Hooks/useCounter.ts @@ -1,5 +1,5 @@ import { useCallback, useEffect, useMemo, useState } from 'react'; -import { useConnex } from '@vechain/react-wallet-kit'; +import { useConnex } from '@vechainfoundation/react-wallet-kit'; import type { abi } from 'thor-devkit'; const _counter: abi.Function.Definition = { diff --git a/apps/sample-react-app/src/Logos/Logo.tsx b/apps/sample-react-app/src/Logos/Logo.tsx index 9304e678..16ff5eb5 100644 --- a/apps/sample-react-app/src/Logos/Logo.tsx +++ b/apps/sample-react-app/src/Logos/Logo.tsx @@ -1,7 +1,7 @@ import type { HTMLChakraProps } from '@chakra-ui/react'; import { Image } from '@chakra-ui/react'; import React from 'react'; -import { VeWorldLogo as VWLogo } from '@vechain/vanilla-wallet-kit'; +import { VeWorldLogo as VWLogo } from '@vechainfoundation/vanilla-wallet-kit'; type IIMage = HTMLChakraProps<'img'>; diff --git a/apps/sample-react-app/src/Screens/components/Counter.tsx b/apps/sample-react-app/src/Screens/components/Counter.tsx index adc696fd..0d40fdf3 100644 --- a/apps/sample-react-app/src/Screens/components/Counter.tsx +++ b/apps/sample-react-app/src/Screens/components/Counter.tsx @@ -12,7 +12,7 @@ import { import type { JSX } from 'react'; import React, { useCallback, useMemo } from 'react'; import { ArrowUpIcon } from '@heroicons/react/24/solid'; -import { useWallet } from '@vechain/react-wallet-kit'; +import { useWallet } from '@vechainfoundation/react-wallet-kit'; import { StyledCard } from '../../Components/shared'; import { useCounter } from '../../Hooks/useCounter'; import { AddressButton } from '../../Components'; diff --git a/apps/sample-vanilla-app/index.js b/apps/sample-vanilla-app/index.js index f7071248..903e15db 100644 --- a/apps/sample-vanilla-app/index.js +++ b/apps/sample-vanilla-app/index.js @@ -1,6 +1,6 @@ // eslint-disable-next-line eslint-comments/disable-enable-pair /* eslint-disable no-undef */ -import { configureThorModal } from '@vechain/vanilla-wallet-kit'; +import { configureThorModal } from '@vechainfoundation/vanilla-wallet-kit'; const walletConnectOptions = { projectId: 'a0b855ceaf109dbc8426479a4c3d38d8', diff --git a/apps/sample-vanilla-app/package.json b/apps/sample-vanilla-app/package.json index 450c30aa..cec15176 100644 --- a/apps/sample-vanilla-app/package.json +++ b/apps/sample-vanilla-app/package.json @@ -8,12 +8,12 @@ "scripts": { "build": "parcel build index.html --public-url /vechain-dapp-kit/vanilla", "clean": "rm -rf dist", - "dev": "parcel index.html --open", + "dev": "parcel index.html --open --port 3001", "purge": "yarn clean && rm -rf node_modules", "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "@vechain/vanilla-wallet-kit": "*" + "@vechainfoundation/vanilla-wallet-kit": "*" }, "devDependencies": { "parcel": "^2.10.2" diff --git a/apps/sample-vue-app/package.json b/apps/sample-vue-app/package.json index a08417c0..cf47339b 100644 --- a/apps/sample-vue-app/package.json +++ b/apps/sample-vue-app/package.json @@ -31,8 +31,8 @@ "root": true }, "dependencies": { - "@vechain/vanilla-wallet-kit": "*", - "@vechain/wallet-kit": "*", + "@vechainfoundation/vanilla-wallet-kit": "*", + "@vechainfoundation/wallet-kit": "*", "core-js": "^3.8.3", "node-polyfill-webpack-plugin": "^2.0.1", "vue": "^3.2.13", diff --git a/apps/sample-vue-app/src/connex/ConnexProvider.vue b/apps/sample-vue-app/src/connex/ConnexProvider.vue index 08590563..e5cae1fc 100644 --- a/apps/sample-vue-app/src/connex/ConnexProvider.vue +++ b/apps/sample-vue-app/src/connex/ConnexProvider.vue @@ -4,7 +4,7 @@ import { ConnectResponse, MultiWalletConnex, WalletSource, -} from '@vechain/wallet-kit'; +} from '@vechainfoundation/wallet-kit'; import type Connex from '@vechain/connex'; import { ConnexSymbol, @@ -12,8 +12,8 @@ import { WalletStateSymbol, } from '@/connex/keys'; import { WalletActions, WalletState } from '@/connex/types'; -import { WalletConnectOptions } from '@vechain/wallet-connect'; -import { configureThorModal } from '@vechain/vanilla-wallet-kit'; +import { WalletConnectOptions } from '@vechainfoundation/wallet-connect'; +import { configureThorModal } from '@vechainfoundation/vanilla-wallet-kit'; const initWallets = (hasWcOptions: boolean) => { const wallets: WalletSource[] = ['sync2']; diff --git a/apps/sample-vue-app/src/connex/types.d.ts b/apps/sample-vue-app/src/connex/types.d.ts index bfad5e71..f25581dd 100644 --- a/apps/sample-vue-app/src/connex/types.d.ts +++ b/apps/sample-vue-app/src/connex/types.d.ts @@ -1,4 +1,4 @@ -import { ConnectResponse, WalletSource } from '@vechain/wallet-kit'; +import { ConnectResponse, WalletSource } from '@vechainfoundation/wallet-kit'; type WalletState = { availableWallets: WalletSource[]; diff --git a/apps/sample-vue-app/src/main.ts b/apps/sample-vue-app/src/main.ts index a9434a40..1c2a07e5 100644 --- a/apps/sample-vue-app/src/main.ts +++ b/apps/sample-vue-app/src/main.ts @@ -1,5 +1,5 @@ import { createApp } from 'vue'; import App from './App.vue'; -import '@vechain/vanilla-wallet-kit'; +import '@vechainfoundation/vanilla-wallet-kit'; createApp(App).mount('#app'); diff --git a/package.json b/package.json index db9e140d..4831797f 100755 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ ], "scripts": { "build": "turbo run build", - "build-react-kit": "turbo run build --filter='@vechain/react-wallet-kit'", - "build:deps": "turbo build --no-daemon --filter='@vechain/*'", + "build-react-kit": "turbo run build --filter='@vechainfoundation/react-wallet-kit'", + "build:deps": "turbo build --no-daemon --filter='@vechainfoundation/*'", "clean": "rm -rf .turbo .parcel-cache build && npx turbo@latest run clean", "cucumber": "yarn && cucumber-js", "dev": "turbo run dev --no-daemon", diff --git a/packages/react-wallet-kit/README.md b/packages/react-wallet-kit/README.md index 282d241a..b878b1dd 100644 --- a/packages/react-wallet-kit/README.md +++ b/packages/react-wallet-kit/README.md @@ -1 +1,92 @@ -# React Vendor +# `@vechainfoundation/react-wallet-kit` + +## Why ? + +- Allow easy interaction with all wallets. +- Connex is designed to play nice with one wallet at a time, this library provides a layer on top of Connex to easily + allow interaction with all wallets. +- Easy setup for wallet connect. +- Create your own + +## Installation + +- See the parent [README](../../README.md) for installation instructions. + +### Build + +```bash +yarn build +``` + +## Usage + +```bash +yarn add @vechainfoundation/react-wallet-kit +``` + +- Create the node options + +```typescript +import type { Options } from '@vechain/connex'; + +const nodeOptions: Omit = { + node: 'https://testnet.vechain.org/', + network: 'test', +}; +``` + +- Optional: Configure wallet connect options + +```typescript +import type { WalletConnectOptions } from '@vechainfoundation/wallet-connect'; + +const walletConnectOptions: WalletConnectOptions = { + projectId: '', // Create your project here: https://cloud.walletconnect.com/sign-up + metadata: { + name: 'My dApp', + description: 'My dApp description', + url: window.location.origin, // Your app URL + icons: [`${window.location.origin}/images/my-dapp-icon.png`], // Your app Icon + }, +}; +``` + +- Initialise the `ConnexVendor` + +```typescript jsx +import { ConnexProvider } from '@vechainfoundation/react-wallet-kit'; + +export const App = (): JSX.Element => { + return ( + <> + + + + + ); +}; +``` + +- Use the hooks provided by the `ConnexProvider` + +```typescript jsx +import { useWallet, useConnex } from '@vechainfoundation/react-wallet-kit'; +import type { WalletSource } from '@vechainfoundation/wallet-kit'; + +// type WalletSource = 'wallet-connect' | 'veworld-extension' | 'sync2' | 'sync'; +const mySource: WalletSource = 'veworld-extension'; + +const { connect, setSource } = useWallet(); + +setSource(mySource); + +const { account } = await connect(); + +//Start using Connex thor/ vendor +const { vendor, thor } = useConnex(); +``` diff --git a/packages/react-wallet-kit/package.json b/packages/react-wallet-kit/package.json index 1dd51c87..29695986 100644 --- a/packages/react-wallet-kit/package.json +++ b/packages/react-wallet-kit/package.json @@ -1,7 +1,7 @@ { - "name": "@vechain/react-wallet-kit", + "name": "@vechainfoundation/react-wallet-kit", "version": "0.0.0", - "private": true, + "private": false, "license": "MIT", "sideEffects": false, "main": "./dist/index.js", @@ -19,9 +19,9 @@ "@vechain/connex": "2.1.0", "@vechain/connex-framework": "2.1.0", "@vechain/picasso": "^2.1.1", - "@vechain/vanilla-wallet-kit": "*", - "@vechain/wallet-connect": "*", - "@vechain/wallet-kit": "*", + "@vechainfoundation/vanilla-wallet-kit": "*", + "@vechainfoundation/wallet-connect": "*", + "@vechainfoundation/wallet-kit": "*", "react-icons": "^4.11.0", "styled-components": "^6.1.0", "thor-devkit": "^2.0.9" diff --git a/packages/react-wallet-kit/src/ConnectWalletButton/Components/ConnectButtonWithModal.tsx b/packages/react-wallet-kit/src/ConnectWalletButton/Components/ConnectButtonWithModal.tsx index c16447d3..be192aec 100644 --- a/packages/react-wallet-kit/src/ConnectWalletButton/Components/ConnectButtonWithModal.tsx +++ b/packages/react-wallet-kit/src/ConnectWalletButton/Components/ConnectButtonWithModal.tsx @@ -1,14 +1,14 @@ -import 'react'; -import { ConnectModalWithButtonWrapped } from './Wrapped/ConnectModalWithButtonWrapped'; import { useCallback, useContext, useState } from 'react'; +import type { WalletSource } from '@vechainfoundation/wallet-kit'; +import type { SourceInfo } from '@vechainfoundation/vanilla-wallet-kit'; import { ThemeContext } from '../../provider/ThemeProvider'; -import { WalletSource } from '@vechain/wallet-kit'; import { useWallet } from '../../ConnexProvider'; -import { SourceInfo } from '@vechain/vanilla-wallet-kit'; +import { ConnectModalWithButtonWrapped } from './Wrapped/ConnectModalWithButtonWrapped'; interface ConnectButtonWithModalProps { onClose?: () => void; } + export const ConnectButtonWithModal = ({ onClose, }: ConnectButtonWithModalProps) => { diff --git a/packages/react-wallet-kit/src/ConnectWalletButton/Components/Wrapped/ConnectModalWithButtonWrapped.tsx b/packages/react-wallet-kit/src/ConnectWalletButton/Components/Wrapped/ConnectModalWithButtonWrapped.tsx index ffb475b2..7cb6d2cb 100644 --- a/packages/react-wallet-kit/src/ConnectWalletButton/Components/Wrapped/ConnectModalWithButtonWrapped.tsx +++ b/packages/react-wallet-kit/src/ConnectWalletButton/Components/Wrapped/ConnectModalWithButtonWrapped.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { createComponent } from '@lit/react'; -import { ConnectButtonWithModal } from '@vechain/vanilla-wallet-kit'; +import { ConnectButtonWithModal } from '@vechainfoundation/vanilla-wallet-kit'; export const ConnectModalWithButtonWrapped = createComponent({ tagName: 'vwk-connect-button-with-modal', diff --git a/packages/react-wallet-kit/src/ConnectWalletButton/Constants/Constants.ts b/packages/react-wallet-kit/src/ConnectWalletButton/Constants/Constants.ts index b6410adb..2e6b462b 100644 --- a/packages/react-wallet-kit/src/ConnectWalletButton/Constants/Constants.ts +++ b/packages/react-wallet-kit/src/ConnectWalletButton/Constants/Constants.ts @@ -1,10 +1,10 @@ -import type { WalletSource } from '@vechain/wallet-kit'; +import type { WalletSource } from '@vechainfoundation/wallet-kit'; import { Sync2Logo, SyncLogo, VeWorldLogo, WalletConnectLogo, -} from '@vechain/vanilla-wallet-kit'; +} from '@vechainfoundation/vanilla-wallet-kit'; interface SourceInfo { name: string; diff --git a/packages/react-wallet-kit/src/ConnexProvider.tsx b/packages/react-wallet-kit/src/ConnexProvider.tsx index 03b6edcd..d700b26b 100644 --- a/packages/react-wallet-kit/src/ConnexProvider.tsx +++ b/packages/react-wallet-kit/src/ConnexProvider.tsx @@ -6,11 +6,11 @@ import React, { useMemo, useState, } from 'react'; -import type { WalletSource } from '@vechain/wallet-kit'; -import { MultiWalletConnex } from '@vechain/wallet-kit'; +import type { WalletSource } from '@vechainfoundation/wallet-kit'; +import { MultiWalletConnex } from '@vechainfoundation/wallet-kit'; import type { ConnexContext, ConnexProviderOptions } from './types'; -const STORAGE_PREFIX = '@vechain/wallet-kit'; +const STORAGE_PREFIX = '@vechainfoundation/wallet-kit'; const persist = (key: 'source' | 'account', value: string): void => { localStorage.setItem(`${STORAGE_PREFIX}${key}`, value); }; diff --git a/packages/react-wallet-kit/src/types.ts b/packages/react-wallet-kit/src/types.ts index 4fe591b3..319cf6ec 100644 --- a/packages/react-wallet-kit/src/types.ts +++ b/packages/react-wallet-kit/src/types.ts @@ -1,7 +1,10 @@ import type { Options } from '@vechain/connex'; import type React from 'react'; -import type { WalletConnectOptions } from '@vechain/wallet-connect'; -import type { ConnectResponse, WalletSource } from '@vechain/wallet-kit'; +import type { WalletConnectOptions } from '@vechainfoundation/wallet-connect'; +import type { + ConnectResponse, + WalletSource, +} from '@vechainfoundation/wallet-kit'; export interface AccountState { address: string | null; diff --git a/packages/vanilla-wallet-kit/package.json b/packages/vanilla-wallet-kit/package.json index 3f1e7fa2..6d872dd6 100644 --- a/packages/vanilla-wallet-kit/package.json +++ b/packages/vanilla-wallet-kit/package.json @@ -1,7 +1,7 @@ { - "name": "@vechain/vanilla-wallet-kit", - "version": "2.0.0", - "private": true, + "name": "@vechainfoundation/vanilla-wallet-kit", + "version": "0.0.0", + "private": false, "description": "Vanilla js wallet kit", "keywords": [ "web-components", @@ -17,14 +17,14 @@ "scripts": { "build": "tsup", "clean": "rm -rf dist .turbo", - "dev": "parcel index.html --open", + "dev": "parcel index.html --open --port 1234", "format": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.eslintignore --write", "lint": "eslint 'src/**/*.ts'", "purge": "yarn clean && rm -rf node_modules", "watch": "tsup --watch" }, "dependencies": { - "@vechain/wallet-kit": "*", + "@vechainfoundation/wallet-kit": "*", "@wagmi/core": "^1.4.5", "@web3modal/ethereum": "^2.7.1", "@web3modal/html": "^2.7.1", diff --git a/packages/vanilla-wallet-kit/src/client.ts b/packages/vanilla-wallet-kit/src/client.ts index a3deaa94..1dd14090 100644 --- a/packages/vanilla-wallet-kit/src/client.ts +++ b/packages/vanilla-wallet-kit/src/client.ts @@ -1,6 +1,6 @@ -import type { WalletSource } from '@vechain/wallet-kit'; -import { MultiWalletConnex } from '@vechain/wallet-kit'; -import type { ConnexOptions } from '@vechain/wallet-kit/src'; +import type { WalletSource } from '@vechainfoundation/wallet-kit'; +import { MultiWalletConnex } from '@vechainfoundation/wallet-kit'; +import type { ConnexOptions } from '@vechainfoundation/wallet-kit/src'; import type { SourceInfo } from './constants'; import './components'; diff --git a/packages/vanilla-wallet-kit/src/components/base/vwk-base-modal/index.ts b/packages/vanilla-wallet-kit/src/components/base/vwk-base-modal/index.ts index 72712b62..f5916c95 100644 --- a/packages/vanilla-wallet-kit/src/components/base/vwk-base-modal/index.ts +++ b/packages/vanilla-wallet-kit/src/components/base/vwk-base-modal/index.ts @@ -1,7 +1,7 @@ import type { TemplateResult } from 'lit'; import { css, html, LitElement } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import { Theme, ThemeMode } from '@vechain/wallet-kit'; +import { Theme, ThemeMode } from '@vechainfoundation/wallet-kit'; import { Colors } from '../../../constants'; @customElement('vwk-base-modal') diff --git a/packages/vanilla-wallet-kit/src/components/vwk-connect-button-with-modal/index.ts b/packages/vanilla-wallet-kit/src/components/vwk-connect-button-with-modal/index.ts index 1fb18a87..54a7cc3a 100644 --- a/packages/vanilla-wallet-kit/src/components/vwk-connect-button-with-modal/index.ts +++ b/packages/vanilla-wallet-kit/src/components/vwk-connect-button-with-modal/index.ts @@ -1,7 +1,7 @@ import type { TemplateResult } from 'lit'; import { html, LitElement } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import { Theme, ThemeMode } from '@vechain/wallet-kit'; +import { Theme, ThemeMode } from '@vechainfoundation/wallet-kit'; import { SourceInfo } from '../../constants'; @customElement('vwk-connect-button-with-modal') diff --git a/packages/vanilla-wallet-kit/src/components/vwk-connect-button/index.ts b/packages/vanilla-wallet-kit/src/components/vwk-connect-button/index.ts index 7a4bea13..4173035e 100644 --- a/packages/vanilla-wallet-kit/src/components/vwk-connect-button/index.ts +++ b/packages/vanilla-wallet-kit/src/components/vwk-connect-button/index.ts @@ -1,7 +1,7 @@ import type { TemplateResult } from 'lit'; import { css, html, LitElement } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import { Theme, ThemeMode } from '@vechain/wallet-kit'; +import { Theme, ThemeMode } from '@vechainfoundation/wallet-kit'; import { Colors } from '../../constants'; @customElement('vwk-connect-button') diff --git a/packages/vanilla-wallet-kit/src/components/vwk-connect-modal/index.ts b/packages/vanilla-wallet-kit/src/components/vwk-connect-modal/index.ts index 8a5b5c3a..c68ba001 100644 --- a/packages/vanilla-wallet-kit/src/components/vwk-connect-modal/index.ts +++ b/packages/vanilla-wallet-kit/src/components/vwk-connect-modal/index.ts @@ -1,7 +1,7 @@ import type { TemplateResult } from 'lit'; import { css, html, LitElement, nothing } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import { Theme, ThemeMode } from '@vechain/wallet-kit'; +import { Theme, ThemeMode } from '@vechainfoundation/wallet-kit'; import { DarkCloseSvg, LightCloseSvg } from '../../assets'; import type { SourceInfo } from '../../constants'; import { WalletSources } from '../../constants'; diff --git a/packages/vanilla-wallet-kit/src/components/vwk-source-card/index.ts b/packages/vanilla-wallet-kit/src/components/vwk-source-card/index.ts index a5cf923b..4b962c7b 100644 --- a/packages/vanilla-wallet-kit/src/components/vwk-source-card/index.ts +++ b/packages/vanilla-wallet-kit/src/components/vwk-source-card/index.ts @@ -1,7 +1,7 @@ import type { TemplateResult } from 'lit'; import { css, html, LitElement } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import { Theme, ThemeMode } from '@vechain/wallet-kit'; +import { Theme, ThemeMode } from '@vechainfoundation/wallet-kit'; import type { SourceInfo } from '../../constants'; import { Colors } from '../../constants'; diff --git a/packages/wallet-connect/package.json b/packages/wallet-connect/package.json index 51476ed1..91a44dcb 100644 --- a/packages/wallet-connect/package.json +++ b/packages/wallet-connect/package.json @@ -1,7 +1,7 @@ { - "name": "@vechain/wallet-connect", + "name": "@vechainfoundation/wallet-connect", "version": "0.0.0", - "private": true, + "private": false, "license": "MIT", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/packages/wallet-connect/src/index.ts b/packages/wallet-connect/src/index.ts index 7f010b93..5a8e5ff0 100644 --- a/packages/wallet-connect/src/index.ts +++ b/packages/wallet-connect/src/index.ts @@ -8,6 +8,7 @@ export type { WalletConnectOptions, ResolvedSignClient, WCClient, + WCModal, } from './types'; export { newWcSigner, newWeb3Modal, newWcClient }; diff --git a/packages/wallet-connect/src/signer.ts b/packages/wallet-connect/src/signer.ts index f1c4df77..9a8ea997 100644 --- a/packages/wallet-connect/src/signer.ts +++ b/packages/wallet-connect/src/signer.ts @@ -152,11 +152,11 @@ export const newWcSigner = ({ }); if (uri) { - await web3Modal.openModal({ uri, chains: namespace.chains }); + await web3Modal.openModal({ uri }); } return await new Promise((resolve, reject) => { - web3Modal.subscribeModal((ev: { open: boolean }) => { + web3Modal.subscribeModal((ev) => { if (!ev.open) { reject(new Error('User closed modal')); } diff --git a/packages/wallet-connect/src/types.d.ts b/packages/wallet-connect/src/types.d.ts index c0cb58a4..18bd1218 100644 --- a/packages/wallet-connect/src/types.d.ts +++ b/packages/wallet-connect/src/types.d.ts @@ -1,4 +1,3 @@ -import type { WalletConnectModal } from '@walletconnect/modal'; import type { SignClientTypes } from '@walletconnect/types'; import type { SignClient } from '@walletconnect/sign-client'; @@ -44,6 +43,22 @@ export interface WalletConnectOptions { metadata: SignClientTypes.Options['metadata']; } +interface SubscribeModalState { + open: boolean; +} + +interface OpenOptions { + uri: string; +} + +export interface WCModal { + openModal: (options: OpenOptions) => Promise; + closeModal: () => void; + subscribeModal: ( + callback: (newState: SubscribeModalState) => void, + ) => () => void; +} + /** * Options for the {@link WCSigner} * @param wcClient - A function to get the initialized WalletConnect SignClient @@ -53,7 +68,7 @@ export interface WalletConnectOptions { */ export interface WCSignerOptions { wcClient: WCClient; - web3Modal: WalletConnectModal; + web3Modal: WCModal; onDisconnected?: () => void; genesisId: string; } diff --git a/packages/wallet-connect/src/web3-modal.ts b/packages/wallet-connect/src/web3-modal.ts index 4f9072f9..e364d5e7 100644 --- a/packages/wallet-connect/src/web3-modal.ts +++ b/packages/wallet-connect/src/web3-modal.ts @@ -1,12 +1,22 @@ import { WalletConnectModal } from '@walletconnect/modal'; +import type { WCModal } from './types'; const _cachedModals: Record = {}; +const genesisIds = [ + '0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a', + '0x000000000b2bce3c70bc649a02749e8687721b09ed2e15997f466536b20bb127', +]; + +const chains = genesisIds.map((id) => { + return id.slice(-32); +}); + /** * Creates a new WalletConnectModal instance * @param projectId - Your WalletConnect project ID */ -export const newWeb3Modal = (projectId: string): WalletConnectModal => { +export const newWeb3Modal = (projectId: string): WCModal => { const cached = _cachedModals[projectId]; if (cached) { @@ -26,6 +36,7 @@ export const newWeb3Modal = (projectId: string): WalletConnectModal => { }, }, ], + chains, themeVariables: { '--wcm-z-index': '99999999', }, diff --git a/packages/wallet-kit/README.md b/packages/wallet-kit/README.md index 6571e2db..6a532c67 100644 --- a/packages/wallet-kit/README.md +++ b/packages/wallet-kit/README.md @@ -1,4 +1,4 @@ -# `@vecahin/dapp-kit` +# `@vechainfoundation/wallet-kit` ## Why ? @@ -21,21 +21,13 @@ yarn build ## Usage ```bash -yarn add @vechain/dapp-kit -``` - -- Create a function to handle remote wallet disconnections. Some wallets can disconnect remotely (eg. Wallet Connect) - -```typescript -const onDisconnected = () => { - //TODO: handle disconnect -}; +yarn add @vechainfoundation/wallet-kit ``` - Optional: Configure wallet connect options ```typescript -import type { WalletConnectOptions } from '@vechain/wallet-connect'; +import type { WalletConnectOptions } from '@vechainfoundation/wallet-connect'; const walletConnectOptions: WalletConnectOptions = { projectId: '', // Create your project here: https://cloud.walletconnect.com/sign-up @@ -56,8 +48,7 @@ const walletConnectOptions: WalletConnectOptions = { const { thor, vendor, wallet } = new MultiWalletConnex({ nodeUrl: 'https://sync-testnet.vechain.org/', //Required genesis: 'main', //Optional - "main" | "test" | Connex.Thor.Block - walletConnectOptions, - onDisconnected, + walletConnectOptions, //Optional }); ``` @@ -65,6 +56,11 @@ const { thor, vendor, wallet } = new MultiWalletConnex({ - Connex is ready to use as normal ```typescript +import type { WalletSource } from '@vechainfoundation/wallet-kit'; + +// type WalletSource = 'wallet-connect' | 'veworld-extension' | 'sync2' | 'sync'; +const mySource: WalletSource = 'veworld-extension'; + wallet.setSource('veworld-extension'); ``` @@ -73,10 +69,8 @@ wallet.setSource('veworld-extension'); verified, you should request a subsequent certificate sign in ```typescript -const { account, verified } = await wallet.connect(); -``` +const {account, verified} = await wallet.connect(); -```typescript -const tx = await thor.account("0x...123").method(...).transact().request(); +const tx = await thor.account("0x...123").method(...).transact().signer(account).request(); const certRes = await vendor.sign("cert", {...}).requset(); ``` diff --git a/packages/wallet-kit/package.json b/packages/wallet-kit/package.json index 2d8e3677..a1ee622d 100644 --- a/packages/wallet-kit/package.json +++ b/packages/wallet-kit/package.json @@ -1,7 +1,7 @@ { - "name": "@vechain/wallet-kit", + "name": "@vechainfoundation/wallet-kit", "version": "0.0.0", - "private": true, + "private": false, "main": "./dist/index.js", "types": "./dist/index.d.ts", "scripts": { @@ -15,7 +15,7 @@ "@vechain/connex": "2.1.0", "@vechain/connex-driver": "2.1.0", "@vechain/connex-framework": "2.1.0", - "@vechain/wallet-connect": "*", + "@vechainfoundation/wallet-connect": "*", "events": "^3.3.0", "thor-devkit": "^2.0.9" }, diff --git a/packages/wallet-kit/src/create-wallet.ts b/packages/wallet-kit/src/create-wallet.ts index 7d1901d5..a7f9db32 100644 --- a/packages/wallet-kit/src/create-wallet.ts +++ b/packages/wallet-kit/src/create-wallet.ts @@ -2,7 +2,7 @@ import { newWcClient, newWcSigner, newWeb3Modal, -} from '@vechain/wallet-connect/dist'; +} from '@vechainfoundation/wallet-connect/dist'; import { createSync, createSync2 } from '@vechain/connex/esm/signer'; import type { ConnexOptions, ConnexWallet, WalletSource } from './types'; import { CertificateBasedWallet } from './wallets/certificate-wallet'; @@ -19,6 +19,7 @@ export const createWallet = ({ genesis, walletConnectOptions, onDisconnected, + customWcModal, }: ICreateWallet): ConnexWallet => { const genesisId = normalizeGenesisId(genesis); @@ -58,7 +59,9 @@ export const createWallet = ({ metadata, }); - const web3Modal = newWeb3Modal(projectId); + const web3Modal = customWcModal + ? customWcModal + : newWeb3Modal(projectId); const wallet = newWcSigner({ genesisId, diff --git a/packages/wallet-kit/src/types.d.ts b/packages/wallet-kit/src/types.d.ts index a4a1c20b..062bf304 100644 --- a/packages/wallet-kit/src/types.d.ts +++ b/packages/wallet-kit/src/types.d.ts @@ -1,5 +1,6 @@ import type { Connex1 } from '@vechain/connex/esm/signer'; -import type { WalletConnectOptions } from '@vechain/wallet-connect'; +import type { WalletConnectOptions } from '@vechainfoundation/wallet-connect'; +import type { WCModal } from '@vechainfoundation/wallet-connect/src'; declare global { interface Window { @@ -29,6 +30,7 @@ interface ConnexOptions { nodeUrl: string; genesis?: Genesis; walletConnectOptions?: WalletConnectOptions; + customWcModal?: WCModal; } type BaseWallet = Connex.Signer & { diff --git a/packages/wallet-kit/src/wallets/wc-wallet.ts b/packages/wallet-kit/src/wallets/wc-wallet.ts index 9e4f728a..0524eee0 100644 --- a/packages/wallet-kit/src/wallets/wc-wallet.ts +++ b/packages/wallet-kit/src/wallets/wc-wallet.ts @@ -1,4 +1,4 @@ -import type { WCSigner } from '@vechain/wallet-connect'; +import type { WCSigner } from '@vechainfoundation/wallet-connect'; import type { ConnectResponse, ConnexWallet } from '../types'; class WCWallet implements ConnexWallet {