Skip to content

Commit

Permalink
refactor: reverts replacing chains on update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gancho Radkov committed Mar 25, 2024
1 parent 099f303 commit bdecf43
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 40 deletions.
2 changes: 1 addition & 1 deletion examples/wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@json-rpc-tools/utils": "1.7.6",
"@nextui-org/react": "1.0.0-beta.12",
"@walletconnect/core": "2.11.2",
"@walletconnect/se-sdk": "1.7.0-canary-82cf156-1",
"@walletconnect/se-sdk": "1.7.1-canary.1",
"@walletconnect/utils": "2.11.2",
"ethers": "5.7.2",
"framer-motion": "9.0.2",
Expand Down
95 changes: 75 additions & 20 deletions examples/wallet/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,29 @@
lodash.isequal "4.5.0"
uint8arrays "^3.1.0"

"@walletconnect/[email protected]":
version "2.11.3"
resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.11.3.tgz#c81855722cb9afd411f91f5345c7874f48bade0b"
integrity sha512-/9m4EqiggFUwkQDv5PDWbcTI+yCVnBd/iYW5iIHEkivg2/mnBr2bQz2r/vtPjp19r/ZK62Dx0+UN3U+BWP8ulQ==
dependencies:
"@walletconnect/heartbeat" "1.2.1"
"@walletconnect/jsonrpc-provider" "1.0.13"
"@walletconnect/jsonrpc-types" "1.0.3"
"@walletconnect/jsonrpc-utils" "1.0.8"
"@walletconnect/jsonrpc-ws-connection" "1.0.14"
"@walletconnect/keyvaluestorage" "^1.1.1"
"@walletconnect/logger" "^2.0.1"
"@walletconnect/relay-api" "^1.0.9"
"@walletconnect/relay-auth" "^1.0.4"
"@walletconnect/safe-json" "^1.0.2"
"@walletconnect/time" "^1.0.2"
"@walletconnect/types" "2.11.3"
"@walletconnect/utils" "2.11.3"
events "^3.3.0"
isomorphic-unfetch "3.1.0"
lodash.isequal "4.5.0"
uint8arrays "^3.1.0"

"@walletconnect/core@^2.10.1":
version "2.10.1"
resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.10.1.tgz#d1fb442bd77424666bacdb0f5a07f7708fb3d984"
Expand Down Expand Up @@ -2066,26 +2089,26 @@
dependencies:
tslib "1.14.1"

"@walletconnect/[email protected].0-canary-82cf156-1":
version "1.7.0-canary-82cf156-1"
resolved "https://registry.yarnpkg.com/@walletconnect/se-sdk/-/se-sdk-1.7.0-canary-82cf156-1.tgz#e8b52b29d1f32a55e9d21bf13ff6441cc9b771ea"
integrity sha512-3DMq5hUdIh68u9KeUEenDwkTDm4Kif2B2qscNlqqo0bp/6bM0tSlwM6XwtOgty3VOysUHhhSE4G+lJafs1TagA==
"@walletconnect/[email protected].1-canary.1":
version "1.7.1-canary.1"
resolved "https://registry.yarnpkg.com/@walletconnect/se-sdk/-/se-sdk-1.7.1-canary.1.tgz#9b50fd5c36bc953e5de5bbf249b15112475791f3"
integrity sha512-FZx1a66VW7U07iUq0SwJH/dyEnX88GQIUHl1ceN5wSfL2HDAvJEjqHVWm4cLvozTLSA3Fd2ZU9iG3q7FQSmOwA==
dependencies:
"@walletconnect/web3wallet" "1.10.2"
"@walletconnect/web3wallet" "1.10.3"

