Skip to content

Commit 9768323

Browse files
committed
Fix bug of Discord's wallet not being detected
1 parent 014e58a commit 9768323

File tree

12 files changed

+541
-561
lines changed

12 files changed

+541
-561
lines changed

packages/controller/src/wallets/bridge.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getAddress } from "ethers";
12
import { ArgentWallet } from "./argent";
23
import { MetaMaskWallet } from "./metamask";
34
import { PhantomWallet } from "./phantom";
@@ -134,11 +135,12 @@ export class WalletBridge {
134135
let wallet: WalletAdapter | undefined;
135136
if (typeof identifier === "string") {
136137
// this is an address
138+
const checkSummedAddress = getAddress(identifier);
139+
137140
wallet = this.walletAdapters.values().find((adapter) => {
138-
const ident = identifier.toLowerCase();
139141
return (
140-
adapter.getConnectedAccounts().includes(ident) ||
141-
adapter.type === ident
142+
adapter.getConnectedAccounts().includes(checkSummedAddress) ||
143+
adapter.type === checkSummedAddress
142144
);
143145
});
144146
} else {
@@ -149,7 +151,7 @@ export class WalletBridge {
149151
wallet = this.walletAdapters
150152
.values()
151153
.find((adapter) =>
152-
adapter.getConnectedAccounts().includes(identifier.toLowerCase()),
154+
adapter.getConnectedAccounts().includes(getAddress(identifier)),
153155
);
154156
}
155157

packages/controller/src/wallets/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ export * from "./bridge";
33
export * from "./metamask";
44
export * from "./phantom";
55
export * from "./rabby";
6-
export * from "./turnkey";
76
export * from "./types";
87
export * from "./wallet-connect";

packages/controller/src/wallets/metamask/index.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { MetaMaskSDK } from "@metamask/sdk";
2+
import { getAddress } from "ethers/address";
23
import { createStore } from "mipd";
34
import {
45
ExternalPlatform,
@@ -31,14 +32,20 @@ export class MetaMaskWallet implements WalletAdapter {
3132
})
3233
.then((accounts: any) => {
3334
if (accounts && accounts.length > 0) {
34-
this.account = accounts[0];
35-
this.connectedAccounts = accounts;
35+
this.account = getAddress(accounts[0]);
36+
this.connectedAccounts = accounts.map((account: string) =>
37+
getAddress(account),
38+
);
3639
}
3740
});
3841
this.MMSDK.getProvider()?.on("accountsChanged", (accounts: any) => {
3942
if (Array.isArray(accounts)) {
40-
this.account = accounts?.[0];
41-
this.connectedAccounts = accounts;
43+
if (accounts.length > 0) {
44+
this.account = getAddress(accounts?.[0]);
45+
}
46+
this.connectedAccounts = accounts.map((account: string) =>
47+
getAddress(account),
48+
);
4249
}
4350
});
4451
});
@@ -69,8 +76,8 @@ export class MetaMaskWallet implements WalletAdapter {
6976
}
7077

7178
async connect(address?: string): Promise<ExternalWalletResponse<any>> {
72-
if (address && this.connectedAccounts.includes(address)) {
73-
this.account = address;
79+
if (address && this.connectedAccounts.includes(getAddress(address))) {
80+
this.account = getAddress(address);
7481
}
7582

7683
if (this.account) {
@@ -84,8 +91,10 @@ export class MetaMaskWallet implements WalletAdapter {
8491

8592
const accounts = await this.MMSDK.connect();
8693
if (accounts && accounts.length > 0) {
87-
this.account = accounts[0];
88-
this.connectedAccounts = accounts;
94+
this.account = getAddress(accounts[0]);
95+
this.connectedAccounts = accounts.map((account: string) =>
96+
getAddress(account),
97+
);
8998
return { success: true, wallet: this.type, account: this.account };
9099
}
91100

@@ -141,7 +150,7 @@ export class MetaMaskWallet implements WalletAdapter {
141150

142151
const result = await this.MMSDK.getProvider()?.request({
143152
method: "personal_sign",
144-
params: [this.account!, message],
153+
params: [this.account, message],
145154
});
146155

147156
return { success: true, wallet: this.type, result };

packages/controller/src/wallets/rabby/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getAddress } from "ethers/address";
12
import { createStore, EIP6963ProviderDetail } from "mipd";
23
import {
34
ExternalPlatform,
@@ -31,10 +32,8 @@ export class RabbyWallet implements WalletAdapter {
3132
this.provider?.provider?.on("accountsChanged", (accounts: string[]) => {
3233
if (accounts) {
3334
// rabby doesn't allow multiple accounts to be connected at the same time
34-
this.connectedAccounts = accounts.map((account) =>
35-
account.toLowerCase(),
36-
);
37-
this.account = accounts?.[0]?.toLowerCase();
35+
this.connectedAccounts = accounts.map((account) => getAddress(account));
36+
this.account = getAddress(accounts?.[0]);
3837
}
3938
});
4039
}
@@ -58,8 +57,8 @@ export class RabbyWallet implements WalletAdapter {
5857
}
5958

6059
async connect(address?: string): Promise<ExternalWalletResponse<any>> {
61-
if (address && this.connectedAccounts.includes(address.toLowerCase())) {
62-
this.account = address.toLowerCase();
60+
if (address && this.connectedAccounts.includes(getAddress(address))) {
61+
this.account = getAddress(address);
6362
}
6463

6564
if (this.account) {

packages/controller/src/wallets/turnkey/index.ts

Lines changed: 0 additions & 195 deletions
This file was deleted.

packages/controller/src/wallets/wallet-connect/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Provider from "@walletconnect/ethereum-provider";
2+
import { getAddress } from "ethers/address";
23
import {
34
ExternalPlatform,
45
ExternalWallet,
@@ -17,7 +18,7 @@ export class WalletConnectWallet implements WalletAdapter {
1718
private provider: Provider,
1819
address?: string,
1920
) {
20-
this.account = address?.toLowerCase();
21+
this.account = address ? getAddress(address) : undefined;
2122
}
2223

2324
getConnectedAccounts(): string[] {

packages/keychain/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"dependencies": {
2424
"@auth0/auth0-react": "^2.3.0",
25+
"@auth0/auth0-spa-js": "^2.1.3",
2526
"@cartridge/controller-wasm": "catalog:",
2627
"@cartridge/controller": "workspace:*",
2728
"@cartridge/penpal": "catalog:",
@@ -32,7 +33,7 @@
3233
"@starknet-io/types-js": "catalog:",
3334
"@stripe/react-stripe-js": "^2.8.1",
3435
"@stripe/stripe-js": "^4.8.0",
35-
"@turnkey/sdk-browser": "^4.0.0",
36+
"@turnkey/sdk-browser": "^4.1.0",
3637
"@turnkey/sdk-react": "^4.2.1",
3738
"@walletconnect/ethereum-provider": "^2.20.0",
3839
"base64url": "catalog:",

packages/keychain/src/components/connect/create/social/auth0.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import { IdToken } from "@auth0/auth0-react";
22
import { jwtDecode, JwtPayload } from "jwt-decode";
33

44
export const getOidcToken = async (
5-
getIdTokenClaims: () => Promise<IdToken | undefined>,
5+
tokenClaims: IdToken | undefined,
66
expectedNonce: string,
77
) => {
8-
const tokenClaims = await getIdTokenClaims();
98
if (!tokenClaims) {
109
throw new Error("Not authenticated with Auth0 yet");
1110
}

0 commit comments

Comments
 (0)