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

tech-mask-utils

v1.1.9

Published

Metamask extension functions: - networkSwitcher - addTokenToMetamask

Downloads

23

Readme

About

Metamask extension functions:

  • networkSwitcher
  • addTokenToMetamask

Common functions:

  • removeEFromNumber
  • setStyles
  • createNewWallet

Components:

  • NumericInput

Hooks:

  • useWeb3Contract

Installation

npm i tech-mask-utils or yarn add tech-mask-utils

Usage

To export the newly created function, you must write in index.ts: export {yourFunc} from '../../..'

To import some function or component: import {} from 'tech-mask-utils'

Metamask functions:

  • addTokenToMetamask(web3: any, tokenAddress: string, tokenSymbol?: string, tokenDecimals?: number) tokenSymbol and tokenDecimals is optional parameters
addTokenToMetamask(web3, '0xae13d989dac2f0debff460ac112a837c89baa7cd', 'BNB', 18)
  • networkSwitcher(web3, chainId: number)
networkSwitcher(web3, 56)

Common functions:

  • removeEFromNumber(number: number)
removeEFromNumber(0.2323e+18) => '232300000000000000'
  • createNewWallet() creates new web3 account and returns publicAddress and privateKey
const {publicAddress, privateKey} = createNewWallet()
  • setStyles(styles: object) uses for set styles to component. In example below this function set styles for input max button
const styles = {
  inputMaxButton: {
    background: '#fff',
    'border-radius': '20px'
  },
  'inputMaxButton:hover': {
    background: '#000'
  }
}

setStyles(styles)

Components:

  • <NumericInput/>

If onMax is passed to props, the component will render the max button

Prop types

value: string | number
onUserInput: (input: string) => void
placeholder?: string
onMax?: () => void
inputPadding?: string
inputWidth?: string
inputBackground?: string
inputBorderRadius?: string

Usage

import {NumericInput} from 'tech-mask-utils'

const App = () => {
  return (
    <>
     <NumericInput 
       value={value}
       onUserInput={setValue}
       onMax={onMax}
       placeholder={'enter your value'}
       // styling
       inputPadding={'10px'}
       inputWidth={'10px'}
       inputBackground={'10px'}
       inputBorderRadius={'10px'}
     />
    </>
  )
}

Hooks:

  • useWeb3Contract(contractInfoObject)

Returns chainId, web3 object with current provider and getContract() function

getContract(contractName: string) takes as its argument the name of the contract in uppercase to be returned

The argument object should be as in the example:

export const contractInfoObject = {
  1: {
    USDT: {
      address: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
      name: 'USDT',
      abi: usdtAbi
    }
  },
  56: {
    BUSD: {
      address: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56',
      name: 'BUSD',
      abi: busdAbi
    }
  }
}

Usage

import {useWeb3Contract} from 'tech-mask-utils'

const App = () => {
const {chainId, web3, getContract} = useWeb3Contract(contractInfoObject)
const contract = getContract('USDT')

  return (
    <></>
  )
}