Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make the unipass host become configurable #114

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKB kit

### Requirement

- Python 3.10
- NodeJS 12.x
- yarn 1.x

Expand Down
15 changes: 9 additions & 6 deletions apps/ckit-app/src/containers/WalletContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,6 +29,7 @@ function useWallet() {
const [error, setError] = useState<WalletConnectError | null>(null);
const [visible, setVisible] = useState(false);
const [isInitialized, setIsInitialized] = useState(false);
const { host } = useUnipass();

const setModalVisible = useCallback((visible: boolean) => {
setVisible(visible);
Expand All @@ -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(
() =>
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion apps/ckit-app/src/hooks/useUnipass.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ interface UnipassContext {
cacheTx: (tx: string | null) => void;
clearTx: () => void;
cachedTx: string | null;
host: string;
}

export function useUnipass(): UnipassContext {
const [cachedTx, cacheTx] = useLocalStorage<string | null>('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(),
shouldSendTx: adapter.hasSigData(),
cacheTx,
clearTx: () => cacheTx(null),
cachedTx,
host,
};
}
6 changes: 3 additions & 3 deletions apps/ckit-app/src/wallets/ObservableUnipassWallet.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/ckit/src/tx-builders/unipass/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
];

Expand Down
2 changes: 2 additions & 0 deletions packages/ckit/src/wallets/UnipassWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
21 changes: 13 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"

[email protected]:
version "3.0.0"
Expand Down
Loading