Skip to content

Commit

Permalink
Support AIP-62 connect wallet method response (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmaayan authored Mar 29, 2024
1 parent a2060ef commit 4127cfb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-penguins-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aptos-labs/wallet-adapter-core": minor
---

Support AIP-62 connect wallet method response
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
UserResponseStatus,
AptosSignAndSubmitTransactionOutput,
AccountInfo as StandardAccountInfo,
AptosConnectOutput,
} from "@aptos-labs/wallet-standard";
import {
AnyRawTransaction,
Expand Down Expand Up @@ -35,6 +36,16 @@ export type AptosStandardWallet = AptosWallet & {
};

export class WalletStandardCore {
async connect(wallet: Wallet) {
const response =
(await wallet.connect()) as UserResponse<AptosConnectOutput>;

if (response.status === UserResponseStatus.REJECTED) {
throw new WalletConnectionError("User has rejected the request").message;
}
return response.args;
}

/**
* Signs and submits a transaction to chain
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ import {
import { areBCSArguments, generalizedErrorMessage } from "../utils";

export class WalletCoreV1 extends EventEmitter<WalletCoreEvents> {
async connect(wallet: Wallet) {
const account = await wallet.connect();
return account;
}

/**
* Resolve the transaction type (BCS arguments or Simple arguments)
*
Expand Down
10 changes: 7 additions & 3 deletions packages/wallet-adapter-core/src/WalletCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,12 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
try {
this._connecting = true;
this.setWallet(selectedWallet);
const account = await selectedWallet.connect();
let account;
if (selectedWallet.isAIP62Standard) {
account = await this.walletStandardCore.connect(selectedWallet);
} else {
account = await this.walletCoreV1.connect(selectedWallet);
}
this.setAccount(account);
const network = await selectedWallet.network();
this.setNetwork(network);
Expand Down Expand Up @@ -653,8 +658,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
): Promise<AccountAuthenticator> {
try {
this.ensureWalletExists(this._wallet);
this.ensureAccountExists(this._account);

console.log("this._account", this._account);
// Make sure wallet supports signTransaction
if (this._wallet.signTransaction) {
// If current connected wallet is AIP-62 standard compatible
Expand Down

0 comments on commit 4127cfb

Please sign in to comment.