Skip to content

Commit

Permalink
Add support for AIP-62 compatible SDK wallets (#279)
Browse files Browse the repository at this point in the history
* implement sdk standard wallets

* upgrade t wallet package version

* use production t wallet

* update changeset

* safer typing

* address feedback
  • Loading branch information
0xmaayan authored May 20, 2024
1 parent ef53f38 commit 870ee0c
Show file tree
Hide file tree
Showing 5 changed files with 730 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-items-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aptos-labs/wallet-adapter-core": minor
---

Support T Wallet as a SDK wallet in the adapter core
3 changes: 2 additions & 1 deletion packages/wallet-adapter-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"@aptos-labs/wallet-standard": "^0.0.11",
"buffer": "^6.0.3",
"eventemitter3": "^4.0.7",
"tweetnacl": "^1.0.3"
"tweetnacl": "^1.0.3",
"@atomrigslab/aptos-wallet-adapter": "^0.1.10"
},
"peerDependencies": {
"@aptos-labs/ts-sdk": "^1.13.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { TWallet } from "@atomrigslab/aptos-wallet-adapter";
import { AptosStandardWallet } from "./WalletStandard";

const sdkWallets: AptosStandardWallet[] = [];

sdkWallets.push(new TWallet());

export default sdkWallets;
31 changes: 23 additions & 8 deletions packages/wallet-adapter-core/src/WalletCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import {
NetworkInfo as StandardNetworkInfo,
UserResponse,
UserResponseStatus,
isWalletWithRequiredFeatureSet,
} from "@aptos-labs/wallet-standard";

import SDKWallets from "./AIP62StandardWallets/sdkWallets";
import { ChainIdToAnsSupportedNetworkMap, WalletReadyState } from "./constants";
import {
WalletAccountChangeError,
Expand Down Expand Up @@ -128,7 +130,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
this._wallets = plugins;
// Strategy to detect legacy wallet adapter v1 wallet plugins
this.scopePollingDetectionStrategy();
// Strategy to detect AIP-62 standard compatible wallets
// Strategy to detect AIP-62 standard compatible wallets (extension + SDK wallets)
this.fetchAptosWallets();
// Append AIP-62 compatible wallets that are not detected on the user machine
this.appendNotDetectedStandardSupportedWallets(this._standard_wallets);
Expand Down Expand Up @@ -194,15 +196,28 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
});
}

private async setWallets(wallets: readonly AptosWallet[]) {
/**
* Set potential Standard compatible SDK + extension wallets
*
* Loop over local SDK and Extensions wallets
* 1) check it is Standard compatible
* 2) Update their readyState to Installed (for a future UI detection)
* 3) push the wallet into a local wallets array
* 4) standardize each wallet to the Wallet Plugin type interface for legacy compatibility
*
* @param extensionwWallets
*/
private setWallets(extensionwWallets: readonly AptosWallet[]) {
const aptosStandardWallets: AptosStandardWallet[] = [];

wallets.map((wallet: AptosWallet) => {
const standardWallet = wallet as AptosStandardWallet;

standardWallet.readyState = WalletReadyState.Installed;
aptosStandardWallets.push(wallet);
this.standardizeStandardWalletToPluginWalletType(standardWallet);
[...SDKWallets, ...extensionwWallets].map((wallet: AptosStandardWallet) => {
const isValid = isWalletWithRequiredFeatureSet(wallet);
// TODO add user opt-in check
if (isValid) {
wallet.readyState = WalletReadyState.Installed;
aptosStandardWallets.push(wallet);
this.standardizeStandardWalletToPluginWalletType(wallet);
}
});

this._standard_wallets = aptosStandardWallets;
Expand Down
Loading

0 comments on commit 870ee0c

Please sign in to comment.