rudimentary search
This commit is contained in:
parent
79d0c2f928
commit
cf3eb52033
@ -232,10 +232,15 @@ walletCli
|
|||||||
});
|
});
|
||||||
|
|
||||||
walletCli
|
walletCli
|
||||||
.subcommand("", "transactions", { help: "Show transactions." })
|
.subcommand("transactions", "transactions", { help: "Show transactions." })
|
||||||
|
.maybeOption("currency", ["--currency"], clk.STRING)
|
||||||
|
.maybeOption("search", ["--search"], clk.STRING)
|
||||||
.action(async (args) => {
|
.action(async (args) => {
|
||||||
await withWallet(args, async (wallet) => {
|
await withWallet(args, async (wallet) => {
|
||||||
const pending = await wallet.getTransactions({});
|
const pending = await wallet.getTransactions({
|
||||||
|
currency: args.transactions.currency,
|
||||||
|
search: args.transactions.search,
|
||||||
|
});
|
||||||
console.log(JSON.stringify(pending, undefined, 2));
|
console.log(JSON.stringify(pending, undefined, 2));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -75,10 +75,8 @@ function getRefundStats(
|
|||||||
Amounts.parseOrThrow(perm.refund_fee),
|
Amounts.parseOrThrow(perm.refund_fee),
|
||||||
).amount;
|
).amount;
|
||||||
if (pr.refundsRefreshCost[rk]) {
|
if (pr.refundsRefreshCost[rk]) {
|
||||||
amountEffective = Amounts.sub(
|
amountEffective = Amounts.sub(amountEffective, pr.refundsRefreshCost[rk])
|
||||||
amountEffective,
|
.amount;
|
||||||
pr.refundsRefreshCost[rk],
|
|
||||||
).amount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,6 +98,32 @@ function getRefundStats(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shouldSkipCurrency(
|
||||||
|
transactionsRequest: TransactionsRequest | undefined,
|
||||||
|
currency: string,
|
||||||
|
): boolean {
|
||||||
|
if (!transactionsRequest?.currency) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return transactionsRequest.currency.toLowerCase() !== currency.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldSkipSearch(
|
||||||
|
transactionsRequest: TransactionsRequest | undefined,
|
||||||
|
fields: string[],
|
||||||
|
): boolean {
|
||||||
|
if (!transactionsRequest?.search) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const needle = transactionsRequest.search.trim();
|
||||||
|
for (const f of fields) {
|
||||||
|
if (f.indexOf(needle) >= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrive the full event history for this wallet.
|
* Retrive the full event history for this wallet.
|
||||||
*/
|
*/
|
||||||
@ -130,16 +154,26 @@ export async function getTransactions(
|
|||||||
async (tx) => {
|
async (tx) => {
|
||||||
tx.iter(Stores.withdrawalGroups).forEach((wsr) => {
|
tx.iter(Stores.withdrawalGroups).forEach((wsr) => {
|
||||||
if (
|
if (
|
||||||
transactionsRequest?.currency &&
|
shouldSkipCurrency(
|
||||||
wsr.rawWithdrawalAmount.currency != transactionsRequest.currency
|
transactionsRequest,
|
||||||
|
wsr.rawWithdrawalAmount.currency,
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shouldSkipSearch(transactionsRequest, [])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transactionsRequest?.search)
|
||||||
if (wsr.rawWithdrawalAmount.currency)
|
if (wsr.rawWithdrawalAmount.currency)
|
||||||
if (wsr.timestampFinish) {
|
if (wsr.timestampFinish) {
|
||||||
transactions.push({
|
transactions.push({
|
||||||
type: TransactionType.Withdrawal,
|
type: TransactionType.Withdrawal,
|
||||||
amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue),
|
amountEffective: Amounts.stringify(
|
||||||
|
wsr.denomsSel.totalCoinValue,
|
||||||
|
),
|
||||||
amountRaw: Amounts.stringify(wsr.denomsSel.totalWithdrawCost),
|
amountRaw: Amounts.stringify(wsr.denomsSel.totalWithdrawCost),
|
||||||
confirmed: true,
|
confirmed: true,
|
||||||
exchangeBaseUrl: wsr.exchangeBaseUrl,
|
exchangeBaseUrl: wsr.exchangeBaseUrl,
|
||||||
@ -154,10 +188,10 @@ export async function getTransactions(
|
|||||||
});
|
});
|
||||||
|
|
||||||
tx.iter(Stores.reserves).forEach((r) => {
|
tx.iter(Stores.reserves).forEach((r) => {
|
||||||
if (
|
if (shouldSkipCurrency(transactionsRequest, r.currency)) {
|
||||||
transactionsRequest?.currency &&
|
return;
|
||||||
r.currency != transactionsRequest.currency
|
}
|
||||||
) {
|
if (shouldSkipSearch(transactionsRequest, [])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (r.reserveStatus !== ReserveRecordStatus.WAIT_CONFIRM_BANK) {
|
if (r.reserveStatus !== ReserveRecordStatus.WAIT_CONFIRM_BANK) {
|
||||||
@ -170,7 +204,9 @@ export async function getTransactions(
|
|||||||
type: TransactionType.Withdrawal,
|
type: TransactionType.Withdrawal,
|
||||||
confirmed: false,
|
confirmed: false,
|
||||||
amountRaw: Amounts.stringify(r.bankInfo.denomSel.totalWithdrawCost),
|
amountRaw: Amounts.stringify(r.bankInfo.denomSel.totalWithdrawCost),
|
||||||
amountEffective: Amounts.stringify(r.bankInfo.denomSel.totalCoinValue),
|
amountEffective: Amounts.stringify(
|
||||||
|
r.bankInfo.denomSel.totalCoinValue,
|
||||||
|
),
|
||||||
exchangeBaseUrl: r.exchangeBaseUrl,
|
exchangeBaseUrl: r.exchangeBaseUrl,
|
||||||
pending: true,
|
pending: true,
|
||||||
timestamp: r.timestampCreated,
|
timestamp: r.timestampCreated,
|
||||||
@ -184,11 +220,16 @@ export async function getTransactions(
|
|||||||
|
|
||||||
tx.iter(Stores.purchases).forEachAsync(async (pr) => {
|
tx.iter(Stores.purchases).forEachAsync(async (pr) => {
|
||||||
if (
|
if (
|
||||||
transactionsRequest?.currency &&
|
shouldSkipCurrency(
|
||||||
pr.contractData.amount.currency != transactionsRequest.currency
|
transactionsRequest,
|
||||||
|
pr.contractData.amount.currency,
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (shouldSkipSearch(transactionsRequest, [pr.contractData.summary])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const proposal = await tx.get(Stores.proposals, pr.proposalId);
|
const proposal = await tx.get(Stores.proposals, pr.proposalId);
|
||||||
if (!proposal) {
|
if (!proposal) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user