client-aftermath-ts-sdk
Version:
Client Aftermath TypeScript SDK
67 lines (66 loc) • 3.5 kB
JavaScript
;
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.WalletApi = void 0;
const helpers_1 = require("../utils/helpers");
class WalletApi {
// =========================================================================
// Constructor
// =========================================================================
constructor(Provider) {
this.Provider = Provider;
// =========================================================================
// Fetching
// =========================================================================
// =========================================================================
// Coins
// =========================================================================
this.fetchCoinBalance = (inputs) => __awaiter(this, void 0, void 0, function* () {
const { walletAddress, coin } = inputs;
const coinBalance = yield this.Provider.provider.getBalance({
owner: walletAddress,
coinType: helpers_1.Helpers.stripLeadingZeroesFromType(coin),
});
return BigInt(coinBalance.totalBalance);
});
// TODO: make toBigIntSafe function ?
// TODO: return prices here as well and sort ?
this.fetchAllCoinBalances = (inputs) => __awaiter(this, void 0, void 0, function* () {
const { walletAddress } = inputs;
const allBalances = yield this.Provider.provider.getAllBalances({
owner: walletAddress,
});
const coinsToBalance = allBalances.reduce((acc, balance) => {
return Object.assign(Object.assign({}, acc), { [helpers_1.Helpers.addLeadingZeroesToType(balance.coinType)]: BigInt(balance.totalBalance) });
}, {});
return coinsToBalance;
});
// =========================================================================
// Transactions
// =========================================================================
// TODO: make this only look at aftermath relevant addresses in to address
// TODO: restrict all filtering for events, etc. similarly using updated sdk filters
this.fetchPastTransactions = (inputs) => __awaiter(this, void 0, void 0, function* () {
const { walletAddress, cursor, limit } = inputs;
const transactionsWithCursor = yield this.Provider.Transactions().fetchTransactionsWithCursor({
query: {
filter: {
FromAddress: walletAddress,
},
},
cursor,
limit,
});
return transactionsWithCursor;
});
}
}
exports.WalletApi = WalletApi;