UNPKG

client-aftermath-ts-sdk

Version:
65 lines (64 loc) 3.01 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 }); exports.Wallet = void 0; const caller_1 = require("../utils/caller"); class Wallet extends caller_1.Caller { constructor(address, config, Provider) { super(config, `wallet/${address}`); this.address = address; this.Provider = Provider; // ========================================================================= // Private Helpers // ========================================================================= this.useProvider = () => { var _a; const provider = (_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Wallet(); if (!provider) throw new Error("missing AftermathApi Provider"); return provider; }; } // ========================================================================= // Balances // ========================================================================= getBalance(inputs) { return __awaiter(this, void 0, void 0, function* () { return this.useProvider().fetchCoinBalance(Object.assign(Object.assign({}, inputs), { walletAddress: this.address })); }); } // TODO: change return type to Record<Coin, Balance> ? getBalances(inputs) { return __awaiter(this, void 0, void 0, function* () { // const balances = await Promise.all( // inputs.coins.map((coin) => this.getBalance({ coin })) // ); // return balances; return this.fetchApi(`balances/coins`, inputs); }); } getAllBalances() { return __awaiter(this, void 0, void 0, function* () { return this.useProvider().fetchAllCoinBalances({ walletAddress: this.address, }); }); } // ========================================================================= // Transactions // ========================================================================= getPastTransactions(inputs) { return __awaiter(this, void 0, void 0, function* () { return this.useProvider().fetchPastTransactions(Object.assign(Object.assign({}, inputs), { walletAddress: this.address })); }); } } exports.Wallet = Wallet;