UNPKG

@bajetech/digitalbits-wallet-sdk

Version:

A library to make it easier to write wallets that interact with the DigitalBits blockchain

42 lines 1.48 kB
import { Asset } from "xdb-digitalbits-sdk"; import { NATIVE_ASSET_IDENTIFIER } from "../constants/digitalbits"; /** * Get the string identifier for a token. * @returns "native" if the token is native, otherwise returns * `${tokenCode}:${issuerKey}`. */ export function getTokenIdentifier(token) { if (token.type === NATIVE_ASSET_IDENTIFIER) { return NATIVE_ASSET_IDENTIFIER; } return "".concat(token.code, ":").concat(token.issuer.key); } /** * Get the string identifier for a balance line item from Frontier. The response * should be the same as if that balance was a Token object, and you passed it * through `getTokenIdentifier` * @returns Returns `${tokenCode}:${issuerKey}`. */ export function getBalanceIdentifier(balance) { if ("asset_issuer" in balance && !balance.asset_issuer) { return NATIVE_ASSET_IDENTIFIER; } switch (balance.asset_type) { case "credit_alphanum4": case "credit_alphanum12": return "".concat(balance.asset_code, ":").concat(balance.asset_issuer); default: return NATIVE_ASSET_IDENTIFIER; } } /** * Convert a Wallet-SDK-formatted Token object to a DigitalBits SDK Asset object. * @returns Returns `${tokenCode}:${issuerKey}`. */ export function getDigitalBitsSdkAsset(token) { if (token.type === NATIVE_ASSET_IDENTIFIER) { return Asset.native(); } return new Asset(token.code, token.issuer.key); } //# sourceMappingURL=index.js.map