aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-11-28 00:46:34 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-11-28 00:46:34 +0100
commit706c07fa1d069290992bd31d53b0c89324992f9c (patch)
tree8114c23cda7547f8475c7d8d579f51f968a97f9d /src/wallet.ts
parentc3ca556affe2f514aeb7fd052fe6d626d9319e99 (diff)
implement JS-only Taler, remove emscripten
Diffstat (limited to 'src/wallet.ts')
-rw-r--r--src/wallet.ts37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/wallet.ts b/src/wallet.ts
index 58bb6b8c3..f1d7be5e5 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -30,6 +30,7 @@ import {
getTalerStampSec,
strcmp,
extractTalerStamp,
+ extractTalerStampOrThrow,
} from "./helpers";
import { HttpRequestLibrary } from "./http";
import * as LibtoolVersion from "./libtoolVersion";
@@ -163,20 +164,10 @@ const builtinCurrencies: CurrencyRecord[] = [
];
function isWithdrawableDenom(d: DenominationRecord) {
- const nowSec = new Date().getTime() / 1000;
- const stampWithdrawSec = getTalerStampSec(d.stampExpireWithdraw);
- if (stampWithdrawSec === null) {
- return false;
- }
- const stampStartSec = getTalerStampSec(d.stampStart);
- if (stampStartSec === null) {
- return false;
- }
- // Withdraw if still possible to withdraw within a minute
- if (stampWithdrawSec + 60 > nowSec && nowSec >= stampStartSec) {
- return true;
- }
- return false;
+ const now = getTimestampNow();
+ const started = now.t_ms >= d.stampStart.t_ms;
+ const stillOkay = d.stampExpireWithdraw.t_ms + (60 * 1000) > now.t_ms;
+ return started && stillOkay;
}
interface SelectPayCoinsResult {
@@ -1374,6 +1365,7 @@ export class Wallet {
denom.feeWithdraw,
);
if (x.saturated) {
+ // FIXME!!!!
console.error("database inconsistent");
throw TransactionAbort;
}
@@ -1891,10 +1883,10 @@ export class Wallet {
const { isTrusted, isAudited } = await this.getExchangeTrust(exchangeInfo);
- let earliestDepositExpiration = Infinity;
- for (const denom of selectedDenoms) {
- const expireDeposit = getTalerStampSec(denom.stampExpireDeposit)!;
- if (expireDeposit < earliestDepositExpiration) {
+ let earliestDepositExpiration = selectedDenoms[0].stampExpireDeposit;
+ for (let i = 1; i < selectedDenoms.length; i++) {
+ const expireDeposit = selectedDenoms[i].stampExpireDeposit;
+ if (expireDeposit.t_ms < earliestDepositExpiration.t_ms) {
earliestDepositExpiration = expireDeposit;
}
}
@@ -2653,6 +2645,7 @@ export class Wallet {
resp = await this.http.postJson(reqUrl.href(), req);
} catch (e) {
console.error("got error during /refresh/reveal request");
+ console.error(e);
return;
}
@@ -3137,10 +3130,10 @@ export class Wallet {
feeWithdraw: Amounts.parseOrThrow(denomIn.fee_withdraw),
isOffered: true,
masterSig: denomIn.master_sig,
- stampExpireDeposit: denomIn.stamp_expire_deposit,
- stampExpireLegal: denomIn.stamp_expire_legal,
- stampExpireWithdraw: denomIn.stamp_expire_withdraw,
- stampStart: denomIn.stamp_start,
+ stampExpireDeposit: extractTalerStampOrThrow(denomIn.stamp_expire_deposit),
+ stampExpireLegal: extractTalerStampOrThrow(denomIn.stamp_expire_legal),
+ stampExpireWithdraw: extractTalerStampOrThrow(denomIn.stamp_expire_withdraw),
+ stampStart: extractTalerStampOrThrow(denomIn.stamp_start),
status: DenominationStatus.Unverified,
value: Amounts.parseOrThrow(denomIn.value),
};