-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor the account info output type to be compatible with AIP-62
standard
#441
base: main
Are you sure you want to change the base?
Conversation
API-62
standardAIP-62
standard
@@ -74,7 +79,7 @@ export declare interface WalletCoreEvents { | |||
readyStateChange(wallet: Wallet): void; | |||
standardWalletsAdded(wallets: Wallet | AptosStandardSupportedWallet): void; | |||
networkChange(network: NetworkInfo | null): void; | |||
accountChange(account: AccountInfo | null): void; | |||
accountChange(account: AccountInfo | StandardAccountInfoInput | null): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it might be better to just share the AccountInfoOutput
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is tricky as the adapter still supports legacy and new standard types, so the account the adapter gets back from the wallet can be of both types. Changing it gets us into a type-rabbit-hole, so we simply change the actual input type the adapter returns.
In the near future, we should probably support only AIP-62 wallets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use AccountInfo
from @aptos-labs/wallet-standard
here, that uses the PublicKey
type.
If I understand correctly, this is an event that can be listened to externally by the dapp.
Since we're bumping the major, we might as well clean up the interface and have the "right" type here.
In case of legacy plugins, we should be able to adapt the return types to AccountInfo
so that the dapp sees one consistent return type.
EDIT: here's a good spot where we could normalize
97d2efe
to
3eec0de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making this change!
As per my comments, I think we should try using AccountInfo
from the standard :)
@@ -74,7 +79,7 @@ export declare interface WalletCoreEvents { | |||
readyStateChange(wallet: Wallet): void; | |||
standardWalletsAdded(wallets: Wallet | AptosStandardSupportedWallet): void; | |||
networkChange(network: NetworkInfo | null): void; | |||
accountChange(account: AccountInfo | null): void; | |||
accountChange(account: AccountInfo | StandardAccountInfoInput | null): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use AccountInfo
from @aptos-labs/wallet-standard
here, that uses the PublicKey
type.
If I understand correctly, this is an event that can be listened to externally by the dapp.
Since we're bumping the major, we might as well clean up the interface and have the "right" type here.
In case of legacy plugins, we should be able to adapt the return types to AccountInfo
so that the dapp sees one consistent return type.
EDIT: here's a good spot where we could normalize
@@ -131,7 +131,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> { | |||
private _wallet: Wallet | null = null; | |||
|
|||
// Current connected account | |||
private _account: AccountInfo | null = null; | |||
private _account: AccountInfo | StandardAccountInfoInput | null = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, let's just use AccountInfo
from the standard. We can convert it to the right type before setting its value
@@ -465,7 +465,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> { | |||
* @param account An account | |||
*/ | |||
private ensureAccountExists( | |||
account: AccountInfo | null | |||
account: AccountInfo | StandardAccountInfoInput | null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
setAccount(account: AccountInfo | StandardAccountInfo | null): void { | ||
this._account = account; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a good spot where we support both AccountInfo
s (the old internal type, and the standard type) as inputs, and normalize it to the standard one.
@@ -687,9 +642,30 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> { | |||
* @return account info | |||
* @throws WalletAccountError | |||
*/ | |||
get account(): AccountInfo | null { | |||
get account(): AccountInfoOutput | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just return AccountInfo
from the wallet standard package
: // for backward compatibility, if the account public key is of type `string[]` convert each string to Ed25519PublicKey | ||
Array.isArray(this._account.publicKey) && | ||
this._account.publicKey.every( | ||
(item) => typeof item === "string" | ||
) | ||
? this._account.publicKey.map((key) => new Ed25519PublicKey(key)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we should convert string[]
and minKeysRequired
to MultiEd25519PublicKey
that extends PublicKey
@@ -147,7 +150,7 @@ function WalletSelection() { | |||
} | |||
|
|||
interface WalletConnectionProps { | |||
account: AccountInfo | null; | |||
account: AccountInfoOutput | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use AccountInfo
from the standard
@@ -44,9 +45,9 @@ export function isInstallRequired(wallet: AnyAptosWallet) { | |||
} | |||
|
|||
/** Truncates the provided wallet address at the middle with an ellipsis. */ | |||
export function truncateAddress(address: string | undefined) { | |||
export function truncateAddress(address: AccountAddress | undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nit: we could use AccountAddressInput
, but nbd
By quickly looking at the code, I think we could do this:
basically.. let's normalize as soon as we have a chance to make our life easier :) |
To support the different Public Key types and for developers to easily be able to pass the account info down to SDK functions, changing the Account Info return type to be compatible with AIP-62
An updated version with this change here: https://aptos-labs.github.io/aptos-wallet-adapter/nextjs-example-testing/
Will be released with a major version update
OLD
NEW
This way, one can do