Coder Social home page Coder Social logo

near / wallet-selector Goto Github PK

View Code? Open in Web Editor NEW
141.0 10.0 132.0 67.07 MB

This is a wallet selector modal that allows users to interact with NEAR dApps with a selection of available wallets.

Home Page: https://near.github.io/wallet-selector/

License: Apache License 2.0

TypeScript 89.80% JavaScript 1.09% CSS 8.93% Shell 0.18%
blockchain wallets nearprotocol near-blockchain near-wallet ledger dapps

wallet-selector's Introduction

NEAR Wallet Selector

NEAR Wallet Selector makes it easy for users to interact with your dApp by providing an abstraction over various wallets within the NEAR ecosystem:

Preview

React / Next.js and Angular variations of the Guest Book dApp can be found in the examples directory. You can use these to gain a concrete understanding of how to integrate NEAR Wallet Selector into your own dApp.

Preview

Installation and Usage

The easiest way to use NEAR Wallet Selector is to install the core package from the NPM registry, some packages may require near-api-js v1.0.0 or above check them at packages

# Using Yarn
yarn add near-api-js

# Using NPM.
npm install near-api-js
# Using Yarn
yarn add @near-wallet-selector/core

# Using NPM.
npm install @near-wallet-selector/core

Next, you'll need to install the wallets you want to support:

# Using Yarn
yarn add \
  @near-wallet-selector/bitget-wallet \
  @near-wallet-selector/my-near-wallet \
  @near-wallet-selector/sender \
  @near-wallet-selector/nearfi \
  @near-wallet-selector/here-wallet \
  @near-wallet-selector/math-wallet \
  @near-wallet-selector/nightly \
  @near-wallet-selector/meteor-wallet \
  @near-wallet-selector/okx-wallet \
  @near-wallet-selector/narwallets \
  @near-wallet-selector/welldone-wallet \
  @near-wallet-selector/near-snap \
  @near-wallet-selector/ledger \
  @near-wallet-selector/wallet-connect \
  @near-wallet-selector/coin98-wallet \
  @near-wallet-selector/neth \
  @near-wallet-selector/xdefi \
  @near-wallet-selector/ramper-wallet \
  @near-wallet-selector/near-mobile-wallet  \
  @near-wallet-selector/bitget-wallet \
  @near-wallet-selector/okx-wallet \
  @near-wallet-selector/mintbase-wallet \
  @near-wallet-selector/bitte-wallet \
  @near-wallet-selector/ethereum-wallets


# Using NPM.
npm install \
  @near-wallet-selector/bitget-wallet \
  @near-wallet-selector/my-near-wallet \
  @near-wallet-selector/sender \
  @near-wallet-selector/nearfi \
  @near-wallet-selector/here-wallet \
  @near-wallet-selector/math-wallet \
  @near-wallet-selector/nightly \
  @near-wallet-selector/meteor-wallet \
  @near-wallet-selector/okx-wallet \
  @near-wallet-selector/narwallets \
  @near-wallet-selector/welldone-wallet \
  @near-wallet-selector/near-snap \
  @near-wallet-selector/ledger \
  @near-wallet-selector/wallet-connect \
  @near-wallet-selector/coin98-wallet \
  @near-wallet-selector/neth \
  @near-wallet-selector/xdefi \
  @near-wallet-selector/ramper-wallet \
  @near-wallet-selector/near-mobile-wallet \
  @near-wallet-selector/bitget-wallet \
  @near-wallet-selector/okx-wallet \
  @near-wallet-selector/mintbase-wallet \
  @near-wallet-selector/bitte-wallet \
  @near-wallet-selector/ethereum-wallets

Optionally, you can install our modal-ui or modal-ui-js package for a pre-built interface that wraps the core API and presents the supported wallets:

# Using Yarn
yarn add @near-wallet-selector/modal-ui

# Using NPM.
npm install @near-wallet-selector/modal-ui

Then in your dApp:

