Skip to content

Commit

Permalink
[core] Bumped @aptos-labs/wallet-standard to 0.2.0 to add transacti…
Browse files Browse the repository at this point in the history
…on input support
  • Loading branch information
hardsetting committed Sep 6, 2024
1 parent 9ff164b commit fb9f3ec
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions packages/wallet-adapter-core/src/WalletCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
plugins: ReadonlyArray<Wallet>,
optInWallets: ReadonlyArray<AvailableWallets>,
dappConfig?: DappConfig,
disableTelemetry?: boolean
disableTelemetry?: boolean,
) {
super();

Expand Down Expand Up @@ -191,7 +191,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
// new standard version installed. Pontem uses "Pontem" wallet name for previous versions and
// "Pontem Wallet" with new version
const existingStandardPontemWallet = this._standard_wallets.find(
(wallet) => wallet.name == "Pontem Wallet"
(wallet) => wallet.name == "Pontem Wallet",
);
if (wallet.name === "Pontem" && existingStandardPontemWallet) {
return;
Expand All @@ -203,7 +203,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
* include the plugin wallet (i.e npm package)
*/
const existingWalletIndex = this._standard_wallets.findIndex(
(standardWallet) => standardWallet.name == wallet.name
(standardWallet) => standardWallet.name == wallet.name,
);
if (existingWalletIndex !== -1) return;

Expand Down Expand Up @@ -258,7 +258,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
aptosStandardSupportedWalletList.map((supportedWallet) => {
// Check if we already have this wallet as an installed plugin
const existingPluginWalletIndex = this.wallets.findIndex(
(wallet) => wallet.name === supportedWallet.name
(wallet) => wallet.name === supportedWallet.name,
);

// If the plugin wallet is installed, dont append and dont show it on the selector modal
Expand All @@ -269,7 +269,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
// new standard version installed. Pontem uses "Pontem" wallet name for previous versions and
// "Pontem Wallet" with new version
const existingStandardPontemWallet = this.wallets.find(
(wallet) => wallet.name == "Pontem"
(wallet) => wallet.name == "Pontem",
);
if (
supportedWallet.name === "Pontem Wallet" &&
Expand All @@ -280,7 +280,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {

// Check if we already have this wallet as a AIP-62 wallet standard
const existingStandardWallet = this._standard_wallets.find(
(wallet) => wallet.name == supportedWallet.name
(wallet) => wallet.name == supportedWallet.name,
);

// If AIP-62 wallet detected but it is excluded by the dapp, dont add it to the wallets array
Expand Down Expand Up @@ -318,7 +318,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
// Twallet SDK fires a register event so the adapter assumes it is an extension wallet
// so filter out t wallet, remove it when twallet fixes it
const wallets = extensionwWallets.filter(
(wallet) => wallet.name !== "Dev T wallet" && wallet.name !== "T wallet"
(wallet) => wallet.name !== "Dev T wallet" && wallet.name !== "T wallet",
);

wallets.map((wallet: AptosStandardWallet) => {
Expand Down Expand Up @@ -376,7 +376,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
* @param standardWallet An AIP-62 standard compatible wallet
*/
private standardizeStandardWalletToPluginWalletType = (
standardWallet: AptosStandardWallet
standardWallet: AptosStandardWallet,
) => {
let standardWalletConvertedToWallet: Wallet = {
name: standardWallet.name as WalletName,
Expand All @@ -388,27 +388,27 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
network: standardWallet.features["aptos:network"].network,
account: standardWallet.features["aptos:account"].account,
signAndSubmitTransaction:
standardWallet.features["aptos:signAndSubmitTransaction"]
?.signAndSubmitTransaction,
standardWallet.features["aptos:signAndSubmitTransaction"]
?.signAndSubmitTransaction,
signMessage: standardWallet.features["aptos:signMessage"].signMessage,
onAccountChange:
standardWallet.features["aptos:onAccountChange"].onAccountChange,
standardWallet.features["aptos:onAccountChange"].onAccountChange,
onNetworkChange:
standardWallet.features["aptos:onNetworkChange"].onNetworkChange,
standardWallet.features["aptos:onNetworkChange"].onNetworkChange,
signTransaction:
standardWallet.features["aptos:signTransaction"].signTransaction,
standardWallet.features["aptos:signTransaction"].signTransaction,
openInMobileApp:
standardWallet.features["aptos:openInMobileApp"]?.openInMobileApp,
standardWallet.features["aptos:openInMobileApp"]?.openInMobileApp,
changeNetwork:
standardWallet.features["aptos:changeNetwork"]?.changeNetwork,
standardWallet.features["aptos:changeNetwork"]?.changeNetwork,
readyState: WalletReadyState.Installed,
isAIP62Standard: true,
isSignTransactionV1_1: standardWallet.features["aptos:signTransaction"]?.version === '1.1',
};

// Remove optional duplications in the _all_wallets array
this._all_wallets = this._all_wallets.filter(
(item) => item.name !== standardWalletConvertedToWallet.name
(item) => item.name !== standardWalletConvertedToWallet.name,
);
this._all_wallets.push(standardWalletConvertedToWallet);

Expand Down Expand Up @@ -450,7 +450,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
* @param account An account
*/
private ensureAccountExists(
account: AccountInfo | null
account: AccountInfo | null,
): asserts account is AccountInfo {
if (!account) {
throw new WalletAccountError("Account is not set").name;
Expand Down Expand Up @@ -538,7 +538,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
| AccountInfo
| StandardAccountInfo
| UserResponse<StandardAccountInfo>
| null
| null,
): void {
if (account === null) {
this._account = null;
Expand Down Expand Up @@ -707,7 +707,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
const allDetectedWallets = this._all_wallets as Array<Wallet>;

const selectedWallet = allDetectedWallets.find(
(wallet: Wallet) => wallet.name === walletName
(wallet: Wallet) => wallet.name === walletName,
);
if (!selectedWallet) return;

Expand All @@ -716,7 +716,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
// if the selected wallet is already connected, we don't need to connect again
if (this._wallet?.name === walletName)
throw new WalletConnectionError(
`${walletName} wallet is already connected`
`${walletName} wallet is already connected`,
).message;
}

Expand Down Expand Up @@ -815,7 +815,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
* @returns The pending transaction hash (V1 output) | PendingTransactionResponse (V2 output)
*/
async signAndSubmitTransaction(
transactionInput: InputTransactionData
transactionInput: InputTransactionData,
): Promise<
{ hash: Types.HexEncodedBytes; output?: any } | PendingTransactionResponse
> {
Expand Down Expand Up @@ -848,7 +848,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
aptos,
this._account,
this._wallet,
this._standard_wallets
this._standard_wallets,
);
return { hash, output };
} else {
Expand All @@ -858,7 +858,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
payloadData,
this._network,
this._wallet,
transactionInput
transactionInput,
);
return { hash, output };
}
Expand Down Expand Up @@ -899,7 +899,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
async signTransaction(
transactionOrPayload: AnyRawTransaction | Types.TransactionPayload,
asFeePayer?: boolean,
options?: InputGenerateTransactionOptions
options?: InputGenerateTransactionOptions,
): Promise<AccountAuthenticator> {
try {
this.ensureWalletExists(this._wallet);
Expand All @@ -916,12 +916,12 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
return await this.walletStandardCore.signTransaction(
transactionOrPayload,
this._wallet,
asFeePayer
asFeePayer,
);
} else if (this._wallet.isSignTransactionV1_1) {
// This wallet is AIP-62 compliant and supports payload generation
// This wallet is AIP-62 compliant and supports transaction inputs
const payload = convertPayloadInputV1ToV2(transactionOrPayload);
const optionsV1 = options as CompatibleTransactionOptions;
const optionsV1 = options as CompatibleTransactionOptions | undefined;
const { authenticator } = await this.walletStandardCore.signTransaction(
{
payload,
Expand All @@ -930,7 +930,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
gasUnitPrice: optionsV1?.gasUnitPrice ?? optionsV1?.gas_unit_price,
maxGasAmount: optionsV1?.maxGasAmount ?? optionsV1?.max_gas_amount,
sequenceNumber: optionsV1?.sequenceNumber,
sender: optionsV1.sender ? { address: AccountAddress.from(optionsV1.sender) } : undefined,
sender: optionsV1?.sender ? { address: AccountAddress.from(optionsV1.sender) } : undefined,
},
this._wallet,
);
Expand All @@ -941,7 +941,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
const sender = this._account.address;
const payload = await generateTransactionPayloadFromV1Input(
aptosConfig,
transactionOrPayload
transactionOrPayload,
);
const optionsV1 = options as CompatibleTransactionOptions;
const optionsV2 = {
Expand All @@ -962,7 +962,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
return await this.walletStandardCore.signTransaction(
new SimpleTransaction(rawTransaction),
this._wallet,
false
false,
);
}
}
Expand All @@ -973,7 +973,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
if ("rawTransaction" in transactionOrPayload) {
const accountAuthenticator = (await this._wallet.signTransaction(
transactionOrPayload,
asFeePayer
asFeePayer,
)) as AccountAuthenticator;

return accountAuthenticator;
Expand All @@ -988,7 +988,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
gas_unit_price: options?.gasUnitPrice
? BigInt(options?.gasUnitPrice)
: undefined,
}
},
);

if (!response) {
Expand All @@ -1007,15 +1007,15 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {

const accountAuthenticator = new AccountAuthenticatorEd25519(
new Ed25519PublicKey(publicKey),
new Ed25519Signature(signature)
new Ed25519Signature(signature),
);
return accountAuthenticator;
}
}

// If we are here it means this wallet does not support signTransaction
throw new WalletNotSupportedMethod(
`Sign Transaction is not supported by ${this.wallet?.name}`
`Sign Transaction is not supported by ${this.wallet?.name}`,
).message;
} catch (error: any) {
const errMsg = generalizedErrorMessage(error);
Expand Down Expand Up @@ -1052,7 +1052,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
* @returns PendingTransactionResponse
*/
async submitTransaction(
transaction: InputSubmitTransactionData
transaction: InputSubmitTransactionData,
): Promise<PendingTransactionResponse> {
try {
this.ensureWalletExists(this._wallet);
Expand Down Expand Up @@ -1094,10 +1094,10 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
}

/**
Event for when account has changed on the wallet
@return the new account info
@throws WalletAccountChangeError
*/
Event for when account has changed on the wallet
@return the new account info
@throws WalletAccountChangeError
*/
async onAccountChange(): Promise<void> {
try {
this.ensureWalletExists(this._wallet);
Expand All @@ -1107,7 +1107,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
await this.setAnsName();
this.recordEvent("account_change");
this.emit("accountChange", this._account);
}
},
);
} catch (error: any) {
const errMsg = generalizedErrorMessage(error);
Expand All @@ -1116,10 +1116,10 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
}

/**
Event for when network has changed on the wallet
@return the new network info
@throws WalletNetworkChangeError
*/
Event for when network has changed on the wallet
@return the new network info
@throws WalletNetworkChangeError
*/
async onNetworkChange(): Promise<void> {
try {
this.ensureWalletExists(this._wallet);
Expand All @@ -1128,7 +1128,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
this.setNetwork(data);
await this.setAnsName();
this.emit("networkChange", this._network);
}
},
);
} catch (error: any) {
const errMsg = generalizedErrorMessage(error);
Expand Down Expand Up @@ -1166,7 +1166,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
return response.args;
}
throw new WalletChangeNetworkError(
`${this._wallet.name} does not support changing network request`
`${this._wallet.name} does not support changing network request`,
).message;
} catch (error: any) {
const errMsg = generalizedErrorMessage(error);
Expand All @@ -1188,14 +1188,14 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
if (this._wallet.isAIP62Standard) {
return this.walletStandardCore.signMessageAndVerify(
message,
this._wallet
this._wallet,
);
}

return await this.walletCoreV1.signMessageAndVerify(
message,
this._wallet,
this._account
this._account,
);
} catch (error: any) {
const errMsg = generalizedErrorMessage(error);
Expand Down

0 comments on commit fb9f3ec

Please sign in to comment.