diff --git a/README.md b/README.md index 86cb416..a70eccf 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ CKB kit ### Requirement +- Python 3.10 - NodeJS 12.x - yarn 1.x diff --git a/apps/ckit-app/src/containers/WalletContainer/index.tsx b/apps/ckit-app/src/containers/WalletContainer/index.tsx index a39ad8c..2020d56 100644 --- a/apps/ckit-app/src/containers/WalletContainer/index.tsx +++ b/apps/ckit-app/src/containers/WalletContainer/index.tsx @@ -4,6 +4,7 @@ import { autorun, runInAction } from 'mobx'; import { useLocalObservable } from 'mobx-react-lite'; import { useCallback, useEffect, useState } from 'react'; import { createContainer } from 'unstated-next'; +import { useUnipass } from '../../hooks/useUnipass'; import { CkitProviderContainer } from '../CkitProviderContainer'; import { ObservableAcpPwLockWallet, @@ -28,6 +29,7 @@ function useWallet() { const [error, setError] = useState(null); const [visible, setVisible] = useState(false); const [isInitialized, setIsInitialized] = useState(false); + const { host } = useUnipass(); const setModalVisible = useCallback((visible: boolean) => { setVisible(visible); @@ -40,13 +42,13 @@ function useWallet() { runInAction(() => { wallets.splice(0); wallets.push( - new ObservableUnipassWallet(ckitProvider), + new ObservableUnipassWallet(ckitProvider, { host, loginDataCacheKey: '__unipass__' }), new ObservableOmnilockWallet(ckitProvider), new ObservableAcpOmnilockWallet(ckitProvider), ); wallets.find((value) => value.descriptor.name === currentWalletName)?.connect(); }); - }, [ckitProvider]); + }, [ckitProvider, currentWalletName, host]); useEffect( () => @@ -81,21 +83,22 @@ function useWallet() { ); }); }), - [setModalVisible, wallets], + [setCurrentWalletName, setModalVisible, wallets], ); const currentWallet = wallets.find((value) => value.descriptor.name === currentWalletName); useEffect(() => { autorun(() => { + if (!currentWallet || !currentWallet.signer) return; + setSignerAddress(undefined); - const wallet = wallets.find((value) => value.descriptor.name === currentWalletName); - void Promise.resolve(wallet?.signer?.getAddress()).then((address) => { + void Promise.resolve(currentWallet.signer.getAddress()).then((address) => { setSignerAddress(address); setIsInitialized(true); }); }); - }, [currentWalletName]); + }, [currentWallet, currentWalletName, wallets]); return { isInitialized, diff --git a/apps/ckit-app/src/hooks/useUnipass.tsx b/apps/ckit-app/src/hooks/useUnipass.tsx index 1e81901..47dad5d 100644 --- a/apps/ckit-app/src/hooks/useUnipass.tsx +++ b/apps/ckit-app/src/hooks/useUnipass.tsx @@ -8,11 +8,14 @@ interface UnipassContext { cacheTx: (tx: string | null) => void; clearTx: () => void; cachedTx: string | null; + host: string; } export function useUnipass(): UnipassContext { const [cachedTx, cacheTx] = useLocalStorage('unipassTx'); - const adapter = new UnipassWallet.UnipassRedirectAdapter({ host: 'https://unipass.xyz' }); // TODO use the config + // TODO unipass.xyz is deprecated, change it when the new host is ready + const host = 'https://unipass.xyz'; + const adapter = new UnipassWallet.UnipassRedirectAdapter({ host }); // TODO use the config return { shouldLogin: adapter.hasLoginInfo(), cacheLogin: () => adapter.saveLoginInfo(), @@ -20,5 +23,6 @@ export function useUnipass(): UnipassContext { cacheTx, clearTx: () => cacheTx(null), cachedTx, + host, }; } diff --git a/apps/ckit-app/src/wallets/ObservableUnipassWallet.ts b/apps/ckit-app/src/wallets/ObservableUnipassWallet.ts index 9cd4eca..6cae5ce 100644 --- a/apps/ckit-app/src/wallets/ObservableUnipassWallet.ts +++ b/apps/ckit-app/src/wallets/ObservableUnipassWallet.ts @@ -1,9 +1,9 @@ -import { UnipassWallet, CkitProvider } from '@ckitjs/ckit'; +import { UnipassWallet, CkitProvider, UnipassAdapterConfig } from '@ckitjs/ckit'; import { makeObservable, observable } from 'mobx'; export class ObservableUnipassWallet extends UnipassWallet { - constructor(provider: CkitProvider) { - super(provider); + constructor(provider: CkitProvider, adapterConfig?: UnipassAdapterConfig) { + super(provider, adapterConfig); this.setDescriptor({ name: 'UniPass' }); makeObservable(this, { connectStatus: observable, diff --git a/packages/ckit/src/tx-builders/unipass/config.ts b/packages/ckit/src/tx-builders/unipass/config.ts index e57b6a5..097f18f 100644 --- a/packages/ckit/src/tx-builders/unipass/config.ts +++ b/packages/ckit/src/tx-builders/unipass/config.ts @@ -33,7 +33,7 @@ export const nets = [ const AggronCellDeps = [ new CellDep(DepType.code, new OutPoint('0x04a1ac7fe15e454741d3c5c9a409efb9a967714ad2f530870514417978a9f655', '0x0')), - new CellDep(DepType.code, new OutPoint('0x3d41e1c543f0fddcbb17157d15a2845d7c5fb0363561cd8f50ecd0e118b34f84', '0x0')), + new CellDep(DepType.code, new OutPoint('0x65080f85a9c270c1208cc8648f8d73dfb630bab659699f56fb27cff9039c5820', '0x0')), new CellDep(DepType.code, new OutPoint('0xd346695aa3293a84e9f985448668e9692892c959e7e83d6d8042e59c08b8cf5c', '0x0')), ]; diff --git a/packages/ckit/src/wallets/UnipassWallet.ts b/packages/ckit/src/wallets/UnipassWallet.ts index 08ad90c..430ba6c 100644 --- a/packages/ckit/src/wallets/UnipassWallet.ts +++ b/packages/ckit/src/wallets/UnipassWallet.ts @@ -4,6 +4,8 @@ import { CkitProvider } from '../providers'; import { AbstractSingleEntrySigner } from './AbstractSingleEntrySigner'; import { AdapterConfig, UnipassRedirectAdapter } from './unipass/UnipassAdapter'; +export { AdapterConfig as UnipassAdapterConfig } from './unipass/UnipassAdapter'; + export class UnipassWallet extends AbstractWallet { static UnipassRedirectAdapter: typeof UnipassRedirectAdapter = UnipassRedirectAdapter; diff --git a/yarn.lock b/yarn.lock index 17f3501..bef584c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5045,11 +5045,11 @@ buffer@^5.0.5, buffer@^5.5.0, buffer@^5.6.0: ieee754 "^1.1.13" bufferutil@^4.0.1: - version "4.0.3" - resolved "https://registry.yarnpkg.com/bufferutil/-/bufferutil-4.0.3.tgz#66724b756bed23cd7c28c4d306d7994f9943cc6b" - integrity sha512-yEYTwGndELGvfXsImMBLop58eaGW+YdONi1fNjTINSY98tmMmFijBG6WXgdkfuLNt4imzQNtIE+eBp1PVpMCSw== + version "4.0.8" + resolved "https://registry.yarnpkg.com/bufferutil/-/bufferutil-4.0.8.tgz#1de6a71092d65d7766c4d8a522b261a6e787e8ea" + integrity sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw== dependencies: - node-gyp-build "^4.2.0" + node-gyp-build "^4.3.0" builtin-modules@^3.1.0: version "3.2.0" @@ -11326,6 +11326,11 @@ node-gyp-build@^4.2.0: resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.2.3.tgz#ce6277f853835f718829efb47db20f3e4d9c4739" integrity sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg== +node-gyp-build@^4.3.0: + version "4.6.1" + resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.6.1.tgz#24b6d075e5e391b8d5539d98c7fc5c210cac8a3e" + integrity sha512-24vnklJmyRS8ViBNI8KbtK/r/DmXQMRiOMXTNz2nrTnAYUwjmEEbnnpB/+kt+yWRv73bPsSPRFddrcIbAxSiMQ== + node-gyp@^5.0.2: version "5.1.1" resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-5.1.1.tgz#eb915f7b631c937d282e33aed44cb7a025f62a3e" @@ -16175,11 +16180,11 @@ use@^3.1.0: integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ== utf-8-validate@^5.0.2: - version "5.0.5" - resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.5.tgz#dd32c2e82c72002dc9f02eb67ba6761f43456ca1" - integrity sha512-+pnxRYsS/axEpkrrEpzYfNZGXp0IjC/9RIxwM5gntY4Koi8SHmUGSfxfWqxZdRxrtaoVstuOzUp/rbs3JSPELQ== + version "5.0.10" + resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.10.tgz#d7d10ea39318171ca982718b6b96a8d2442571a2" + integrity sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ== dependencies: - node-gyp-build "^4.2.0" + node-gyp-build "^4.3.0" utf8@3.0.0: version "3.0.0"