"@walletconnect/[email protected].2":
version "2.11.2"
resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.11.2.tgz#855609653855f0d23b0502cdbdcf43402e34c459"
integrity sha512-MfBcuSz2GmMH+P7MrCP46mVE5qhP0ZyWA0FyIH6/WuxQ6G+MgKsGfaITqakpRPsykWOJq8tXMs3XvUPDU413OQ==
"@walletconnect/[email protected].3":
version "2.11.3"
resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.11.3.tgz#3ea7b3acf92ee31cc42b45d42e66c44b4720b28b"
integrity sha512-JVjLTxN/3NjMXv5zalSGKuSYLRyU2yX6AWEdq17cInlrwODpbWZr6PS1uxMWdH4r90DXBLhdtwDbEq/pfd0BPg==
dependencies:
"@walletconnect/core" "2.11.2"
"@walletconnect/core" "2.11.3"
"@walletconnect/events" "^1.0.1"
"@walletconnect/heartbeat" "1.2.1"
"@walletconnect/jsonrpc-utils" "1.0.8"
"@walletconnect/logger" "^2.0.1"
"@walletconnect/time" "^1.0.2"
"@walletconnect/types" "2.11.2"
"@walletconnect/utils" "2.11.2"
"@walletconnect/types" "2.11.3"
"@walletconnect/utils" "2.11.3"
events "^3.3.0"

"@walletconnect/time@^1.0.2":
Expand Down Expand Up @@ -2119,6 +2142,18 @@
"@walletconnect/logger" "^2.0.1"
events "^3.3.0"

"@walletconnect/[email protected]":
version "2.11.3"
resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.11.3.tgz#8ce43cb77e8fd9d5269847cdd73bcfa7cce7dd1a"
integrity sha512-JY4wA9MVosDW9dcJMTpnwliste0aJGJ1X6Q4ulLsQsgWRSEBRkLila0oUT01TDBW9Yq8uUp7uFOUTaKx6KWVAg==
dependencies:
"@walletconnect/events" "^1.0.1"
"@walletconnect/heartbeat" "1.2.1"
"@walletconnect/jsonrpc-types" "1.0.3"
"@walletconnect/keyvaluestorage" "^1.1.1"
"@walletconnect/logger" "^2.0.1"
events "^3.3.0"

"@walletconnect/[email protected]", "@walletconnect/utils@^2.10.1":
version "2.10.1"
resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.10.1.tgz#65b37c9800eb0e80a08385b6987471fb46e1e22e"
Expand Down Expand Up @@ -2159,19 +2194,39 @@
query-string "7.1.3"
uint8arrays "^3.1.0"

"@walletconnect/[email protected]":
version "1.10.2"
resolved "https://registry.yarnpkg.com/@walletconnect/web3wallet/-/web3wallet-1.10.2.tgz#5887642773e6e1b88d1bfb159a00ec45b31f762a"
integrity sha512-FbWsJwhihppl6poJ0+0WCkjXZDVdb11KJiS/AJt+qyNheIKQ7z6NfCnCnnKPBEpNNoUPclcFo4b/BmdFo2YlMw==
"@walletconnect/[email protected]":
version "2.11.3"
resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.11.3.tgz#3731809b54902655cf202e0bf0e8f268780e8b54"
integrity sha512-jsdNkrl/IcTkzWFn0S2d0urzBXg6RxVJtUYRsUx3qI3wzOGiABP9ui3yiZ3SgZOv9aRe62PaNp1qpbYZ+zPb8Q==
dependencies:
"@stablelib/chacha20poly1305" "1.0.1"
"@stablelib/hkdf" "1.0.1"
"@stablelib/random" "^1.0.2"
"@stablelib/sha256" "1.0.1"
"@stablelib/x25519" "^1.0.3"
"@walletconnect/relay-api" "^1.0.9"
"@walletconnect/safe-json" "^1.0.2"
"@walletconnect/time" "^1.0.2"
"@walletconnect/types" "2.11.3"
"@walletconnect/window-getters" "^1.0.1"
"@walletconnect/window-metadata" "^1.0.1"
detect-browser "5.3.0"
query-string "7.1.3"
uint8arrays "^3.1.0"

"@walletconnect/[email protected]":
version "1.10.3"
resolved "https://registry.yarnpkg.com/@walletconnect/web3wallet/-/web3wallet-1.10.3.tgz#8195308757bd298ccc9caa6e3fe9f4ff82b94607"
integrity sha512-1Dr2P8KIDCqEWZ+s4coKGJz/+pj87ogFs+icPDXPu9QpzTgY5Y1WSzuAHaqoY5gTlL7WS58YP49s0E7iacUz4g==
dependencies:
"@walletconnect/auth-client" "2.1.2"
"@walletconnect/core" "2.11.2"
"@walletconnect/core" "2.11.3"
"@walletconnect/jsonrpc-provider" "1.0.13"
"@walletconnect/jsonrpc-utils" "1.0.8"
"@walletconnect/logger" "2.0.1"
"@walletconnect/sign-client" "2.11.2"
"@walletconnect/types" "2.11.2"
"@walletconnect/utils" "2.11.2"
"@walletconnect/sign-client" "2.11.3"
"@walletconnect/types" "2.11.3"
"@walletconnect/utils" "2.11.3"