import { setupWalletSelector } from "@near-wallet-selector/core";
import { setupModal } from "@near-wallet-selector/modal-ui";
import { setupBitgetWallet } from "@near-wallet-selector/bitget-wallet";
import { setupMyNearWallet } from "@near-wallet-selector/my-near-wallet";
import { setupSender } from "@near-wallet-selector/sender";
import { setupHereWallet } from "@near-wallet-selector/here-wallet";
import { setupNearSnap } from "@near-wallet-selector/near-snap";
import { setupMathWallet } from "@near-wallet-selector/math-wallet";
import { setupNightly } from "@near-wallet-selector/nightly";
import { setupMeteorWallet } from "@near-wallet-selector/meteor-wallet";
import { setupOkxWallet } from "@near-wallet-selector/okx-wallet";
import { setupNarwallets } from "@near-wallet-selector/narwallets";
import { setupWelldoneWallet } from "@near-wallet-selector/welldone-wallet";
import { setupLedger } from "@near-wallet-selector/ledger";
import { setupWalletConnect } from "@near-wallet-selector/wallet-connect";
import { setupNearFi } from "@near-wallet-selector/nearfi";
import { setupCoin98Wallet } from "@near-wallet-selector/coin98-wallet";
import { setupNeth } from "@near-wallet-selector/neth";
import { setupXDEFI } from "@near-wallet-selector/xdefi";
import { setupRamperWallet } from "@near-wallet-selector/ramper-wallet";
import { setupNearMobileWallet } from "@near-wallet-selector/near-mobile-wallet"; 
import { setupMintbaseWallet } from "@near-wallet-selector/mintbase-wallet"; 
import { setupBitteWallet } from "@near-wallet-selector/bitte-wallet";
import { setupEthereumWallets } from "@near-wallet-selector/ethereum-wallets";

const selector = await setupWalletSelector({
  network: "testnet",
  modules: [
    setupBitgetWallet(),
    setupMyNearWallet(),
    setupSender(),
    setupHereWallet(),
    setupMathWallet(),
    setupNightly(),
    setupMeteorWallet(),
    setupNearSnap(),
    setupOkxWallet(),
    setupNarwallets(),
    setupWelldoneWallet(),
    setupLedger(),
    setupNearFi(),
    setupCoin98Wallet(),
    setupNeth(),
    setupXDEFI(),
    setupWalletConnect({
      projectId: "c4f79cc...",
      metadata: {
        name: "NEAR Wallet Selector",
        description: "Example dApp used by NEAR Wallet Selector",
        url: "https://github.com/near/wallet-selector",
        icons: ["https://avatars.githubusercontent.com/u/37784886"],
      },
    }),
    setupNearMobileWallet(),
    setupMintbaseWallet({
          networkId: "mainnet",
          walletUrl: "https://wallet.mintbase.xyz",
          callbackUrl: "https://www.mywebsite.com",
          deprecated: false,
    }),
    setupBitteWallet({
        networkId: "mainnet",
        walletUrl: "https://wallet.bitte.ai",
        callbackUrl: "https://www.mywebsite.com",
        deprecated: false,
    }),
    setupEthereumWallets({ wagmiConfig, web3Modal }),
  ],
});

const modal = setupModal(selector, {
  contractId: "guest-book.testnet"
});

Wallet Package Documentation

Each wallet package contains its own README document, please refer inside the packages folder for extra information.

Contributing

Contributors may find the examples directory useful as it provides a quick and consistent way to manually test new changes and/or bug fixes.

More details around contributing to this project can be found here.

Editor Setup

This project uses ESLint (with Prettier) to enforce a consistent coding style. It's important that you configure your editor correctly to avoid issues when you're ready to open a Pull Request.

Although this project uses Prettier, it's simply an "internal" dependency to our ESLint configuration. This is because we want Prettier to handle code styling while avoiding conflicts with ESLint which specifically focuses on potentially problematic code. As a result, it's important that you switch off Prettier in your editor and ensure only ESLint is enabled.

License

This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0). See LICENSE-MIT and LICENSE-APACHE for details.

wallet-selector's People

Contributors

