simplify coin status, don't show refreshed coins in balance
This commit is contained in:
parent
ace1a1be34
commit
75cf7ac3c3
@ -24,7 +24,7 @@
|
||||
import * as native from "./emscriptif";
|
||||
import {
|
||||
PreCoinRecord, PayCoinInfo, AmountJson,
|
||||
RefreshSessionRecord, RefreshPreCoinRecord, ReserveRecord
|
||||
RefreshSessionRecord, RefreshPreCoinRecord, ReserveRecord, CoinStatus,
|
||||
} from "./types";
|
||||
import create = chrome.alarms.create;
|
||||
import {OfferRecord} from "./wallet";
|
||||
@ -210,8 +210,7 @@ namespace RpcFunctions {
|
||||
let newAmount = new native.Amount(cd.coin.currentAmount);
|
||||
newAmount.sub(coinSpend);
|
||||
cd.coin.currentAmount = newAmount.toJson();
|
||||
cd.coin.dirty = true;
|
||||
cd.coin.transactionPending = true;
|
||||
cd.coin.status = CoinStatus.TransactionPending;
|
||||
|
||||
let d = new native.DepositRequestPS({
|
||||
h_contract: native.HashCode.fromCrock(offer.H_contract),
|
||||
|
@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
|
||||
import {ExchangeRecord, DenominationRecord} from "src/types";
|
||||
import {ExchangeRecord, DenominationRecord, CoinStatus} from "src/types";
|
||||
import { ReserveRecord, CoinRecord, PreCoinRecord, Denomination } from "src/types";
|
||||
import { ImplicitStateComponent, StateHolder } from "src/components";
|
||||
import {
|
||||
@ -124,8 +124,7 @@ class CoinView extends React.Component<CoinViewProps, void> {
|
||||
<li>Current amount: {prettyAmount(c.currentAmount)}</li>
|
||||
<li>Denomination: <ExpanderText text={c.denomPub} /></li>
|
||||
<li>Suspended: {(c.suspended || false).toString()}</li>
|
||||
<li>Dirty: {(c.dirty || false).toString()}</li>
|
||||
<li>Transaction Pending: {(c.transactionPending || false).toString()}</li>
|
||||
<li>Status: {CoinStatus[c.status]}</li>
|
||||
<li><RefreshDialog coin={c} /></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
18
src/types.ts
18
src/types.ts
@ -347,6 +347,12 @@ export interface CoinPaySig {
|
||||
f: AmountJson;
|
||||
}
|
||||
|
||||
|
||||
export enum CoinStatus {
|
||||
Fresh, TransactionPending, Dirty, Refreshed,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* CoinRecord as stored in the "coins" data store
|
||||
* of the wallet database.
|
||||
@ -391,17 +397,9 @@ export interface CoinRecord {
|
||||
suspended?: boolean;
|
||||
|
||||
/**
|
||||
* Was the coin revealed in a transaction?
|
||||
* Status of the coin.
|
||||
*/
|
||||
dirty: boolean;
|
||||
|
||||
/**
|
||||
* Is the coin currently involved in a transaction?
|
||||
*
|
||||
* This delays refreshing until the transaction is finished or
|
||||
* aborted.
|
||||
*/
|
||||
transactionPending: boolean;
|
||||
status: CoinStatus;
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,6 +42,7 @@ import {
|
||||
WalletBalance,
|
||||
WalletBalanceEntry,
|
||||
WireInfo, DenominationRecord, DenominationStatus, denominationRecordFromKeys,
|
||||
CoinStatus,
|
||||
} from "./types";
|
||||
import {
|
||||
HttpRequestLibrary,
|
||||
@ -266,7 +267,7 @@ export function selectCoins(cds: CoinWithDenom[], paymentAmount: AmountJson,
|
||||
if (coin.suspended) {
|
||||
continue;
|
||||
}
|
||||
if (coin.dirty) {
|
||||
if (coin.status != CoinStatus.Fresh) {
|
||||
continue;
|
||||
}
|
||||
if (Amounts.cmp(denom.feeDeposit, coin.currentAmount) >= 0) {
|
||||
@ -526,7 +527,7 @@ export class Wallet {
|
||||
this.q()
|
||||
.iter(Stores.coins)
|
||||
.reduce((c: CoinRecord) => {
|
||||
if (c.dirty && !c.transactionPending && !(c.currentAmount.value == 0 && c.currentAmount.fraction == 0)) {
|
||||
if (c.status == CoinStatus.Dirty) {
|
||||
console.log("resuming pending refresh for coin", c);
|
||||
this.refresh(c.coinPub);
|
||||
}
|
||||
@ -581,10 +582,7 @@ export class Wallet {
|
||||
if (coin.suspended) {
|
||||
continue;
|
||||
}
|
||||
if (coin.dirty) {
|
||||
continue;
|
||||
}
|
||||
if (coin.transactionPending) {
|
||||
if (coin.status != CoinStatus.Fresh) {
|
||||
continue;
|
||||
}
|
||||
cds.push({coin, denom});
|
||||
@ -989,8 +987,7 @@ export class Wallet {
|
||||
denomSig: denomSig,
|
||||
currentAmount: pc.coinValue,
|
||||
exchangeBaseUrl: pc.exchangeBaseUrl,
|
||||
dirty: false,
|
||||
transactionPending: false,
|
||||
status: CoinStatus.Fresh,
|
||||
};
|
||||
return coin;
|
||||
}
|
||||
@ -1348,6 +1345,9 @@ export class Wallet {
|
||||
if (c.suspended) {
|
||||
return balance;
|
||||
}
|
||||
if (!(c.status == CoinStatus.Dirty || c.status == CoinStatus.Fresh)) {
|
||||
return balance;
|
||||
}
|
||||
let currency = c.currentAmount.currency;
|
||||
let entry = ensureEntry(balance, currency);
|
||||
entry.available = Amounts.add(entry.available, c.currentAmount).amount;
|
||||
@ -1496,6 +1496,7 @@ export class Wallet {
|
||||
throw AbortTransaction;
|
||||
}
|
||||
c.currentAmount = r.amount;
|
||||
c.status = CoinStatus.Refreshed;
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -1667,8 +1668,7 @@ export class Wallet {
|
||||
denomSig: denomSig,
|
||||
currentAmount: denom.value,
|
||||
exchangeBaseUrl: refreshSession.exchangeBaseUrl,
|
||||
dirty: false,
|
||||
transactionPending: false,
|
||||
status: CoinStatus.Fresh,
|
||||
};
|
||||
|
||||
coins.push(coin);
|
||||
@ -1787,7 +1787,7 @@ export class Wallet {
|
||||
console.error("coin not found");
|
||||
return;
|
||||
}
|
||||
c.transactionPending = false;
|
||||
c.status = CoinStatus.Dirty;
|
||||
modifiedCoins.push(c);
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ import * as logging from "./logging";
|
||||
"use strict";
|
||||
|
||||
const DB_NAME = "taler";
|
||||
const DB_VERSION = 15;
|
||||
const DB_VERSION = 16;
|
||||
|
||||
import {Stores} from "./wallet";
|
||||
import {Store, Index} from "./query";
|
||||
|
Loading…
Reference in New Issue
Block a user