Skip to content

Commit

Permalink
Merge pull request #13 from Conflux-Chain/feat/add-chain
Browse files Browse the repository at this point in the history
feat: optional checkConnected before addChain
  • Loading branch information
SSSensational authored Jan 17, 2024
2 parents e3a5fef + 877d696 commit 24a2d42
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions core/base/src/emitter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ class Emitter<T extends RPCMethod> {
return this.RPCMethod.typedSign(typedData);
};

public addChain: T['addChain'] = (params: unknown) => {
public addChain = (params: Parameters<T['addChain']>[0], needConnected = true) => {
if (!this.RPCMethod.addChain) {
throw new Error(`Current Wallet does'nt have addChain method.`);
}

this.checkConnected('addChain');
return this.RPCMethod.addChain(params);
needConnected && this.checkConnected('addChain');
return this.RPCMethod.addChain(params) as ReturnType<T['addChain']>;
};

public switchChain: T['switchChain'] = (params: unknown) => {
Expand Down
2 changes: 1 addition & 1 deletion core/react/build/dts/chain.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export declare const connect: () => Promise<string[]>;
export declare const sendTransaction: (params: Omit<import("./type").TransactionParameters, "from">) => Promise<string>;
export declare const personalSign: (message: string) => Promise<string>;
export declare const typedSign: (typedData: import("./type").TypedSignParams) => Promise<string>;
export declare const addChain: (params: import("./type").AddChainParameter) => Promise<string>;
export declare const addChain: (params: import('./type').AddChainParameter, needConnected?: boolean) => Promise<string>;
export declare const switchChain: (chainId: string) => Promise<string>;
export declare const watchAsset: (param: import("./type").WatchAssetParams) => Promise<string>;
export declare const provider: import("./type").Provider | undefined;
Expand Down
2 changes: 1 addition & 1 deletion core/react/build/dts/wallet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export declare const connect: () => Promise<string[]>;
export declare const sendTransaction: (params: Omit<import('./type').TransactionParameters, 'from'>) => Promise<string>;
export declare const personalSign: (message: string) => Promise<string>;
export declare const typedSign: (typedData: import('./type').TypedSignParams) => Promise<string>;
export declare const addChain: (params: import('./type').AddChainParameter) => Promise<string>;
export declare const addChain: (params: import('./type').AddChainParameter, needConnected?: boolean) => Promise<string>;
export declare const switchChain: (chainId: string) => Promise<string>;
export declare const watchAsset: (param: import('./type').WatchAssetParams) => Promise<string>;
export declare const provider: import('./type').Provider | undefined;
Expand Down
2 changes: 1 addition & 1 deletion core/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react",
"version": "0.0.2-5",
"version": "0.0.2-6",
"type": "module",
"scripts": {
"build": "rimraf dist && node ./build/index.js",
Expand Down
2 changes: 1 addition & 1 deletion core/vue3/build/dts/chain.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export declare const connect: () => Promise<string[]>;
export declare const sendTransaction: (params: Omit<import("./type").TransactionParameters, "from">) => Promise<string>;
export declare const personalSign: (message: string) => Promise<string>;
export declare const typedSign: (typedData: Record<string, any>) => Promise<string>;
export declare const addChain: (params: import("./type").AddChainParameter) => Promise<string>;
export declare const addChain: (params: import('./type').AddChainParameter, needConnected?: boolean) => Promise<string>;
export declare const switchChain: (chainId: string) => Promise<string>;
export declare const watchAsset: (param: import("./type").WatchAssetParams) => Promise<string>;
export declare const provider: import("./type").Provider | undefined;
Expand Down
2 changes: 1 addition & 1 deletion core/vue3/build/dts/wallet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export declare const connect: () => Promise<string[]>;
export declare const sendTransaction: (params: Omit<import("./type").TransactionParameters, "from">) => Promise<string>;
export declare const personalSign: (message: string) => Promise<string>;
export declare const typedSign: (typedData: Record<string, any>) => Promise<string>;
export declare const addChain: (params: import("./type").AddChainParameter) => Promise<string>;
export declare const addChain: (params: import('./type').AddChainParameter, needConnected?: boolean) => Promise<string>;
export declare const switchChain: (chainId: string) => Promise<string>;
export declare const watchAsset: (param: import("./type").WatchAssetParams) => Promise<string>;
export declare const provider: import("./type").Provider | undefined;
Expand Down
2 changes: 1 addition & 1 deletion core/vue3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue3",
"version": "0.0.2-5",
"version": "0.0.2-6",
"type": "module",
"scripts": {
"build": "rimraf dist && node ./build/index.js",
Expand Down

0 comments on commit 24a2d42

Please sign in to comment.