amirsaran3 avatar ammarhumackicsqa avatar andy-haynes avatar azbang avatar bendegalab avatar beroburny avatar calcifer1001 avatar damirsqa avatar dependabot[bot] avatar erditkurteshisqa avatar gentbinakusqa avatar guillemgarciadev avatar harissqa avatar hcho112 avatar irubido avatar khiemsoft avatar kujtimprenkusqa avatar lewis-sqa avatar lostpebble avatar mattlockyer avatar near-bulldozer[bot] avatar norbertbodziony avatar paouvrard avatar pawel-szydlo avatar pivanov avatar rgolea avatar rubenmarcus avatar think-in-universe avatar trechriron avatar yoon-suji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wallet-selector's Issues

Restructure classes into injected, wallets and hardware

Related to user story #3

Currently, everything is extended from the BaseWallet class. To add more abstraction the logic needs to be separated into multiple wallet types.

Types:

  • injected (browser extensions)
  • wallet (redirect/website wallet)
  • hardware (ledger)

This is a suggestion from Mike.

Add SenderWallet install message

When the user selects SenderWallet provider option from the modal, if the SenderWallet extension is not detected the message "You'll need to install SenderWallet extension to continue. After installing refresh the page." is shown with the link to redirect to the chrome web store to install it.

Link: chrome web store

Example:
Screen Shot 2021-12-30 at 2 51 32 PM

Show "What is a wallet?" explonation in the guest book example

When initializing the wallet selector in the options object pass also the following option (object):

walletSelectorUI: {
  description: "Please select a wallet to connect to this dapp:",
  explanation: `Wallets are used to send, receive, and store digital assets. There are different types of wallets. 
              They can be an extension added to your browser, a hardware device plugged into your computer, 
              web-based, or as an app on your phone.`,
}

Repository: https://github.com/amirsaran3/guest-book-example
Live Demo: https://amirsaran3.github.io/guest-book-example/

With this the collapsible wallet explanation and a custom description will be shown like in the below pic:
explanation

Add Support For Unit Testing

Description

This project is currently lacking ways for changes to be validated. We need a unit testing solution that can inspect functionality in various ways to ensure we don’t:

  • Cause regressions as we make further enhancements.
  • Validate new features are working as intended (as described in task Acceptance Criteria)

My proposed solution, given we’re using React, is to implement Jest coupled with React Testing Library. These frameworks will provide a foundation for us to move quickly without compromising on quality.

As common practice, we will add Jest to the “test” NPM script. In the future we can look at integrating this command with GitHub Actions to ensure pull requests are in a working state before reviews take place.

Acceptance Criteria

  • Jest and React Testing Library are added to the devDependencies list in the package.json
  • test NPM script in the package.json file maps to the Jest CLI command (correctly configured with a Jest config file).
  • A basic test that simply renders the Modal component passes.

As a dApp user, I WANT to be able to choose the appropriate derivation path shown in the modal SO THAT I can select my Ledger device from the browser pop up AND initiate the connection to that physical device

Acceptance criteria

GIVEN that I access dApp and I have Ledger device connected
WHEN I choose the appropriate derivation path from the modal
THEN the browser pop up is shown with the list of available devices
AND I choose the Ledger device from the list
AND the connection to that physical device is initiated

Encapsulate DOM Mutations in React

Description

As mentioned in #54, we need to move away from mutating the DOM directly, particularly elements owned by React. When React mounts to a given target, it must be the sole owner of the HTML node (and child nodes it contains). This is because in order for React to make necessary changes, it needs to have a representation of what the DOM looks like currently and what the next render should look like. The difference between these two states is what React then batches up into efficient DOM operations. When we directly modify these elements outside of React (in the case of ModalHelper this is, for example, when we change the style of elements), it no longer has a consistent model of what the actual DOM looks like to what it has in memory (Virtual DOM).

Ignoring the bugs that come with this approach, it is also confusing for the project as a whole. We should be able to make the assumption that everything related to the UI is in the React realm and not managed by multiple sources.

My proposed solution is to move away from the ModalHelper entirely and either make a containing React component in its place and/or migrate some of the functionality directly into the Modal component.

Acceptance Criteria

  • Direct DOM mutations are removed from the project in favour of using React. This is usually achieved by introducing state of some kind.
  • Creation of the modal element is moved into the NearWalletSelector.

Add a collapsible section to the modal UI

Related to user story #2

Add an animated collapsible (slide down) section to the modal with the general description of what is a wallet and what are different types of wallets.

Description to add:

