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