0.0.25 • Published 2 years ago

@hoangman1108/aptos-adapter v0.0.25

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

aptos-wallet-adapter

React WalletProvider supporting loads of aptos wallets.

Supports:

Working on (PR welcome):

Installation

with yarn

yarn add @hoangman1108/aptos-adapter

with npm

npm install @hoangman1108/aptos-adapter

Examples

Frontend Integration

Here's an example of how we integrate the adapter into hippo's frontend:

Wallet integration

Wallets source code here.

Use React Provider

import React from "react";
import {
  WalletProvider,
  HippoWalletAdapter,
  AptosWalletAdapter,
  HippoExtensionWalletAdapter,
  MartianWalletAdapter,
  FewchaWalletAdapter,
  PontemWalletAdapter
} from '@hoangman1108/aptos-adapter';

const wallets = [
  new HippoWalletAdapter(),
  new MartianWalletAdapter(),
  new AptosWalletAdapter(),
  new FewchaWalletAdapter(),
  new HippoExtensionWalletAdapter(),
  new PontemWalletAdapter()
];

const App: React.FC = () => {
  return (
    <WalletProvider
      wallets={wallets}
      onError={(error: Error) => {
        console.log('Handle Error Message', error)
      }}>
      {/* your website */}
    </WalletProvider>
  );
};

export default App;

Web3 Hook

import { useWallet } from '@hoangman1108/aptos-adapter';

const { connected, account, ...rest } = useWallet();

/*
  ** Properties available: **

  wallets: Wallet[]; - Array of wallets
  wallet: Wallet | null; - Selected wallet
  account(): AccountKeys | null; - Wallet info: address, publicKey, authKey
  connected: boolean; - check the website is connected yet
  connect(walletName: string): Promise<void>; - trigger connect popup
  disconnect(): Promise<void>; - trigger disconnect action
  signAndSubmitTransaction(
    transaction: TransactionPayload
  ): Promise<PendingTransaction>; - function to sign and submit the transaction to chain
*/

Connect & Disconnect

import { AptosWalletName, useWallet } from "@hoangman1108/aptos-adapter"

...

const { connect, disconnect, connected } = useWallet();

if (!connected) {
  return (
    <button
      onClick={() => {
        connect(AptosWalletName); // E.g. connecting to the Aptos official wallet
      }}
    >
      Connect
    </button>
  );
} else {
  return (
    <button
      onClick={() => {
        disconnect();
      }}
    >
      Disconnect
    </button>
  );
}

source: `typescript @manahippo/aptos-wallet-adapter

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.1

2 years ago