npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@amax/amaxwallet-adapters

v1.1.1

Published

Wallet adapters to help developers interact with Amax wallets using consistent API.

Downloads

3

Readme

@amax/amaxwallet-adapters

@amax/amaxwallet-adapters provides multiple wallet adapters to help developers connect to Amax wallet.

Supported wallets

As @amax/amaxwallet-adapters exports adapter of each wallet , you can use this package, or use the individual wallet adapter you want.

| NPM package | Description | Source Code | | -------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | | @amax/amaxwallet-adapters | Includes all the wallet adapters | View | | @amax/amaxwallet-adapter-armodillo | adapter for Armadillo | View | | @amax/amaxwallet-adapter-aplink | adapter for adapter for APLink | View | | @amax/amaxwallet-adapter-metamask | adapter for Metamask | View | | "@amax/amaxwallet-adapter-unisat | adapter for UniSat | View |

Usage

If you are working in a typescript project, you must set skipLibCheck: true in tsconfig.json.

React

You can use @amax/amaxwallet-adapters in your component. Use useMemo to memorize the adapter to improve your web performance.

import { ArmodilloAdapter } from '@amax/amaxwallet-adapters';

function App() {
    const [readyState, setReadyState] = useState(WalletReadyState.NotFound);
    const [account, setAccount] = useState('');
    const [signedMessage, setSignedMessage] = useState('');

    const adapter = useMemo(() => new ArmodilloAdapter({permission: 'owner' }), []);

    useEffect(() => {
        setReadyState(adapter.readyState);
        setAccount(adapter.account!);

        adapter.on('connect', () => {
            setAccount(adapter.account!);
        });

        adapter.on('readyStateChanged', (state) => {
            setReadyState(state);
        });

        adapter.on('accountsChanged', (data) => {
            setAccount(data);
        });

        adapter.on('disconnect', () => {
            // when disconnect from wallet
        });
        return () => {
            // remove all listeners when components is destroyed
            adapter.removeAllListeners();
        };
    }, []);

    async function sign() {
        const res = await adapter!.signMessage('helloworld');
        setSignedMessage(res);
    }

    return (
        <div className="App">
            <div>readyState: {readyState}</div>
            <div>current account: {JSON.stringify(account)}</div>
            <button disabled={adapter.connected} onClick={() => adapter.connect()}>
                Connect to Amax
            </button>
            <button onClick={sign}>sign message</button>
            <br />
            SignedMessage: {signedMessage}
        </div>
    );
}

A demo with cdn file can be found here.

Vue

In Vue, as the created/mounted hook just can be executed once, you can init the adapter in mounted or created hook.

// vue2.x
export default {
    created() {
        this.adapter = new ArmodilloAdapter();
        this.adapter.on('connect', () => {
            // here you can do something
        });
    },
    beforeDestroy() {
        this.adapter.removeAllListeners();
    }
}

// vue3
export default {
    setup() {
        onMounted(function() {
            const adapter = new ArmodilloAdapter();
            adapter.on('connect', () => {
                // here you can do something
            });
        });
        onBeforeUnmount(function() {
            // remove all listeners when components is destroyed
            adapter.removeAllListeners();
        });
        return {};
    }
}

API Reference

Adapter

The Adapter class defines the common interface for all adapters of specified wallets.

Constructor

  • constructor(config): adapter constructor method, an optional config is valid. For detailed config type, refer to the following adapter section.

Properties

  • name: The name of the adapter.
  • url: The website of the adapter's wallet.
  • icon: The icon of the adapter's wallet.
  • readyState: The wallet's state, which includes three value:
    • Loading: When adapter is checking if the wallet is available or not.
    • NotFound: The wallet is not detected in current browser.
    • Found: The wallet is detected in current browser.
  • account: The account of current account when the adapter is connected.
  • connecting: Whether the adapter is trying to connect to the wallet.
  • connected: Whether the adapter is connected to the wallet.

Methods

  • connect(): Promise<void>: connect to the wallet.
  • disconnect(): Promise<void>: disconnect to the wallet.
  • signMessage(message): Promise<string>: sign a string, return the signature result.
  • transact(actions): Promise<TransactResult>: push a transaction.

Events

Adapter extends the EventEmitter class in eventemitter3 package. So you can listen to the events by adapter.on('connect', function() {}).

Events are as follows:

  • connect(address): Emit when adapter is connected to the wallet. The parameter is the address of current account.
  • disconnect(): Emit when adapter is disconnected to the wallet.
  • readyStateChanged(state: WalletReadyState): Emit when wallet's readyState is changed. The parameter is the state of wallet:
    enum WalletReadyState {
        /**
         * Adapter will start to check if wallet exists after adapter instance is created.
         */
        Loading = 'Loading',
        /**
         * When checking ends and wallet is not found, readyState will be NotFound.
         */
        NotFound = 'NotFound',
        /**
         * When checking ends and wallet is found, readyState will be Found.
         */
        Found = 'Found',
    }
  • accountsChanged(address: string, preAddress: string): Emit when users change the current selected account in wallet. The parameter is the address of new account.
  • chainChanged(chainInfo: ChainInfo): Emit when users change the current selected chain in wallet. The parameter is the new network config:
    interface ChainInfo {
        chainId: string;
    }
  • error(WalletError): Emit when there are some errors when call the adapter's method. The [WalletError Types] is defined as follows.

WalletError

WalletError is a superclass which defines the error when using adapter. All error types are extended from this class. Developers can check the error type according to the error instance.

try {
    // do something here
} catch (error: WalletError) {
    if (error instanceof WalletNotFoundError) {
        console.log('Wallet is not found');
    }
}

All errors are as follows:

  • WalletNotFoundError: Occurs when wallet is not installed.
  • WalletNotSelectedError: Occurs when connect but there is no selected wallet.
  • WalletDisconnectedError: Occurs when wallet is disconnected. Used by some wallets which won't connect automatically when call signMessage() or signTransaction().
  • WalletConnectionError: Occurs when try to connect a wallet.
  • WalletDisconnectionError: Occurs when try to disconnect a wallet.
  • WalletSignMessageError: Occurs when call signMessage().
  • WalletSignTransactionError: Occurs when call signTransaction().

Following exmaple shows how to get original error info with WalletError:

const adapter = new ArmodilloAdapter();
try {
    await adapter.connect();
} catch (e: any) {
    const originalError = e.error;
}
  • Constructor(config: ArmodilloAdapterConfig)

    interface ArmodilloAdapterConfig {
        permission?: string;
        walletProviderLocalStorageKey?: string;
    }
  • TronLink Doesn't support disconnect by DApp. As ArmodilloAdapter doesn't support disconnect by DApp website, call adapter.disconnect() won't disconnect from amax extension really.

  • Auto open TronLink app in mobile browser. If developers call connect() method in mobile browser, it will open DApp in TronLink app to get amax wallet.