"Wallets are used to send, receive, and store digital assets. There are different types of wallets. They can be an extension added to your browser, a hardware device plugged into your computer, web-based, or as an app on your phone."

Text within Modal is not visible when system is using dark mode with 'light' theme

Description

When the modal is launched with the "theme": "light" configuration, I'm unable to see the text. It seems the text matches the background colour.

Steps to Reproduce

  1. Configure system/browser to use dark mode.
  2. Configure initialisation options to use the 'light' theme.
  3. Launch modal
  4. Observe 'invisible' text.

Acceptance Criteria

  • Text is clear and visible in any of the following scenarios:
    • Dark mode with 'light' theme.
    • Dark mode with 'dark' theme.
    • Light mode with 'light' theme.
    • Light mode with 'dark' theme.

Create basic, extendable system for various wallet types

As we discussed in our calls, we can model the architecture of OnboardJS and Web3Modal to create a modal pop-up that displays different available NEAR wallets for the end user to choose. The user will then interact with this wallet unless they choose to "deconnect" the wallet, in which has the modal would pop up again when prompted.

The three types of wallets we can start with are:

  1. URL Redirect (like NEAR Wallet or the NEAR Wallet for testnet)
  2. Hardware wallet (We currently support Ledger. More info on this in our main documentation.)
  3. Browser extension (SenderWallet and keep in mind the Opera wallet that's coming, and potentially NarWallets)

Please watch this video that's a cursory review of how OnboardJS is likely the better option to take inspiration from:
https://youtu.be/8pDf_PaxdpY

PS: This is worth a look, to see how another potential web-based wallet may join the ecosystem with a pop-up.
https://youtu.be/AlMlYajqCzM?t=488

Update project's README.md file

Final update to README.md file should contain:

  • introduction with a summary paragraph that describes the project at a high level

  • simple installation and usage instructions

  • a preview of project features with a demo GIF or screenshots

  • a list of the functions that will be included in the package (this should be a 1-2 sentence description for each function)

  • added license (a short description of the license)

Switch network message

Detect if the user needs to switch wallet provider network if it's not matching the network of dApp and show an appropriate message.

Add an option for the user to switch to a different wallet provider if their selected wallet provider doesn't support changing networks.

Example:
Screen Shot 2022-01-05 at 3 59 14 PM

Add switch wallet provider functionality

Have a function that will be called to open a modal again for the user to switch from already selected to a different wallet provider.

Check to see if the wallet provider that the user is selecting is the same as the current one so that it won't instantiate twice.

Show already selected wallet option in the modal. Example:
Screen Shot 2021-12-29 at 3 41 06 PM

Go through Ledger (hardware wallet) documentation

Migrate Wallet State Into React

Description

I’ve noticed a few major problems with the implementation of state in this project. The main source of state is stored in a “global” (if we ignore the require cache) module here. The problem with this approach is React doesn’t own this object so it’s unable to respond to changes made to it. This leads to inconsistencies in the view layer and the underlying state model.

My proposed solution is to migrate this state object into the React realm either by using a store pattern (using context) or multiple useState hooks directly in a persistently mounted top-level component.

Before this work can commence, we need to address another design problem I’ve identified in the ModalHelper module here. This module needs to move away from modifying DOM elements directly - this is the job of React and can be done more effectively this way. The visibility of the modal and particular sections would become useState variables within the component(s). See #56 for more detail.

Acceptance Criteria

  • Changes to state are immediately reflected in the UI.
  • State is no longer global. This will technically mean new instances of the wallet selector are encapsulated. However, the idea of multiple wallet selectors needs to be addressed in another ticket - this should not be possible(?).
  • References to local storage values should be removed from state. Currently values such as isSignedIn and signedInwalletId are only evaluated when the module is first imported (when NearWalletSelector is imported). Logic that relies on this will be susceptible to out-of-date values which ultimately cause bugs in the long run.

Error handling for Ledger wallet provider option

Related to user stories #23 and #24

After selecting the appropriate derivation path to connect if Ledger wallet device is not found and selected from the browser pop up, display error message "Error connecting to Ledger wallet".

Example:
Screen Shot 2021-12-23 at 1 52 13 PM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.