@wallet-standard/ui-features
TypeScript icon, indicating that this package has built-in type declarations

0.0.0-20240703212708 • Public • Published

@wallet-standard/ui-features

This package includes functions useful for getting wallet and wallet accounts features.

Functions

getWalletFeature(uiWalletHandle, featureName)

Given a ‘handle’ to a wallet (either a UiWallet or a UiWalletAccount) and the name of a feature, this function returns the feature object from the underlying Wallet Standard Wallet. If the wallet does not support the feature, a WalletStandardError will be thrown.

function ConnectButton({ children, wallet }) {
    const connectFeature = getWalletFeature(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>
    );
}

getWalletAccountFeature(uiWalletAccount, featureName)

Given a UiWalletAccount and the name of a feature, this function returns the feature object from the underlying Wallet Standard Wallet. This is a specialization of getWalletFeature() that takes into consideration that the features supported by a wallet might not be supported by every account in that wallet. In the event that the wallet or account does not support the feature, a WalletStandardError will be thrown.

Readme

Keywords

none

Package Sidebar

Install

npm i @wallet-standard/ui-features

Weekly Downloads

188

Version

0.0.0-20240703212708

License

Apache-2.0

Unpacked Size

45.6 kB

Total Files

40

Last publish

Collaborators

  • steveluscher
  • jordansexton