Given a ‘handle’ to a wallet (either a UiWallet or a UiWalletAccount) and the name of a feature, this hook returns the feature object from the underlying Wallet Standard Wallet. In the event that the wallet or account does not support the feature, a WalletStandardError will be thrown.
function ConnectButton({ children, wallet }) {
const connectFeature = useWalletFeature(wallet, 'standard:connect') as StandardConnectFeature;
return <button onClick={() => connectFeature.connect()}>{children}</button>;
}
function Error({ error }) {
let message;
if (isWalletStandardError(error, WALLET_STANDARD_ERROR__FEATURES__WALLET_FEATURE_UNIMPLEMENTED)) {
const { featureName, walletName } = error.context;
message = `The wallet '${walletName}' does not support the ${featureName} feature`;
} else {
message = 'Unknown error';
}
return <div className="errorMessage">{message}</div>;
}
function App() {
return (
<ErrorBoundary FallbackComponent={Error}>
<ConnectButton>Connect</ConnectButton>
</ErrorBoundary>
);
}
Given a ‘handle’ to a wallet (either a
UiWallet
or aUiWalletAccount
) and the name of a feature, this hook returns the feature object from the underlying Wallet StandardWallet
. In the event that the wallet or account does not support the feature, aWalletStandardError
will be thrown.