"@walletconnect/window-getters@^1.0.1":
version "1.0.1"
Expand Down
36 changes: 20 additions & 16 deletions src/controllers/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ export class Engine extends ISingleEthereumEngine {
const parsed = parseChain(chain);
return parseInt(parsed);
});
const approvedChains = [...new Set([chainId, ...requiredChains])];
const optionalChains = (normalizedOptional[EVM_IDENTIFIER]?.chains || []).map((chain) => {
const parsed = parseChain(chain);
return parseInt(parsed);
});

const approvedChains = [...new Set([chainId, ...requiredChains, ...optionalChains])];
const approveParams = {
id,
namespaces: {
Expand Down Expand Up @@ -111,16 +116,12 @@ export class Engine extends ISingleEthereumEngine {
const namespaces = session.namespaces[EVM_IDENTIFIER];
let shouldUpdateSession = false;
if (!chainAlreadyInSession(session, chainId)) {
const requiredChains = session.requiredNamespaces?.[EVM_IDENTIFIER]?.chains || [];
namespaces.chains = [formattedChain, ...requiredChains];
namespaces?.chains?.push(formattedChain);
shouldUpdateSession = true;
}

if (!accountsAlreadyInSession(session, formattedAccounts)) {
namespaces.accounts =
namespaces.chains
?.map((chain) => formatAccounts(accounts, parseInt(parseChain(chain))))
.flat() || [];
namespaces.accounts = namespaces.accounts.concat(formattedAccounts);
shouldUpdateSession = true;
}

Expand Down Expand Up @@ -149,15 +150,18 @@ export class Engine extends ISingleEthereumEngine {
await this.changeChain(topic, chainId);
this.chainId = chainId;
}

await this.web3wallet.emitSessionEvent({
topic,
event: {
name: "accountsChanged",
data: formattedAccounts,
},
chainId: formattedChain,
});
try {
await this.web3wallet.emitSessionEvent({
topic,
event: {
name: "accountsChanged",
data: formattedAccounts,
},
chainId: formattedChain,
});
} catch (e) {
this.client.logger.warn(e);
}
};

public approveRequest: ISingleEthereumEngine["approveRequest"] = async (params) => {
Expand Down
2 changes: 1 addition & 1 deletion test/shared/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const TEST_NAMESPACES = {
export const TEST_UPDATED_NAMESPACES = {
eip155: {
methods: TEST_METHODS.concat(TEST_OPTIONAL_METHODS),
accounts: [TEST_GOERLI_ACCOUNT, TEST_ETHEREUM_ACCOUNT],
accounts: [TEST_ETHEREUM_ACCOUNT, TEST_GOERLI_ACCOUNT],
events: TEST_EVENTS,
},
};
Expand Down
12 changes: 10 additions & 2 deletions test/sign.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,15 @@ describe("Sign Integration", () => {
new Promise((resolve) => {
dapp.events.on("session_update", (session) => {
const { params } = session;
expect(params.namespaces).to.toMatchObject(TEST_UPDATED_NAMESPACES);
expect(params.namespaces.eip155.accounts).to.toMatchObject(
TEST_UPDATED_NAMESPACES.eip155.accounts,
);
expect(params.namespaces.eip155.methods).to.toMatchObject(
TEST_UPDATED_NAMESPACES.eip155.methods,
);
expect(params.namespaces.eip155.events).to.toMatchObject(
TEST_UPDATED_NAMESPACES.eip155.events,
);
resolve(session);
});
}),
Expand Down Expand Up @@ -261,7 +269,7 @@ describe("Sign Integration", () => {
]);
});

it("should replace approved chainId on update", async () => {
it.skip("should replace approved chainId on update", async () => {
dapp = await SignClient.init({
...TEST_CORE_OPTIONS,
name: "Dapp",
Expand Down

0 comments on commit bdecf43

Please sign in to comment.