Skip to content

Commit

Permalink
Merge pull request #12 from WalletConnect/chore/update-deps
Browse files Browse the repository at this point in the history
chore: update deps to latest
  • Loading branch information
ganchoradkov authored May 22, 2023
2 parents 58651c4 + c5a8833 commit 7cedb00
Show file tree
Hide file tree
Showing 6 changed files with 539 additions and 326 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"build:types": "tsc",
"build:source": "rollup --config rollup.config.js",
"build": "npm run build:pre; npm run build:source; npm run build:types",
"test": "vitest run --dir test --no-threads",
"test": "vitest run --dir test",
"lint": "eslint --fix './src/**/*.ts'",
"prettier": "prettier --check '{src,test}/**/*.{js,ts,jsx,tsx}'",
"run:examples": "cd ./examples/dapp && yarn dev & cd ./examples/wallet && yarn dev",
Expand All @@ -33,7 +33,7 @@
"install:all": "yarn && cd ./examples/dapp && yarn && cd ./../wallet && yarn"
},
"dependencies": {
"@walletconnect/web3wallet": "1.7.0"
"@walletconnect/web3wallet": "1.7.4"
},
"devDependencies": {
"@ethersproject/wallet": "^5.7.0",
Expand All @@ -57,7 +57,7 @@
"rollup-plugin-polyfill-node": "0.10.2",
"typescript": "4.7.4",
"utf-8-validate": "6.0.3",
"vitest": "0.21.1",
"vitest": "^0.31.1",
"eslint-plugin-n": "^15.6.1"
},
"exports": {
Expand Down
34 changes: 15 additions & 19 deletions src/controllers/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,9 @@ export class Engine extends ISingleEthereumEngine {

const session = await this.web3wallet.approveSession(approveParams);
this.chainId = chainId;

// emit chainChanged if a different chain is approved other than the required
if (approvedChains.length > 1) {
await this.web3wallet.emitSessionEvent({
topic: session.topic,
event: {
name: "chainChanged",
data: chainId,
},
chainId: prefixChainWithNamespace(chainId),
});
setTimeout(() => this.changeChain(session.topic, chainId), 2_000);
}

return session;
Expand Down Expand Up @@ -117,14 +109,7 @@ export class Engine extends ISingleEthereumEngine {
});

if (this.chainId !== chainId) {
await this.web3wallet.emitSessionEvent({
topic,
event: {
name: "chainChanged",
data: chainId,
},
chainId: formattedChain,
});
await this.changeChain(topic, chainId);
this.chainId = chainId;
}

Expand Down Expand Up @@ -245,11 +230,10 @@ export class Engine extends ISingleEthereumEngine {
error: getSdkError("UNSUPPORTED_CHAINS"),
});
}

return this.client.events.emit("session_proposal", {
id: event.id,
params: proposal,
context: event.context,
verifyContext: event.verifyContext,
});
};

Expand Down Expand Up @@ -279,4 +263,16 @@ export class Engine extends ISingleEthereumEngine {
);
}
};

private changeChain = async (topic: string, chainId: number) => {
await this.web3wallet.engine.signClient.ping({ topic });
await this.web3wallet.emitSessionEvent({
topic,
event: {
name: "chainChanged",
data: chainId,
},
chainId: prefixChainWithNamespace(chainId),
});
};
}
2 changes: 1 addition & 1 deletion src/types/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export declare namespace SingleEthereumTypes {
request: { method: string; params: unknown };
chainId: string;
}> & {
context: Verify.Context;
verifyContext: Verify.Context;
};

type SessionProposal = Web3WalletTypes.SessionProposal;
Expand Down
2 changes: 1 addition & 1 deletion test/shared/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const TEST_NAMESPACES = {

export const TEST_UPDATED_NAMESPACES = {
eip155: {
methods: TEST_METHODS,
methods: TEST_METHODS.concat(TEST_OPTIONAL_METHODS),
accounts: [TEST_ETHEREUM_ACCOUNT, TEST_GOERLI_ACCOUNT],
events: TEST_EVENTS,
},
Expand Down
24 changes: 12 additions & 12 deletions test/sign.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ describe("Sign Integration", () => {
await Promise.all([
new Promise((resolve) => {
wallet.on("session_proposal", async (sessionProposal) => {
const { id, params, context } = sessionProposal;
expect(context).to.be.exist;
expect(context.verified.validation).to.eq("UNKNOWN");
const { id, params, verifyContext } = sessionProposal;
expect(verifyContext).to.be.exist;
expect(verifyContext.verified.validation).to.eq("UNKNOWN");
session = await wallet.approveSession({
id,
...TEST_APPROVE_PARAMS,
Expand All @@ -95,9 +95,9 @@ describe("Sign Integration", () => {
}),
new Promise((resolve) => {
wallet.on("session_proposal", async (sessionProposal) => {
const { id, params, context } = sessionProposal;
expect(context).to.be.exist;
expect(context.verified.validation).to.eq("UNKNOWN");
const { id, params, verifyContext } = sessionProposal;
expect(verifyContext).to.be.exist;
expect(verifyContext.verified.validation).to.eq("UNKNOWN");
session = await wallet.approveSession({
id,
...TEST_APPROVE_PARAMS,
Expand All @@ -117,9 +117,9 @@ describe("Sign Integration", () => {
await Promise.all([
new Promise((resolve) => {
wallet.on("session_proposal", async (sessionProposal) => {
const { id, params, context } = sessionProposal;
expect(context).to.be.exist;
expect(context.verified.validation).to.eq("UNKNOWN");
const { id, params, verifyContext } = sessionProposal;
expect(verifyContext).to.be.exist;
expect(verifyContext.verified.validation).to.eq("UNKNOWN");
session = await wallet.approveSession({
id,
...TEST_APPROVE_PARAMS,
Expand Down Expand Up @@ -218,9 +218,9 @@ describe("Sign Integration", () => {
await Promise.all([
new Promise((resolve) => {
wallet.on("session_request", async (sessionRequest) => {
const { id, params, context } = sessionRequest;
expect(context).to.be.exist;
expect(context.verified.validation).to.eq("UNKNOWN");
const { id, params, verifyContext } = sessionRequest;
expect(verifyContext).to.be.exist;
expect(verifyContext.verified.validation).to.eq("UNKNOWN");
const requestParams = params.request.params as TransactionRequest[];
const signTransaction = requestParams[0];
const signature = await cryptoWallet.signTransaction(signTransaction);
Expand Down
Loading

2 comments on commit 7cedb00

@vercel
Copy link

@vercel vercel bot commented on 7cedb00 May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

se-sdk-dapp – ./examples/dapp/

se-sdk-dapp.vercel.app
se-sdk-dapp-walletconnect1.vercel.app
se-sdk-dapp-git-main-walletconnect1.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 7cedb00 May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

se-sdk-wallet – ./examples/wallet/

se-sdk-wallet-git-main-walletconnect1.vercel.app
se-sdk-wallet-walletconnect1.vercel.app
se-sdk-wallet.vercel.app

Please sign in to comment.