anza-xyz / wallet-standard

Solana extensions to the Wallet Standard.
Apache License 2.0
79 stars 42 forks source link

A generic hook for fetching concrete features for wallet handles #54

Closed steveluscher closed 2 months ago

steveluscher commented 3 months ago

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>
    );
}
steveluscher commented 3 months ago

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @steveluscher and the rest of your teammates on Graphite Graphite

steveluscher commented 2 months ago

Merge activity