@dahlia-labs/token-utils
Version:
Token-related math and transaction utilities.
81 lines • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.tokensEqual = exports.Token = void 0;
const celo_contrib_1 = require("@dahlia-labs/celo-contrib");
/**
* Token information.
*/
class Token {
constructor(info) {
var _a;
this.info = info;
this.network = (_a = (0, celo_contrib_1.chainIdToNetwork)(info.chainId)) !== null && _a !== void 0 ? _a : celo_contrib_1.Mainnet;
}
/**
* The Base58 string representation of the mint address.
*/
get address() {
return this.info.address;
}
/**
* The chain ID of the token.
*/
get chainId() {
return this.info.chainId;
}
/**
* Number of decimals of the token.
*/
get decimals() {
return this.info.decimals;
}
/**
* The name of the token.
*/
get name() {
return this.info.name;
}
/**
* The symbol of the token.
*/
get symbol() {
return this.info.symbol;
}
/**
* The token's icon to render.
*/
get icon() {
return this.info.logoURI;
}
equals(other) {
return (0, exports.tokensEqual)(this, other);
}
toString() {
return `Token[address=${this.address}, decimals=${this.decimals}, chainId=${this.chainId}]`;
}
toJSON() {
return this.info;
}
/**
* Returns true if the given tag is present.
* @param tag The tag to check.
* @returns
*/
hasTag(tag) {
var _a;
return !!((_a = this.info.tags) === null || _a === void 0 ? void 0 : _a.includes(tag));
}
}
exports.Token = Token;
/**
* Checks if two tokens are equal.
* @param a
* @param b
* @returns
*/
const tokensEqual = (a, b) => a !== undefined &&
b !== undefined &&
a.address === b.address &&
a.network === b.network;
exports.tokensEqual = tokensEqual;
//# sourceMappingURL=token.js.map