@ethersproject/strings#parseBytes32String TypeScript Examples

The following examples show how to use @ethersproject/strings#parseBytes32String. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: data.ts    From hypertext with GNU General Public License v3.0 6 votes vote down vote up
function getOnchainToken(
  contract: Contract,
  contractBytes32: Contract
): (chainId: number, address: string) => Promise<Token | null> {
  return async (chainId: number, address: string): Promise<Token | null> => {
    const [decimals, symbol, name] = await Promise.all([
      contract.decimals().catch(() => null),
      contract.symbol().catch(() =>
        contractBytes32
          .symbol()
          .then(parseBytes32String)
          .catch(() => 'UNKNOWN')
      ),
      contract.name().catch(() =>
        contractBytes32
          .name()
          .then(parseBytes32String)
          .catch(() => 'Unknown')
      ),
    ])
    return decimals === null ? null : new Token(chainId, address, decimals, symbol, name)
  }
}
Example #2
Source File: Tokens.ts    From interface-v2 with GNU General Public License v3.0 6 votes vote down vote up
function parseStringOrBytes32(
  str: string | undefined,
  bytes32: string | undefined,
  defaultValue: string,
): string {
  return str && str.length > 0
    ? str
    : bytes32 && BYTES32_REGEX.test(bytes32)
    ? parseBytes32String(bytes32)
    : defaultValue;
}
Example #3
Source File: Tokens.ts    From limit-orders-lib with GNU General Public License v3.0 6 votes vote down vote up
function parseStringOrBytes32(
  str: string | undefined,
  bytes32: string | undefined,
  defaultValue: string
): string {
  return str && str.length > 0
    ? str
    : // need to check for proper bytes string and valid terminator
    bytes32 && BYTES32_REGEX.test(bytes32) && arrayify(bytes32)[31] === 0
    ? parseBytes32String(bytes32)
    : defaultValue;
}
Example #4
Source File: Tokens.ts    From cuiswap with GNU General Public License v3.0 5 votes vote down vote up
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
  return str && str.length > 0
    ? str
    : bytes32 && BYTES32_REGEX.test(bytes32)
    ? parseBytes32String(bytes32)
    : defaultValue
}
Example #5
Source File: Tokens.ts    From sybil-interface with GNU General Public License v3.0 5 votes vote down vote up
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
  return str && str.length > 0
    ? str
    : bytes32 && BYTES32_REGEX.test(bytes32)
    ? parseBytes32String(bytes32)
    : defaultValue
}
Example #6
Source File: Tokens.ts    From cheeseswap-interface with GNU General Public License v3.0 5 votes vote down vote up
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
  return str && str.length > 0
    ? str
    : bytes32 && BYTES32_REGEX.test(bytes32)
    ? parseBytes32String(bytes32)
    : defaultValue
}
Example #7
Source File: Tokens.ts    From dyp with Do What The F*ck You Want To Public License 5 votes vote down vote up
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
  return str && str.length > 0
    ? str
    : bytes32 && BYTES32_REGEX.test(bytes32)
    ? parseBytes32String(bytes32)
    : defaultValue
}
Example #8
Source File: Tokens.ts    From glide-frontend with GNU General Public License v3.0 5 votes vote down vote up
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
  return str && str.length > 0
    ? str
    : // need to check for proper bytes string and valid terminator
    bytes32 && BYTES32_REGEX.test(bytes32) && arrayify(bytes32)[31] === 0
    ? parseBytes32String(bytes32)
    : defaultValue
}
Example #9
Source File: Tokens.ts    From goose-frontend-amm with GNU General Public License v3.0 5 votes vote down vote up
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
  return str && str.length > 0
    ? str
    : bytes32 && BYTES32_REGEX.test(bytes32)
    ? parseBytes32String(bytes32)
    : defaultValue
}
Example #10
Source File: Tokens.ts    From mozartfinance-swap-interface with GNU General Public License v3.0 5 votes vote down vote up
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
  return str && str.length > 0
    ? str
    : bytes32 && BYTES32_REGEX.test(bytes32)
    ? parseBytes32String(bytes32)
    : defaultValue
}
Example #11
Source File: Tokens.ts    From pancake-swap-exchange-testnet with GNU General Public License v3.0 5 votes vote down vote up
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
  return str && str.length > 0
    ? str
    : bytes32 && BYTES32_REGEX.test(bytes32)
    ? parseBytes32String(bytes32)
    : defaultValue
}
Example #12
Source File: Tokens.ts    From panther-frontend-dex with GNU General Public License v3.0 5 votes vote down vote up
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
  return str && str.length > 0
    ? str
    : bytes32 && BYTES32_REGEX.test(bytes32)
    ? parseBytes32String(bytes32)
    : defaultValue
}
Example #13
Source File: Tokens.ts    From forward.swaps with GNU General Public License v3.0 5 votes vote down vote up
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
  return str && str.length > 0
    ? str
    : // need to check for proper bytes string and valid terminator
    bytes32 && BYTES32_REGEX.test(bytes32) && arrayify(bytes32)[31] === 0
    ? parseBytes32String(bytes32)
    : defaultValue
}
Example #14
Source File: Tokens.ts    From luaswap-interface with GNU General Public License v3.0 5 votes vote down vote up
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
  return str && str.length > 0
    ? str
    : bytes32 && BYTES32_REGEX.test(bytes32)
    ? parseBytes32String(bytes32)
    : defaultValue
}
Example #15
Source File: Tokens.ts    From vvs-ui with GNU General Public License v3.0 5 votes vote down vote up
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
  return str && str.length > 0
    ? str
    : // need to check for proper bytes string and valid terminator
    bytes32 && BYTES32_REGEX.test(bytes32) && arrayify(bytes32)[31] === 0
    ? parseBytes32String(bytes32)
    : defaultValue
}
Example #16
Source File: Tokens.ts    From pancakeswap-testnet with GNU General Public License v3.0 5 votes vote down vote up
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
  return str && str.length > 0
    ? str
    : bytes32 && BYTES32_REGEX.test(bytes32)
    ? parseBytes32String(bytes32)
    : defaultValue
}