@rainbow-me/kit-utils
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -1,2 +0,13 @@ | ||
export declare function isAddress(value: any): string | false; | ||
/** | ||
* Check an Ethereum address for validity | ||
* @param address blockchain address | ||
* @returns original address or "false" | ||
*/ | ||
export declare function isAddress(value: string): string | false; | ||
/** | ||
* Shortens an Ethereum address by N characters | ||
* @param address blockchain address | ||
* @param chars amount of character t shorten | ||
* @returns formatted string | ||
*/ | ||
export declare function shortenAddress(address: string, chars?: number): string; |
@@ -1,4 +0,14 @@ | ||
export declare const connectorByWallet: (name: string) => "Injected" | "WalletLink" | "Frame" | "Torus" | "WalletConnect"; | ||
export declare const walletByConnector: (connector: string) => "metamask" | "coinbase" | "torus" | "walletconnect"; | ||
export declare const chainNametoID: (name: string) => number; | ||
/** | ||
* Finds a connector name by wallet name | ||
* @param wallet wallet name | ||
* @returns connector name | ||
*/ | ||
export declare const connectorByWallet: (wallet: string) => "Injected" | "WalletLink" | "Frame" | "WalletConnect"; | ||
/** | ||
* Finds a wallet name by connector name | ||
* @param connector connect name | ||
* @returns wallet name | ||
*/ | ||
export declare const walletByConnector: (connector: string) => "metamask" | "walletlink" | "frame" | "walletconnect"; | ||
export declare const chainNametoId: (name: string) => number; | ||
export declare const chainIdToName: (id: number) => string; | ||
@@ -5,0 +15,0 @@ export declare const chainIdToAlias: (id: number) => string; |
@@ -506,3 +506,3 @@ import React from 'react'; | ||
chainId: 43113, | ||
aliases: ['avax testnet', 'avalanche testnet', 'avax fuji', 'avalanche fuji'] | ||
aliases: ['avax testnet', 'avalanche testnet', 'avax fuji', 'avalanche fuji', 'fuji', 'fuji testnet'] | ||
}, | ||
@@ -569,4 +569,9 @@ { | ||
const connectorByWallet = (name) => { | ||
switch (name) { | ||
/** | ||
* Finds a connector name by wallet name | ||
* @param wallet wallet name | ||
* @returns connector name | ||
*/ | ||
const connectorByWallet = (wallet) => { | ||
switch (wallet) { | ||
case 'metamask': | ||
@@ -579,9 +584,13 @@ return 'Injected'; | ||
return 'Frame'; | ||
case 'torus': | ||
return 'Torus'; | ||
case 'walletconnect': | ||
case 'rainbow': | ||
case 'argent': | ||
return 'WalletConnect'; | ||
} | ||
}; | ||
/** | ||
* Finds a wallet name by connector name | ||
* @param connector connect name | ||
* @returns wallet name | ||
*/ | ||
const walletByConnector = (connector) => { | ||
@@ -592,10 +601,10 @@ switch (connector) { | ||
case 'WalletLinkConnector': | ||
return 'coinbase'; | ||
case 'TorusConnector': | ||
return 'torus'; | ||
return 'walletlink'; | ||
case 'WalletConnectConnector': | ||
return 'walletconnect'; | ||
case 'FrameConnector': | ||
return 'frame'; | ||
} | ||
}; | ||
const chainNametoID = (name) => { var _a; return ((_a = chains.find((chain) => chain.aliases.includes(name))) === null || _a === void 0 ? void 0 : _a.chainId) || 1; }; | ||
const chainNametoId = (name) => { var _a; return ((_a = chains.find((chain) => chain.aliases.includes(name))) === null || _a === void 0 ? void 0 : _a.chainId) || 1; }; | ||
const chainIdToName = (id) => { var _a; return ((_a = chains.find((chain) => chain.chainId === id)) === null || _a === void 0 ? void 0 : _a.name) || 'Ethereum'; }; | ||
@@ -612,2 +621,7 @@ const chainIdToAlias = (id) => { var _a; return ((_a = chains.find((chain) => chain.chainId === id)) === null || _a === void 0 ? void 0 : _a.aliases[0]) || 'ethereum'; }; | ||
/** | ||
* Check an Ethereum address for validity | ||
* @param address blockchain address | ||
* @returns original address or "false" | ||
*/ | ||
function isAddress(value) { | ||
@@ -621,7 +635,12 @@ try { | ||
} | ||
/** | ||
* Shortens an Ethereum address by N characters | ||
* @param address blockchain address | ||
* @param chars amount of character t shorten | ||
* @returns formatted string | ||
*/ | ||
function shortenAddress(address, chars = 4) { | ||
const parsed = isAddress(address); | ||
if (!parsed) { | ||
if (!parsed) | ||
throw Error(`Invalid 'address' parameter '${address}'.`); | ||
} | ||
return `${parsed.substring(0, chars + 2)}...${parsed.substring(42 - chars)}`; | ||
@@ -811,7 +830,7 @@ } | ||
function hashCode(text) { | ||
let hash = 0, i, chr; | ||
let hash = 0; | ||
if (text.length === 0) | ||
return hash; | ||
for (i = 0; i < text.length; i++) { | ||
chr = text.charCodeAt(i); | ||
for (let i = 0; i < text.length; i++) { | ||
const chr = text.charCodeAt(i); | ||
hash = (hash << 5) - hash + chr; | ||
@@ -841,5 +860,4 @@ hash |= 0; | ||
return 0; | ||
if (colors.includes(colorHex)) { | ||
if (colors.includes(colorHex)) | ||
return colors.indexOf(colorHex); | ||
} | ||
return 0; | ||
@@ -862,2 +880,2 @@ } | ||
export { ChainId, addressHashedColorIndex, addressHashedEmoji, addressHashedIndex, avatarColor, avatars, chainIDToExplorer, chainIDToToken, chainIdToAlias, chainIdToName, chainNametoID, chains, colorHexToIndex, colors, connectorByWallet, emojiColorIndexes, etherscanFetcher, getWalletInfo, guessTitle, hashCode, isAddress, isAuthorized, logsFetcher, popularEmojis, resolveAddress, setupProvider, shortenAddress, switchNetwork, toSignificant, walletByConnector, walletConnectRPCs, withWeb3React }; | ||
export { ChainId, addressHashedColorIndex, addressHashedEmoji, addressHashedIndex, avatarColor, avatars, chainIDToExplorer, chainIDToToken, chainIdToAlias, chainIdToName, chainNametoId, chains, colorHexToIndex, colors, connectorByWallet, emojiColorIndexes, etherscanFetcher, getWalletInfo, guessTitle, hashCode, isAddress, isAuthorized, logsFetcher, popularEmojis, resolveAddress, setupProvider, shortenAddress, switchNetwork, toSignificant, walletByConnector, walletConnectRPCs, withWeb3React }; |
{ | ||
"name": "@rainbow-me/kit-utils", | ||
"type": "module", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"exports": "./dist/index.js", | ||
@@ -6,0 +6,0 @@ "types": "./dist/index.d.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40628
1056