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 🙏

© 2026 – Pkg Stats / Ryan Hefner

dodo-wallet

v1.1.8

Published

# 使用(可参照 example)

Readme

dodo-web 项目抽出来的钱包模块,意图独立钱包相关的逻辑,方便维护升级,也希望可以在将来的其他项目中直接引用,目前是 Init 版本,仅规范了一些用法和一部分监听逻辑

使用(可参照 example)

初始化

import { initWallet, WalletReducer } from 'dodo-wallet';
import { createStore, combineReducers, compose, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import mixpanel from 'mixpanel-browser';
import { enUS as walletEnUS, zhCN as walletZhCN } from 'dodo-wallet';

mixpanel.init('8b3e8750fd267914f7911af086a5e5d7');

// ... 处理多语言

const store = createStore(combineReducers(WalletReducer), undefined, compose(applyMiddleware(thunkMiddleware)));
initWallet({
  walletConfig: {
    ETH_NETWORK: 'mainnet',
    PORTIS_ID: 'portis',
  },
  customChainConfig: {},
  projectStore: store,
  projectMixpanel: mixpanel,
});

initWallet 初始化一些环境变量级别的配置和项目本身的 Store,参数说明:

walletConfig: {
  ETH_NETWORK, // 初始化web3Modal以及指定默认ChainId
  PORTIS_ID    // 初始化Portis
}
customChainConfig // 选填,自定义配置,目前支持multicallAddr字段,用于打包RPC查询请求
store // 项目的Store,WalletReducer在项目初始化store的时候要放到Reducers里,```state.dodoWallet```就是钱包的reducer

API

Hooks

useDODOWallet(); // 自动连接浏览器插件钱包,监听TokenList变化和ProxyAddress变化加载TokenList的Balance和Allowance
useBlockNumberTimer(); // 轮询区块高度,每13秒查询一次
useBalancesTimer(); // 轮询ETH余额,每13秒查询一次

Actions,举例两个特殊的 Action,setTokens setProxyAddress,他们除了更新 Reducer 数据外,还会触发一些其他的逻辑。使用useDODOWallet()时,初始 Store 里的 Tokens 和 ProxyAddress 是undefined,当 Tokens 和 ProxyAddress 发生改变时会去查询 Balance 和 Allowance,意味着只要有 TokenList,并且连接钱包成功获取到钱包地址,那么就会去加载一次全部 Token 的 Balance,同时如果存在 ProxyAddress,那么就会加载一次全部的 Allowance。这里没有轮询的逻辑,如果需要更新数据则需要手动执行loadTokenBalancesloadTokenAllowances

Selectors,如果是一次性的查询,可以直接用getCurrentAccount()方法获取到当前连接到的钱包地址,如果需要 Hooks 监听状态变化,则可以使用useSelector(getCurrentAccount)

web3,定义了一些 web3 方法,如connectToWallet连接钱包。也可以通过getWeb3()来直接获取一个 web3 实例。

开发流程

根目录执行yarn安装依赖和本地打包 package 文件

建立本地 package 软链接

yarn link

进入到example/路径或 dodo-web 项目下

alias 不能使用不同依赖的包

yarn link dodo-wallet 后,dodo-wallet 下的文件会使用最近一层的 node_modules,外部的文件使用自身项目的 node_modules 。导致两者不唯一。使用 alias ,确保使用的是同一个包.

// config-overrides.js (for create-react-app)
const path = require('path');
const {
  override,
  addWebpackAlias,
} = require('customize-cra');

const webpackAlias = {
  src: path.resolve(__dirname, 'src'),
};
if (process.env.NODE_ENV !== 'production') {
  // avoid Link leading to depends on errors
  const reactLinkPackages = [
    'react',
    'react-dom',
    'react-router-dom',
    'react-redux',
    'styled-components',
    'react-i18next',
    'redux',
  ];
  reactLinkPackages.forEach((pkg) => {
    webpackAlias[pkg] = path.resolve(__dirname, `node_modules/${pkg}`);
  });
}

const overrides = [
  addWebpackAlias(webpackAlias)
];

module.exports = override(...overrides);

执行

yarn
yarn link dodo-wallet
yarn run start

运行 example,默认写了 3000 端口,浏览器打开页面进行调试

Add new chain

  • chainConfig.ts
  • wallet.ts registerArbitrumNetworkWithMetamask()
  • src/components/images/networks-logo/CHAIN.svg
  • NetworkMismatchDialog.ts registerMap
  • WalletsPage.ts Network networkKeyMap networkMatchChainNameMap chainLogoMap list handleChange
  • utils/wallet.ts getChainIdWithNetworkName getNetworkNameWithChainId isETHOrBSCChain ChainType getChainType validNetworkList