Skip to content

Commit

Permalink
fix: fixes linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
andreahaku committed Jul 17, 2024
1 parent ea4cbf6 commit caaf925
Showing 1 changed file with 69 additions and 67 deletions.
136 changes: 69 additions & 67 deletions app/core/WalletConnect/WalletConnectV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ export class WC2Manager {
web3Wallet.on(
'session_delete',
async (event: SingleEthereumTypes.SessionDelete) => {
const session = sessions[event.topic];
const session = sessions?.[event.topic];
if (session && deeplinkSessions[session?.pairingTopic]) {
delete deeplinkSessions[session.pairingTopic];
await AsyncStorage.setItem(
Expand Down Expand Up @@ -576,80 +576,82 @@ export class WC2Manager {
}
).PermissionController;

Object.keys(sessions).forEach(async (sessionKey) => {
try {
const session = sessions[sessionKey];

this.sessions[sessionKey] = new WalletConnect2Session({
web3Wallet,
channelId: sessionKey,
navigation: this.navigation,
deeplink:
typeof deeplinkSessions[session.pairingTopic] !== 'undefined',
session,
});

// Find approvedAccounts for current sessions
DevLogger.log(
`WC2::init getPermittedAccounts for ${sessionKey} origin=${session.peer.metadata.url}`,
JSON.stringify(permissionController.state, null, 2),
);
const accountPermission = permissionController.getPermission(
session.peer.metadata.url,
'eth_accounts',
);

DevLogger.log(
`WC2::init accountPermission`,
JSON.stringify(accountPermission, null, 2),
);
let approvedAccounts =
(await getPermittedAccounts(accountPermission?.id ?? '')) ?? [];
const fromOrigin = await getPermittedAccounts(
session.peer.metadata.url,
);
if (sessions) {
Object.keys(sessions).forEach(async (sessionKey) => {
try {
const session = sessions[sessionKey];

this.sessions[sessionKey] = new WalletConnect2Session({
web3Wallet,
channelId: sessionKey,
navigation: this.navigation,
deeplink:
typeof deeplinkSessions[session.pairingTopic] !== 'undefined',
session,
});

// Find approvedAccounts for current sessions
DevLogger.log(
`WC2::init getPermittedAccounts for ${sessionKey} origin=${session.peer.metadata.url}`,
JSON.stringify(permissionController.state, null, 2),
);
const accountPermission = permissionController.getPermission(
session.peer.metadata.url,
'eth_accounts',
);

DevLogger.log(
`WC2::init approvedAccounts id ${accountPermission?.id}`,
approvedAccounts,
);
DevLogger.log(
`WC2::init fromOrigin ${session.peer.metadata.url}`,
fromOrigin,
);
DevLogger.log(
`WC2::init accountPermission`,
JSON.stringify(accountPermission, null, 2),
);
let approvedAccounts =
(await getPermittedAccounts(accountPermission?.id ?? '')) ?? [];
const fromOrigin = await getPermittedAccounts(
session.peer.metadata.url,
);

// fallback to origin from metadata url
if (approvedAccounts.length === 0) {
DevLogger.log(
`WC2::init fallback to metadata url ${session.peer.metadata.url}`,
`WC2::init approvedAccounts id ${accountPermission?.id}`,
approvedAccounts,
);
approvedAccounts =
(await getPermittedAccounts(session.peer.metadata.url)) ?? [];
}
DevLogger.log(
`WC2::init fromOrigin ${session.peer.metadata.url}`,
fromOrigin,
);

// fallback to origin from metadata url
if (approvedAccounts.length === 0) {
DevLogger.log(
`WC2::init fallback to metadata url ${session.peer.metadata.url}`,
);
approvedAccounts =
(await getPermittedAccounts(session.peer.metadata.url)) ?? [];
}

if (approvedAccounts?.length === 0) {
DevLogger.log(
`WC2::init fallback to parsing accountPermission`,
accountPermission,
);
// FIXME: Why getPermitted accounts doesn't work???
approvedAccounts = extractApprovedAccounts(accountPermission);
DevLogger.log(`WC2::init approvedAccounts`, approvedAccounts);
}

if (approvedAccounts?.length === 0) {
const nChainId = parseInt(chainId, 16);
DevLogger.log(
`WC2::init fallback to parsing accountPermission`,
accountPermission,
`WC2::init updateSession session=${sessionKey} chainId=${chainId} nChainId=${nChainId} selectedAddress=${selectedAddress}`,
approvedAccounts,
);
// FIXME: Why getPermitted accounts doesn't work???
approvedAccounts = extractApprovedAccounts(accountPermission);
DevLogger.log(`WC2::init approvedAccounts`, approvedAccounts);
await this.sessions[sessionKey].updateSession({
chainId: nChainId,
accounts: approvedAccounts,
});
} catch (err) {
console.warn(`WC2::init can't update session ${sessionKey}`);
}

const nChainId = parseInt(chainId, 16);
DevLogger.log(
`WC2::init updateSession session=${sessionKey} chainId=${chainId} nChainId=${nChainId} selectedAddress=${selectedAddress}`,
approvedAccounts,
);
await this.sessions[sessionKey].updateSession({
chainId: nChainId,
accounts: approvedAccounts,
});
} catch (err) {
console.warn(`WC2::init can't update session ${sessionKey}`);
}
});
});
}
}

public static async init({
Expand Down

0 comments on commit caaf925

Please sign in to comment.