Skip to content

Commit

Permalink
[Fix] use isAptosConnectWallet function to verify a wallet is an `A…
Browse files Browse the repository at this point in the history
…ptosConnect` wallet (#344)

* use isAptosConnectWallet

* add changeset
  • Loading branch information
0xmaayan authored Jun 26, 2024
1 parent 4254b5f commit 1644cfc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-coats-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aptos-labs/wallet-adapter-core": patch
---

use isAptosConnectWallet function to verify a wallet is an AptosConnect wallet in excludeWallet function
11 changes: 6 additions & 5 deletions packages/wallet-adapter-core/src/WalletCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
fetchDevnetChainId,
generalizedErrorMessage,
getAptosConfig,
isAptosConnectWallet,
isAptosNetwork,
isRedirectable,
removeLocalStorage,
Expand Down Expand Up @@ -224,7 +225,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
// If AIP-62 wallet detected but it is excluded by the dapp, dont add it to the wallets array
if (
existingStandardWallet &&
this.excludeWallet(existingStandardWallet.name)
this.excludeWallet(existingStandardWallet)
) {
return;
}
Expand Down Expand Up @@ -254,7 +255,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {

[...this._sdkWallets, ...extensionwWallets].map(
(wallet: AptosStandardWallet) => {
if (this.excludeWallet(wallet.name)) {
if (this.excludeWallet(wallet)) {
return;
}
const isValid = isWalletWithRequiredFeatureSet(wallet);
Expand All @@ -275,14 +276,14 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
* @param walletName
* @returns
*/
excludeWallet(walletName: string): boolean {
excludeWallet(wallet: AptosStandardWallet): boolean {
// for now, we always include AptosConnect
if (walletName === "Google (AptosConnect)") return false;
if (isAptosConnectWallet(wallet)) return false;
// If _optInWallets is not empty, and does not include the provided wallet,
// return true to exclude the wallet, otherwise return false
if (
this._optInWallets.length > 0 &&
!this._optInWallets.includes(walletName as AvailableWallets)
!this._optInWallets.includes(wallet.name as AvailableWallets)
) {
return true;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/wallet-adapter-core/src/utils/aptosConnect.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AptosStandardWallet } from "../AIP62StandardWallets";
import { WalletInfo } from "../LegacyWalletPlugins";
import { AnyAptosWallet } from "../WalletCore";
import { partitionWallets } from "./helpers";
Expand All @@ -10,7 +11,9 @@ export const APTOS_CONNECT_ACCOUNT_URL =
"https://aptosconnect.app/dashboard/main-account";

/** Returns `true` if the provided wallet is an Aptos Connect wallet. */
export function isAptosConnectWallet(wallet: WalletInfo | AnyAptosWallet) {
export function isAptosConnectWallet(
wallet: WalletInfo | AnyAptosWallet | AptosStandardWallet
) {
return wallet.url.startsWith(APTOS_CONNECT_BASE_URL);
}

Expand Down

0 comments on commit 1644cfc

Please sign in to comment.