You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling connect behind the seen the enable method is called and in case the wallet is virtual then the loadWallet method is called.
As neither resolveVirtualWallet nor isVirtualWallet is externally exposed by get-starknet the only way to get this behaviour without calling connect is by calling the loadWallet method of a VirtualWallet directly.
A quick a dirty implementation of this is to slightly change the scanObjectForWalletsCustom method and ensuring that we try to load virtual wallet in all cases.
A simple piece of code to achieve this could be
// If not valid still check maybe its a virtual wallet ?
if(!isValid){
try{
resolveVirtualWallet
wallet = await (wallet as any).loadWallet(window)
}
catch(e){
console.log(e)
}
isValid = await checkCompatibility(wallet);
}
The full method becomes :
export async function scanObjectForWalletsCustom(
obj: Record<string, any>, // Browser window object
isWalletObject: (wallet: any) => boolean,
): Promise<ValidWallet[]> {
const wallets = await sn.getAvailableWallets({});
const validWallets: ValidWallet[] = await Promise.all(wallets.map(
async (wallet: WALLET_API.StarknetWindowObject) => {
let isValid = await checkCompatibility(wallet);
// If not valid still check maybe its a virtual wallet ?
if(!isValid){
try{
resolveVirtualWallet
wallet = await (wallet as any).loadWallet(window)
}
catch(e){
console.log(e)
}
isValid = await checkCompatibility(wallet);
}
return { wallet: wallet, isValid: isValid } as ValidWallet;
}
))
console.log(validWallets);
return validWallets;
}
With this slight change we are able to get a proper detection of MetaMask, see the video below :
Screen.Recording.2024-10-31.at.14.38.51.mov
The text was updated successfully, but these errors were encountered:
In
get-starknet
VirtualWallet behave differently that Normal Wallet. Theenable
method defined in https://github.com/starknet-io/get-starknet/blob/51d946452326ae02cf85211ccdd7995f5d7bbce2/packages/core/src/main.ts#L119 is simply a pass through for Normal Wallet (identity
). So it can be skipped for Normal Wallet. But when a VirtualWallet is detected then the methodresolveVirtualWallet
is called to actually resolve the virtual wallet and load it properly.A virtual wallet is :
When calling
connect
behind the seen theenable
method is called and in case the wallet is virtual then theloadWallet
method is called.As neither
resolveVirtualWallet
norisVirtualWallet
is externally exposed by get-starknet the only way to get this behaviour without calling connect is by calling theloadWallet
method of a VirtualWallet directly.A quick a dirty implementation of this is to slightly change the
scanObjectForWalletsCustom
method and ensuring that we try to load virtual wallet in all cases.A simple piece of code to achieve this could be
The full method becomes :
With this slight change we are able to get a proper detection of MetaMask, see the video below :
Screen.Recording.2024-10-31.at.14.38.51.mov
The text was updated successfully, but these errors were encountered: