UNPKG

@funded-labs/dab-js

Version:
58 lines (57 loc) 2.7 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const methods_1 = require("./methods"); const getMetadata = (actor) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b; const metadata = yield actor._drc20_metadata(); const symbol = yield actor._drc20_symbol(); const decimals = yield actor._drc20_decimals(); const name = yield actor._drc20_name(); const fee = yield actor._drc20_fee(); const totalSupply = yield actor._drc20_totalSupply(); return { fungible: { symbol, decimals, name, logo: (_b = (_a = metadata.find((item) => (item === null || item === void 0 ? void 0 : item.name) === 'logo')) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.content, fee, totalSupply, }, }; }); const send = (actor, { to, amount }) => __awaiter(void 0, void 0, void 0, function* () { const transferResult = yield actor._drc20_transfer(to, amount, [], [], []); if ('ok' in transferResult) return { transactionId: transferResult.ok.toString() }; throw new Error(transferResult.err.message); }); const getBalance = (actor, user) => __awaiter(void 0, void 0, void 0, function* () { const decimals = yield getDecimals(actor); const value = (yield actor._drc20_balanceOf(user.toString())).toString(); return { value, decimals }; }); const burnXTC = (_actor, _params) => __awaiter(void 0, void 0, void 0, function* () { throw new Error('BURN NOT SUPPORTED'); }); const approve = (actor, params) => __awaiter(void 0, void 0, void 0, function* () { return actor._drc20_approve(params.spender.toString(), params.amount, [], [], []); }); const getDecimals = (actor) => __awaiter(void 0, void 0, void 0, function* () { return (0, methods_1.getDecimalsFromMetadata)(yield getMetadata(actor)); }); exports.default = { send, getMetadata, getBalance, burnXTC, getDecimals, approve, };