Refactor wallet into logic and extension interface.
This commit is contained in:
parent
2f8aa00595
commit
abf15268ac
@ -41,6 +41,13 @@ namespace Checkable {
|
||||
return target;
|
||||
}
|
||||
|
||||
function checkAnyObject(target, prop): any {
|
||||
if (typeof target !== "object") {
|
||||
throw Error("object expected for " + prop.propertyKey);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
function checkValue(target, prop): any {
|
||||
let type = prop.type;
|
||||
if (!type) {
|
||||
@ -84,11 +91,7 @@ namespace Checkable {
|
||||
|
||||
export function Value(type) {
|
||||
function deco(target: Object, propertyKey: string | symbol): void {
|
||||
let chk = target[chkSym];
|
||||
if (!chk) {
|
||||
chk = {props: []};
|
||||
target[chkSym] = chk;
|
||||
}
|
||||
let chk = mkChk(target);
|
||||
chk.props.push({
|
||||
propertyKey: propertyKey,
|
||||
checker: checkValue,
|
||||
@ -108,20 +111,26 @@ namespace Checkable {
|
||||
}
|
||||
|
||||
export function Number(target: Object, propertyKey: string | symbol): void {
|
||||
let chk = target[chkSym];
|
||||
if (!chk) {
|
||||
chk = {props: []};
|
||||
target[chkSym] = chk;
|
||||
}
|
||||
let chk = mkChk(target);
|
||||
chk.props.push({propertyKey: propertyKey, checker: checkNumber});
|
||||
}
|
||||
|
||||
export function AnyObject(target: Object, propertyKey: string | symbol): void {
|
||||
let chk = mkChk(target);
|
||||
chk.props.push({propertyKey: propertyKey, checker: checkAnyObject});
|
||||
}
|
||||
|
||||
export function String(target: Object, propertyKey: string | symbol): void {
|
||||
let chk = mkChk(target);
|
||||
chk.props.push({propertyKey: propertyKey, checker: checkString});
|
||||
}
|
||||
|
||||
function mkChk(target) {
|
||||
let chk = target[chkSym];
|
||||
if (!chk) {
|
||||
chk = {props: []};
|
||||
target[chkSym] = chk;
|
||||
}
|
||||
chk.props.push({propertyKey: propertyKey, checker: checkString});
|
||||
return chk;
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ function openTalerDb() {
|
||||
coins.createIndex("mintBaseUrl", "mintBaseUrl");
|
||||
db.createObjectStore("transactions", { keyPath: "contractHash" });
|
||||
db.createObjectStore("precoins", { keyPath: "coinPub", autoIncrement: true });
|
||||
db.createObjectStore("history", { keyPath: "id", autoIncrement: true });
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
@ -67,11 +67,8 @@ namespace Db {
|
||||
currentAmount: AmountJson_interface;
|
||||
mintBaseUrl: string;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
const DB_NAME = "taler";
|
||||
const DB_VERSION = 1;
|
||||
|
||||
@ -102,6 +99,7 @@ function openTalerDb(): Promise<IDBDatabase> {
|
||||
db.createObjectStore("transactions", {keyPath: "contractHash"});
|
||||
db.createObjectStore("precoins",
|
||||
{keyPath: "coinPub", autoIncrement: true});
|
||||
db.createObjectStore("history", {keyPath: "id", autoIncrement: true});
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
@ -25,11 +25,10 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
// FIXME: none of these handlers should pass on the sendResponse.
|
||||
|
||||
let handlers = {
|
||||
function makeHandlers(wallet) {
|
||||
return {
|
||||
["balances"]: function(db, detail, sendResponse) {
|
||||
getBalances(db).then(sendResponse);
|
||||
wallet.getBalances().then(sendResponse);
|
||||
return true;
|
||||
},
|
||||
["dump-db"]: function(db, detail, sendResponse) {
|
||||
@ -48,22 +47,60 @@ let handlers = {
|
||||
return false;
|
||||
},
|
||||
["confirm-reserve"]: function(db, detail, sendResponse) {
|
||||
return confirmReserveHandler(db, detail, sendResponse);
|
||||
// TODO: make it a checkable
|
||||
let req: ConfirmReserveRequest = {
|
||||
field_amount: detail.field_amount,
|
||||
field_mint: detail.field_mint,
|
||||
field_reserve_pub: detail.field_reserve_pub,
|
||||
post_url: detail.post_url,
|
||||
mint: detail.mint,
|
||||
amount_str: detail.amount_str
|
||||
};
|
||||
wallet.confirmReserve(req)
|
||||
.then((resp) => {
|
||||
if (resp.success) {
|
||||
resp.backlink = chrome.extension.getURL("pages/reserve-success.html");
|
||||
}
|
||||
sendResponse(resp);
|
||||
});
|
||||
return true;
|
||||
},
|
||||
["confirm-pay"]: function(db, detail, sendResponse) {
|
||||
return confirmPayHandler(db, detail, sendResponse);
|
||||
wallet.confirmPay(detail.offer, detail.merchantPageUrl)
|
||||
.then(() => {
|
||||
sendResponse({success: true})
|
||||
})
|
||||
.catch((e) => {
|
||||
sendResponse({error: e.message});
|
||||
});
|
||||
return true;
|
||||
},
|
||||
["execute-payment"]: function(db, detail, sendResponse) {
|
||||
return doPaymentHandler(db, detail, sendResponse);
|
||||
wallet.doPayment(detail.H_contract)
|
||||
.then((r) => {
|
||||
sendResponse({
|
||||
success: true,
|
||||
payUrl: r.payUrl,
|
||||
payReq: r.payReq
|
||||
});
|
||||
})
|
||||
.catch((e) => {
|
||||
sendResponse({success: false, error: e.message});
|
||||
});
|
||||
// async sendResponse
|
||||
return true;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function wxMain() {
|
||||
chrome.browserAction.setBadgeText({text: ""});
|
||||
|
||||
openTalerDb().then((db) => {
|
||||
updateBadge(db);
|
||||
let wallet = new Wallet(db, undefined, undefined);
|
||||
let handlers = makeHandlers(wallet);
|
||||
wallet.updateBadge();
|
||||
chrome.runtime.onMessage.addListener(
|
||||
function(req, sender, onresponse) {
|
||||
if (req.type in handlers) {
|
||||
|
@ -75,7 +75,22 @@ function canonicalizeBaseUrl(url) {
|
||||
x.query();
|
||||
return x.href();
|
||||
}
|
||||
function signDeposit(db, offer, cds) {
|
||||
function copy(o) {
|
||||
return JSON.parse(JSON.stringify(o));
|
||||
}
|
||||
function rankDenom(denom1, denom2) {
|
||||
// Slow ... we should find a better way than to convert it evert time.
|
||||
let v1 = new Amount(denom1.value);
|
||||
let v2 = new Amount(denom2.value);
|
||||
return (-1) * v1.cmp(v2);
|
||||
}
|
||||
class Wallet {
|
||||
constructor(db, http, badge) {
|
||||
this.db = db;
|
||||
this.http = http;
|
||||
this.badge = badge;
|
||||
}
|
||||
static signDeposit(offer, cds) {
|
||||
let ret = [];
|
||||
let amountSpent = Amount.getZero(cds[0].coin.currentAmount.currency);
|
||||
let amountRemaining = new Amount(offer.contract.amount);
|
||||
@ -120,16 +135,15 @@ function signDeposit(db, offer, cds) {
|
||||
ret.push({ sig: s, updatedCoin: cd.coin });
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
}
|
||||
/**
|
||||
* Get mints and associated coins that are still spendable,
|
||||
* but only if the sum the coins' remaining value exceeds the payment amount.
|
||||
* @param db
|
||||
* @param paymentAmount
|
||||
* @param depositFeeLimit
|
||||
* @param allowedMints
|
||||
*/
|
||||
function getPossibleMintCoins(db, paymentAmount, depositFeeLimit, allowedMints) {
|
||||
getPossibleMintCoins(paymentAmount, depositFeeLimit, allowedMints) {
|
||||
let m = {};
|
||||
function storeMintCoin(mc) {
|
||||
let mint = mc[0];
|
||||
@ -150,7 +164,7 @@ function getPossibleMintCoins(db, paymentAmount, depositFeeLimit, allowedMints)
|
||||
}
|
||||
}
|
||||
let ps = allowedMints.map((info) => {
|
||||
return Query(db)
|
||||
return Query(this.db)
|
||||
.iterIndex("mints", "pubKey", info.master_pub)
|
||||
.indexJoin("coins", "mintBaseUrl", (mint) => mint.baseUrl)
|
||||
.reduce(storeMintCoin);
|
||||
@ -190,8 +204,8 @@ function getPossibleMintCoins(db, paymentAmount, depositFeeLimit, allowedMints)
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
function executePay(db, offer, payCoinInfo, merchantBaseUrl, chosenMint) {
|
||||
}
|
||||
executePay(offer, payCoinInfo, merchantBaseUrl, chosenMint) {
|
||||
let payReq = {};
|
||||
payReq["H_wire"] = offer.contract.H_wire;
|
||||
payReq["H_contract"] = offer.H_contract;
|
||||
@ -207,61 +221,51 @@ function executePay(db, offer, payCoinInfo, merchantBaseUrl, chosenMint) {
|
||||
payUrl: payUrl.href(),
|
||||
payReq: payReq
|
||||
};
|
||||
return Query(db)
|
||||
return Query(this.db)
|
||||
.put("transactions", t)
|
||||
.putAll("coins", payCoinInfo.map((pci) => pci.updatedCoin))
|
||||
.finish();
|
||||
}
|
||||
function confirmPayHandler(db, detail, sendResponse) {
|
||||
let offer = detail.offer;
|
||||
getPossibleMintCoins(db, offer.contract.amount, offer.contract.max_fee, offer.contract.mints)
|
||||
.then((mcs) => {
|
||||
}
|
||||
confirmPay(offer, merchantPageUrl) {
|
||||
return Promise.resolve().then(() => {
|
||||
return this.getPossibleMintCoins(offer.contract.amount, offer.contract.max_fee, offer.contract.mints);
|
||||
}).then((mcs) => {
|
||||
if (Object.keys(mcs).length == 0) {
|
||||
sendResponse({ error: "Not enough coins." });
|
||||
return;
|
||||
throw Error("Not enough coins.");
|
||||
}
|
||||
let mintUrl = Object.keys(mcs)[0];
|
||||
let ds = signDeposit(db, offer, mcs[mintUrl]);
|
||||
return executePay(db, offer, ds, detail.merchantPageUrl, mintUrl)
|
||||
.then(() => {
|
||||
sendResponse({
|
||||
success: true,
|
||||
let ds = Wallet.signDeposit(offer, mcs[mintUrl]);
|
||||
return this.executePay(offer, ds, merchantPageUrl, mintUrl);
|
||||
});
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
function doPaymentHandler(db, detail, sendResponse) {
|
||||
let H_contract = detail.H_contract;
|
||||
Query(db)
|
||||
.get("transactions", H_contract)
|
||||
.then((r) => {
|
||||
if (!r) {
|
||||
sendResponse({ success: false, error: "contract not found" });
|
||||
return;
|
||||
}
|
||||
sendResponse({
|
||||
success: true,
|
||||
payUrl: r.payUrl,
|
||||
payReq: r.payReq
|
||||
doPayment(H_contract) {
|
||||
return Promise.resolve().then(() => {
|
||||
return Query(this.db)
|
||||
.get("transactions", H_contract)
|
||||
.then((t) => {
|
||||
if (!t) {
|
||||
throw Error("contract not found");
|
||||
}
|
||||
let resp = {
|
||||
payUrl: t.payUrl,
|
||||
payReq: t.payReq
|
||||
};
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
// async sendResponse
|
||||
return true;
|
||||
}
|
||||
function confirmReserveHandler(db, detail, sendResponse) {
|
||||
}
|
||||
confirmReserve(req) {
|
||||
let reservePriv = EddsaPrivateKey.create();
|
||||
let reservePub = reservePriv.getPublicKey();
|
||||
let form = new FormData();
|
||||
let now = (new Date()).toString();
|
||||
form.append(detail.field_amount, detail.amount_str);
|
||||
form.append(detail.field_reserve_pub, reservePub.toCrock());
|
||||
form.append(detail.field_mint, detail.mint);
|
||||
// XXX: set bank-specified fields.
|
||||
let mintBaseUrl = canonicalizeBaseUrl(detail.mint);
|
||||
httpPostForm(detail.post_url, form)
|
||||
form.append(req.field_amount, req.amount_str);
|
||||
form.append(req.field_reserve_pub, reservePub.toCrock());
|
||||
form.append(req.field_mint, req.mint);
|
||||
// TODO: set bank-specified fields.
|
||||
let mintBaseUrl = canonicalizeBaseUrl(req.mint);
|
||||
return httpPostForm(req.post_url, form)
|
||||
.then((hresp) => {
|
||||
// TODO: extract as interface
|
||||
let resp = {
|
||||
status: hresp.status,
|
||||
text: hresp.responseText,
|
||||
@ -285,35 +289,20 @@ function confirmReserveHandler(db, detail, sendResponse) {
|
||||
resp.success = true;
|
||||
// We can't show the page directly, so
|
||||
// we show some generic page from the wallet.
|
||||
// TODO: this should not be webextensions-specific
|
||||
resp.backlink = chrome.extension.getURL("pages/reserve-success.html");
|
||||
return Query(db)
|
||||
resp.backlink = null;
|
||||
return Query(this.db)
|
||||
.put("reserves", reserveRecord)
|
||||
.finish()
|
||||
.then(() => {
|
||||
// Do this in the background
|
||||
updateMintFromUrl(db, reserveRecord.mint_base_url)
|
||||
.then((mint) => updateReserve(db, reservePub, mint)
|
||||
.then((reserve) => depleteReserve(db, reserve, mint)));
|
||||
this.updateMintFromUrl(reserveRecord.mint_base_url)
|
||||
.then((mint) => this.updateReserve(reservePub, mint)
|
||||
.then((reserve) => this.depleteReserve(reserve, mint)));
|
||||
return resp;
|
||||
});
|
||||
})
|
||||
.then((resp) => {
|
||||
sendResponse(resp);
|
||||
});
|
||||
// Allow async response
|
||||
return true;
|
||||
}
|
||||
function copy(o) {
|
||||
return JSON.parse(JSON.stringify(o));
|
||||
}
|
||||
function rankDenom(denom1, denom2) {
|
||||
// Slow ... we should find a better way than to convert it evert time.
|
||||
let v1 = new Amount(denom1.value);
|
||||
let v2 = new Amount(denom2.value);
|
||||
return (-1) * v1.cmp(v2);
|
||||
}
|
||||
function withdrawPrepare(db, denom, reserve) {
|
||||
}
|
||||
withdrawPrepare(denom, reserve) {
|
||||
let reservePriv = new EddsaPrivateKey();
|
||||
reservePriv.loadCrock(reserve.reserve_priv);
|
||||
let reservePub = new EddsaPublicKey();
|
||||
@ -350,10 +339,10 @@ function withdrawPrepare(db, denom, reserve) {
|
||||
coinEv: ev.toCrock(),
|
||||
coinValue: denom.value
|
||||
};
|
||||
return Query(db).put("precoins", preCoin).finish().then(() => preCoin);
|
||||
}
|
||||
function withdrawExecute(db, pc) {
|
||||
return Query(db)
|
||||
return Query(this.db).put("precoins", preCoin).finish().then(() => preCoin);
|
||||
}
|
||||
withdrawExecute(pc) {
|
||||
return Query(this.db)
|
||||
.get("reserves", pc.reservePub)
|
||||
.then((r) => {
|
||||
let wd = {};
|
||||
@ -383,8 +372,8 @@ function withdrawExecute(db, pc) {
|
||||
};
|
||||
return coin;
|
||||
});
|
||||
}
|
||||
function updateBadge(db) {
|
||||
}
|
||||
updateBadge() {
|
||||
function countNonEmpty(c, n) {
|
||||
if (c.currentAmount.fraction != 0 || c.currentAmount.value != 0) {
|
||||
return n + 1;
|
||||
@ -395,29 +384,29 @@ function updateBadge(db) {
|
||||
chrome.browserAction.setBadgeText({ text: "" + n });
|
||||
chrome.browserAction.setBadgeBackgroundColor({ color: "#0F0" });
|
||||
}
|
||||
Query(db)
|
||||
Query(this.db)
|
||||
.iter("coins")
|
||||
.reduce(countNonEmpty, 0)
|
||||
.then(doBadge);
|
||||
}
|
||||
function storeCoin(db, coin) {
|
||||
Query(db)
|
||||
}
|
||||
storeCoin(coin) {
|
||||
Query(this.db)
|
||||
.delete("precoins", coin.coinPub)
|
||||
.add("coins", coin)
|
||||
.finish()
|
||||
.then(() => {
|
||||
updateBadge(db);
|
||||
this.updateBadge();
|
||||
});
|
||||
}
|
||||
function withdraw(db, denom, reserve) {
|
||||
return withdrawPrepare(db, denom, reserve)
|
||||
.then((pc) => withdrawExecute(db, pc))
|
||||
.then((c) => storeCoin(db, c));
|
||||
}
|
||||
/**
|
||||
}
|
||||
withdraw(denom, reserve) {
|
||||
return this.withdrawPrepare(denom, reserve)
|
||||
.then((pc) => this.withdrawExecute(pc))
|
||||
.then((c) => this.storeCoin(c));
|
||||
}
|
||||
/**
|
||||
* Withdraw coins from a reserve until it is empty.
|
||||
*/
|
||||
function depleteReserve(db, reserve, mint) {
|
||||
depleteReserve(reserve, mint) {
|
||||
let denoms = copy(mint.keys.denoms);
|
||||
let remaining = new Amount(reserve.current_amount);
|
||||
denoms.sort(rankDenom);
|
||||
@ -440,19 +429,20 @@ function depleteReserve(db, reserve, mint) {
|
||||
}
|
||||
}
|
||||
// Do the request one by one.
|
||||
function next() {
|
||||
let next = () => {
|
||||
if (workList.length == 0) {
|
||||
return;
|
||||
}
|
||||
let d = workList.pop();
|
||||
withdraw(db, d, reserve)
|
||||
this.withdraw(d, reserve)
|
||||
.then(() => next());
|
||||
}
|
||||
};
|
||||
// Asynchronous recursion
|
||||
next();
|
||||
}
|
||||
function updateReserve(db, reservePub, mint) {
|
||||
}
|
||||
updateReserve(reservePub, mint) {
|
||||
let reservePubStr = reservePub.toCrock();
|
||||
return Query(db)
|
||||
return Query(this.db)
|
||||
.get("reserves", reservePubStr)
|
||||
.then((reserve) => {
|
||||
let reqUrl = URI("reserve/status").absoluteTo(mint.baseUrl);
|
||||
@ -466,19 +456,19 @@ function updateReserve(db, reservePub, mint) {
|
||||
throw Error();
|
||||
}
|
||||
reserve.current_amount = reserveInfo.balance;
|
||||
return Query(db)
|
||||
return Query(this.db)
|
||||
.put("reserves", reserve)
|
||||
.finish()
|
||||
.then(() => reserve);
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
}
|
||||
/**
|
||||
* Update or add mint DB entry by fetching the /keys information.
|
||||
* Optionally link the reserve entry to the new or existing
|
||||
* mint entry in then DB.
|
||||
*/
|
||||
function updateMintFromUrl(db, baseUrl) {
|
||||
updateMintFromUrl(baseUrl) {
|
||||
let reqUrl = URI("keys").absoluteTo(baseUrl);
|
||||
return httpGet(reqUrl).then((resp) => {
|
||||
if (resp.status != 200) {
|
||||
@ -492,10 +482,10 @@ function updateMintFromUrl(db, baseUrl) {
|
||||
baseUrl: baseUrl,
|
||||
keys: mintKeysJson
|
||||
};
|
||||
return Query(db).put("mints", mint).finish().then(() => mint);
|
||||
return Query(this.db).put("mints", mint).finish().then(() => mint);
|
||||
});
|
||||
}
|
||||
function getBalances(db) {
|
||||
}
|
||||
getBalances() {
|
||||
function collectBalances(c, byCurrency) {
|
||||
let acc = byCurrency[c.currentAmount.currency];
|
||||
if (!acc) {
|
||||
@ -506,7 +496,8 @@ function getBalances(db) {
|
||||
byCurrency[c.currentAmount.currency] = am.toJson();
|
||||
return byCurrency;
|
||||
}
|
||||
return Query(db)
|
||||
return Query(this.db)
|
||||
.iter("coins")
|
||||
.reduce(collectBalances, {});
|
||||
}
|
||||
}
|
||||
|
@ -131,6 +131,54 @@ interface Reserve {
|
||||
}
|
||||
|
||||
|
||||
interface PaymentResponse {
|
||||
payUrl: string;
|
||||
payReq: any;
|
||||
}
|
||||
|
||||
|
||||
interface ConfirmReserveRequest {
|
||||
/**
|
||||
* Name of the form field for the amount.
|
||||
*/
|
||||
field_amount;
|
||||
|
||||
/**
|
||||
* Name of the form field for the reserve public key.
|
||||
*/
|
||||
field_reserve_pub;
|
||||
|
||||
/**
|
||||
* Name of the form field for the reserve public key.
|
||||
*/
|
||||
field_mint;
|
||||
|
||||
/**
|
||||
* The actual amount in string form.
|
||||
* TODO: where is this format specified?
|
||||
*/
|
||||
amount_str;
|
||||
|
||||
/**
|
||||
* Target URL for the reserve creation request.
|
||||
*/
|
||||
post_url;
|
||||
|
||||
/**
|
||||
* Mint URL where the bank should create the reserve.
|
||||
*/
|
||||
mint;
|
||||
}
|
||||
|
||||
|
||||
interface ConfirmReserveResponse {
|
||||
backlink: string;
|
||||
success: boolean;
|
||||
status: number;
|
||||
text: string;
|
||||
}
|
||||
|
||||
|
||||
type PayCoinInfo = Array<{ updatedCoin: Db.Coin, sig: CoinPaySig_interface }>;
|
||||
|
||||
|
||||
@ -148,9 +196,40 @@ function canonicalizeBaseUrl(url) {
|
||||
return x.href()
|
||||
}
|
||||
|
||||
interface HttpRequestLibrary {
|
||||
|
||||
function signDeposit(db: IDBDatabase,
|
||||
offer: Offer,
|
||||
}
|
||||
|
||||
interface Badge {
|
||||
|
||||
}
|
||||
|
||||
|
||||
function copy(o) {
|
||||
return JSON.parse(JSON.stringify(o));
|
||||
}
|
||||
|
||||
|
||||
function rankDenom(denom1: any, denom2: any) {
|
||||
// Slow ... we should find a better way than to convert it evert time.
|
||||
let v1 = new Amount(denom1.value);
|
||||
let v2 = new Amount(denom2.value);
|
||||
return (-1) * v1.cmp(v2);
|
||||
}
|
||||
|
||||
|
||||
class Wallet {
|
||||
private db: IDBDatabase;
|
||||
private http: HttpRequestLibrary;
|
||||
private badge: Badge;
|
||||
|
||||
constructor(db: IDBDatabase, http: HttpRequestLibrary, badge: Badge) {
|
||||
this.db = db;
|
||||
this.http = http;
|
||||
this.badge = badge;
|
||||
}
|
||||
|
||||
static signDeposit(offer: Offer,
|
||||
cds: Db.CoinWithDenom[]): PayCoinInfo {
|
||||
let ret = [];
|
||||
let amountSpent = Amount.getZero(cds[0].coin.currentAmount.currency);
|
||||
@ -204,19 +283,17 @@ function signDeposit(db: IDBDatabase,
|
||||
ret.push({sig: s, updatedCoin: cd.coin});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get mints and associated coins that are still spendable,
|
||||
* but only if the sum the coins' remaining value exceeds the payment amount.
|
||||
* @param db
|
||||
* @param paymentAmount
|
||||
* @param depositFeeLimit
|
||||
* @param allowedMints
|
||||
*/
|
||||
function getPossibleMintCoins(db: IDBDatabase,
|
||||
paymentAmount: AmountJson_interface,
|
||||
getPossibleMintCoins(paymentAmount: AmountJson_interface,
|
||||
depositFeeLimit: AmountJson_interface,
|
||||
allowedMints: MintInfo[]): Promise<MintCoins> {
|
||||
|
||||
@ -242,7 +319,7 @@ function getPossibleMintCoins(db: IDBDatabase,
|
||||
}
|
||||
|
||||
let ps = allowedMints.map((info) => {
|
||||
return Query(db)
|
||||
return Query(this.db)
|
||||
.iterIndex("mints", "pubKey", info.master_pub)
|
||||
.indexJoin("coins", "mintBaseUrl", (mint) => mint.baseUrl)
|
||||
.reduce(storeMintCoin);
|
||||
@ -286,11 +363,10 @@ function getPossibleMintCoins(db: IDBDatabase,
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function executePay(db,
|
||||
offer: Offer,
|
||||
executePay(offer: Offer,
|
||||
payCoinInfo: PayCoinInfo,
|
||||
merchantBaseUrl: string,
|
||||
chosenMint: string): Promise<void> {
|
||||
@ -310,71 +386,58 @@ function executePay(db,
|
||||
payReq: payReq
|
||||
};
|
||||
|
||||
return Query(db)
|
||||
return Query(this.db)
|
||||
.put("transactions", t)
|
||||
.putAll("coins", payCoinInfo.map((pci) => pci.updatedCoin))
|
||||
.finish();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function confirmPayHandler(db, detail: ConfirmPayRequest, sendResponse) {
|
||||
let offer: Offer = detail.offer;
|
||||
getPossibleMintCoins(db,
|
||||
offer.contract.amount,
|
||||
confirmPay(offer: Offer, merchantPageUrl: string): Promise<any> {
|
||||
return Promise.resolve().then(() => {
|
||||
return this.getPossibleMintCoins(offer.contract.amount,
|
||||
offer.contract.max_fee,
|
||||
offer.contract.mints)
|
||||
.then((mcs) => {
|
||||
}).then((mcs) => {
|
||||
if (Object.keys(mcs).length == 0) {
|
||||
sendResponse({error: "Not enough coins."});
|
||||
return;
|
||||
throw Error("Not enough coins.");
|
||||
}
|
||||
let mintUrl = Object.keys(mcs)[0];
|
||||
let ds = signDeposit(db, offer, mcs[mintUrl]);
|
||||
return executePay(db, offer, ds, detail.merchantPageUrl, mintUrl)
|
||||
.then(() => {
|
||||
sendResponse({
|
||||
success: true,
|
||||
let ds = Wallet.signDeposit(offer, mcs[mintUrl]);
|
||||
return this.executePay(offer, ds, merchantPageUrl, mintUrl);
|
||||
});
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function doPaymentHandler(db, detail, sendResponse) {
|
||||
let H_contract = detail.H_contract;
|
||||
Query(db)
|
||||
.get("transactions", H_contract)
|
||||
.then((r) => {
|
||||
if (!r) {
|
||||
sendResponse({success: false, error: "contract not found"});
|
||||
return;
|
||||
}
|
||||
sendResponse({
|
||||
success: true,
|
||||
payUrl: r.payUrl,
|
||||
payReq: r.payReq
|
||||
|
||||
doPayment(H_contract): Promise<PaymentResponse> {
|
||||
return Promise.resolve().then(() => {
|
||||
return Query(this.db)
|
||||
.get("transactions", H_contract)
|
||||
.then((t) => {
|
||||
if (!t) {
|
||||
throw Error("contract not found");
|
||||
}
|
||||
let resp: PaymentResponse = {
|
||||
payUrl: t.payUrl,
|
||||
payReq: t.payReq
|
||||
};
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
// async sendResponse
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function confirmReserveHandler(db, detail, sendResponse) {
|
||||
confirmReserve(req: ConfirmReserveRequest): Promise<ConfirmReserveResponse> {
|
||||
let reservePriv = EddsaPrivateKey.create();
|
||||
let reservePub = reservePriv.getPublicKey();
|
||||
let form = new FormData();
|
||||
let now = (new Date()).toString();
|
||||
form.append(detail.field_amount, detail.amount_str);
|
||||
form.append(detail.field_reserve_pub, reservePub.toCrock());
|
||||
form.append(detail.field_mint, detail.mint);
|
||||
// XXX: set bank-specified fields.
|
||||
let mintBaseUrl = canonicalizeBaseUrl(detail.mint);
|
||||
httpPostForm(detail.post_url, form)
|
||||
form.append(req.field_amount, req.amount_str);
|
||||
form.append(req.field_reserve_pub, reservePub.toCrock());
|
||||
form.append(req.field_mint, req.mint);
|
||||
// TODO: set bank-specified fields.
|
||||
let mintBaseUrl = canonicalizeBaseUrl(req.mint);
|
||||
|
||||
return httpPostForm(req.post_url, form)
|
||||
.then((hresp) => {
|
||||
// TODO: extract as interface
|
||||
let resp = {
|
||||
let resp: ConfirmReserveResponse = {
|
||||
status: hresp.status,
|
||||
text: hresp.responseText,
|
||||
success: undefined,
|
||||
@ -399,45 +462,24 @@ function confirmReserveHandler(db, detail, sendResponse) {
|
||||
resp.success = true;
|
||||
// We can't show the page directly, so
|
||||
// we show some generic page from the wallet.
|
||||
// TODO: this should not be webextensions-specific
|
||||
resp.backlink = chrome.extension.getURL("pages/reserve-success.html");
|
||||
return Query(db)
|
||||
resp.backlink = null;
|
||||
return Query(this.db)
|
||||
.put("reserves", reserveRecord)
|
||||
.finish()
|
||||
.then(() => {
|
||||
// Do this in the background
|
||||
updateMintFromUrl(db, reserveRecord.mint_base_url)
|
||||
this.updateMintFromUrl(reserveRecord.mint_base_url)
|
||||
.then((mint) =>
|
||||
updateReserve(db, reservePub, mint)
|
||||
.then((reserve) => depleteReserve(db, reserve, mint))
|
||||
this.updateReserve(reservePub, mint)
|
||||
.then((reserve) => this.depleteReserve(reserve,
|
||||
mint))
|
||||
);
|
||||
return resp;
|
||||
});
|
||||
})
|
||||
.then((resp) => {
|
||||
sendResponse(resp);
|
||||
});
|
||||
}
|
||||
|
||||
// Allow async response
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function copy(o) {
|
||||
return JSON.parse(JSON.stringify(o));
|
||||
}
|
||||
|
||||
|
||||
function rankDenom(denom1: any, denom2: any) {
|
||||
// Slow ... we should find a better way than to convert it evert time.
|
||||
let v1 = new Amount(denom1.value);
|
||||
let v2 = new Amount(denom2.value);
|
||||
return (-1) * v1.cmp(v2);
|
||||
}
|
||||
|
||||
|
||||
function withdrawPrepare(db: IDBDatabase,
|
||||
denom: Db.Denomination,
|
||||
withdrawPrepare(denom: Db.Denomination,
|
||||
reserve: Reserve): Promise<Db.PreCoin> {
|
||||
let reservePriv = new EddsaPrivateKey();
|
||||
reservePriv.loadCrock(reserve.reserve_priv);
|
||||
@ -481,12 +523,12 @@ function withdrawPrepare(db: IDBDatabase,
|
||||
coinValue: denom.value
|
||||
};
|
||||
|
||||
return Query(db).put("precoins", preCoin).finish().then(() => preCoin);
|
||||
}
|
||||
return Query(this.db).put("precoins", preCoin).finish().then(() => preCoin);
|
||||
}
|
||||
|
||||
|
||||
function withdrawExecute(db, pc: Db.PreCoin): Promise<Db.Coin> {
|
||||
return Query(db)
|
||||
withdrawExecute(pc: Db.PreCoin): Promise<Db.Coin> {
|
||||
return Query(this.db)
|
||||
.get("reserves", pc.reservePub)
|
||||
.then((r) => {
|
||||
let wd: any = {};
|
||||
@ -518,10 +560,10 @@ function withdrawExecute(db, pc: Db.PreCoin): Promise<Db.Coin> {
|
||||
};
|
||||
return coin;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function updateBadge(db) {
|
||||
updateBadge() {
|
||||
function countNonEmpty(c, n) {
|
||||
if (c.currentAmount.fraction != 0 || c.currentAmount.value != 0) {
|
||||
return n + 1;
|
||||
@ -534,35 +576,33 @@ function updateBadge(db) {
|
||||
chrome.browserAction.setBadgeBackgroundColor({color: "#0F0"});
|
||||
}
|
||||
|
||||
Query(db)
|
||||
Query(this.db)
|
||||
.iter("coins")
|
||||
.reduce(countNonEmpty, 0)
|
||||
.then(doBadge);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function storeCoin(db, coin: Db.Coin) {
|
||||
Query(db)
|
||||
storeCoin(coin: Db.Coin) {
|
||||
Query(this.db)
|
||||
.delete("precoins", coin.coinPub)
|
||||
.add("coins", coin)
|
||||
.finish()
|
||||
.then(() => {
|
||||
updateBadge(db);
|
||||
this.updateBadge();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
withdraw(denom, reserve): Promise<void> {
|
||||
return this.withdrawPrepare(denom, reserve)
|
||||
.then((pc) => this.withdrawExecute(pc))
|
||||
.then((c) => this.storeCoin(c));
|
||||
}
|
||||
|
||||
|
||||
function withdraw(db, denom, reserve): Promise<void> {
|
||||
return withdrawPrepare(db, denom, reserve)
|
||||
.then((pc) => withdrawExecute(db, pc))
|
||||
.then((c) => storeCoin(db, c));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Withdraw coins from a reserve until it is empty.
|
||||
*/
|
||||
function depleteReserve(db, reserve, mint): void {
|
||||
depleteReserve(reserve, mint): void {
|
||||
let denoms = copy(mint.keys.denoms);
|
||||
let remaining = new Amount(reserve.current_amount);
|
||||
denoms.sort(rankDenom);
|
||||
@ -586,24 +626,23 @@ function depleteReserve(db, reserve, mint): void {
|
||||
}
|
||||
|
||||
// Do the request one by one.
|
||||
function next(): void {
|
||||
let next = () => {
|
||||
if (workList.length == 0) {
|
||||
return;
|
||||
}
|
||||
let d = workList.pop();
|
||||
withdraw(db, d, reserve)
|
||||
this.withdraw(d, reserve)
|
||||
.then(() => next());
|
||||
};
|
||||
|
||||
// Asynchronous recursion
|
||||
next();
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
|
||||
function updateReserve(db: IDBDatabase,
|
||||
reservePub: EddsaPublicKey,
|
||||
updateReserve(reservePub: EddsaPublicKey,
|
||||
mint): Promise<Reserve> {
|
||||
let reservePubStr = reservePub.toCrock();
|
||||
return Query(db)
|
||||
return Query(this.db)
|
||||
.get("reserves", reservePubStr)
|
||||
.then((reserve) => {
|
||||
let reqUrl = URI("reserve/status").absoluteTo(mint.baseUrl);
|
||||
@ -617,21 +656,20 @@ function updateReserve(db: IDBDatabase,
|
||||
throw Error();
|
||||
}
|
||||
reserve.current_amount = reserveInfo.balance;
|
||||
return Query(db)
|
||||
return Query(this.db)
|
||||
.put("reserves", reserve)
|
||||
.finish()
|
||||
.then(() => reserve);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Update or add mint DB entry by fetching the /keys information.
|
||||
* Optionally link the reserve entry to the new or existing
|
||||
* mint entry in then DB.
|
||||
*/
|
||||
function updateMintFromUrl(db, baseUrl) {
|
||||
updateMintFromUrl(baseUrl) {
|
||||
let reqUrl = URI("keys").absoluteTo(baseUrl);
|
||||
return httpGet(reqUrl).then((resp) => {
|
||||
if (resp.status != 200) {
|
||||
@ -645,12 +683,12 @@ function updateMintFromUrl(db, baseUrl) {
|
||||
baseUrl: baseUrl,
|
||||
keys: mintKeysJson
|
||||
};
|
||||
return Query(db).put("mints", mint).finish().then(() => mint);
|
||||
return Query(this.db).put("mints", mint).finish().then(() => mint);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getBalances(db): Promise<any> {
|
||||
getBalances(): Promise<any> {
|
||||
function collectBalances(c: Db.Coin, byCurrency) {
|
||||
let acc: AmountJson_interface = byCurrency[c.currentAmount.currency];
|
||||
if (!acc) {
|
||||
@ -662,7 +700,8 @@ function getBalances(db): Promise<any> {
|
||||
return byCurrency;
|
||||
}
|
||||
|
||||
return Query(db)
|
||||
return Query(this.db)
|
||||
.iter("coins")
|
||||
.reduce(collectBalances, {});
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ document.addEventListener("taler-create-reserve", function (e) {
|
||||
let uri = URI(chrome.extension.getURL("pages/confirm-create-reserve.html"));
|
||||
document.location.href = uri.query(params).href();
|
||||
});
|
||||
document.addEventListener('taler-contract', function (e) {
|
||||
document.addEventListener("taler-contract", function (e) {
|
||||
// XXX: the merchant should just give us the parsed data ...
|
||||
let offer = JSON.parse(e.detail);
|
||||
let uri = URI(chrome.extension.getURL("pages/confirm-contract.html"));
|
||||
|
@ -57,7 +57,7 @@ document.addEventListener("taler-create-reserve", function(e: CustomEvent) {
|
||||
document.location.href = uri.query(params).href();
|
||||
});
|
||||
|
||||
document.addEventListener('taler-contract', function(e: CustomEvent) {
|
||||
document.addEventListener("taler-contract", function(e: CustomEvent) {
|
||||
// XXX: the merchant should just give us the parsed data ...
|
||||
let offer = JSON.parse(e.detail);
|
||||
let uri = URI(chrome.extension.getURL("pages/confirm-contract.html"));
|
||||
|
@ -43,12 +43,12 @@
|
||||
"scripts": [
|
||||
"lib/util.js",
|
||||
"lib/URI.js",
|
||||
"background/checkable.js",
|
||||
"background/libwrapper.js",
|
||||
"background/emscriptif.js",
|
||||
"background/db.js",
|
||||
"background/query.js",
|
||||
"background/messaging.js",
|
||||
"background/checkable.js",
|
||||
"background/http.js",
|
||||
"background/wallet.js"
|
||||
]
|
||||
|
@ -22,7 +22,7 @@
|
||||
<body>
|
||||
<div id="header" class="nav">
|
||||
<a href="balance-overview.html" class="active">Wallet</a>
|
||||
<a href="transactions.html">Transactions</a>
|
||||
<a href="history.html">History</a>
|
||||
<a href="reserves.html">Reserves</a>
|
||||
<button id="debug">Debug!</button>
|
||||
<button id="reset">Reset!</button>
|
||||
|
@ -1,5 +1,20 @@
|
||||
/*
|
||||
This file is part of TALER
|
||||
(C) 2016 GNUnet e.V.
|
||||
|
||||
TALER is free software; you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 3, or (at your option) any later version.
|
||||
|
||||
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
"use strict";
|
||||
document.addEventListener('DOMContentLoaded', (e) => {
|
||||
document.addEventListener("DOMContentLoaded", (e) => {
|
||||
console.log("content loaded");
|
||||
chrome.runtime.sendMessage({ type: "balances" }, function (wallet) {
|
||||
let context = document.getElementById("balance-template").innerHTML;
|
||||
|
@ -1,6 +1,22 @@
|
||||
/*
|
||||
This file is part of TALER
|
||||
(C) 2016 GNUnet e.V.
|
||||
|
||||
TALER is free software; you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 3, or (at your option) any later version.
|
||||
|
||||
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
document.addEventListener('DOMContentLoaded', (e) => {
|
||||
document.addEventListener("DOMContentLoaded", (e) => {
|
||||
console.log("content loaded");
|
||||
chrome.runtime.sendMessage({type: "balances"}, function(wallet) {
|
||||
let context = document.getElementById("balance-template").innerHTML;
|
||||
|
32
extension/popup/history.html
Normal file
32
extension/popup/history.html
Normal file
@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="popup.css" type="text/css">
|
||||
<script src="../lib/util.js" type="text/javascript"></script>
|
||||
<script src="history.js" type="text/javascript"></script>
|
||||
|
||||
<script id="balance-template" type="text/x-handlebars-template">
|
||||
{{#each transactions}}
|
||||
<p>bla</p>
|
||||
{{else}}
|
||||
There's nothing here. Go to
|
||||
our <a href="http://demo.taler.net">demo site</a> to try GNU Taler.
|
||||
{{/each}}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="header" class="nav">
|
||||
<a href="balance-overview.html">Wallet</a>
|
||||
<a href="history.html" class="active">Transactions</a>
|
||||
<a href="reserves.html">Reserves</a>
|
||||
</div>
|
||||
|
||||
<div id="content">
|
||||
(Loading...)
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
22
extension/popup/history.tsx
Normal file
22
extension/popup/history.tsx
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
This file is part of TALER
|
||||
(C) 2016 GNUnet e.V.
|
||||
|
||||
TALER is free software; you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 3, or (at your option) any later version.
|
||||
|
||||
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
document.addEventListener("DOMContentLoaded", (e) => {
|
||||
|
||||
});
|
@ -9,7 +9,7 @@
|
||||
<body>
|
||||
<div id="header" class="nav">
|
||||
<a href="balance-overview.html">Wallet</a>
|
||||
<a href="transactions.html">Transactions</a>
|
||||
<a href="history.html">Transactions</a>
|
||||
<a href="reserves.html" class="active">Reserves</a>
|
||||
</div>
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
<body>
|
||||
<div id="header" class="nav">
|
||||
<a href="balance-overview.html">Wallet</a>
|
||||
<a href="transactions.html">Transactions</a>
|
||||
<a href="history.html">Transactions</a>
|
||||
<a href="reserves.html" class="active">Reserves</a>
|
||||
</div>
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
<body>
|
||||
<div id="header" class="nav">
|
||||
<a href="balance-overview.html">Wallet</a>
|
||||
<a href="transactions.html">Transactions</a>
|
||||
<a href="history.html">Transactions</a>
|
||||
<a href="reserves.html" class="active">Reserves</a>
|
||||
</div>
|
||||
|
||||
|
@ -1,62 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="popup.css" type="text/css">
|
||||
<script src="../lib/util.js" type="text/javascript"></script>
|
||||
<script src="transactions.js" type="text/javascript"></script>
|
||||
|
||||
<script id="balance-template" type="text/x-handlebars-template">
|
||||
{{#each transactions}}
|
||||
bla
|
||||
{{else}}
|
||||
Looks like you didn't make any transactions. Get some
|
||||
coins and <a>donate</a> something.
|
||||
{{/each}}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="header" class="nav">
|
||||
<a href="balance-overview.html">Wallet</a>
|
||||
<a href="transactions.html" class="active">Transactions</a>
|
||||
<a href="reserves.html">Reserves</a>
|
||||
</div>
|
||||
|
||||
<div id="content">
|
||||
<table id="transactions-table" class="hidden">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Amount</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<!--
|
||||
<tr>
|
||||
<td class="date">2015-12-21 13:37</td>
|
||||
<td class="amount">42 EUR</td>
|
||||
<td class="status">Completed</td>
|
||||
<td class="contract"><button>Contract</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="date">2015-12-22 10:01</td>
|
||||
<td class="amount">23 USD</td>
|
||||
<td class="status">Pending</td>
|
||||
<td class="contract"><button>Contract</button></td>
|
||||
</tr>
|
||||
-->
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p id="no-transactions">
|
||||
There are no transactions to show.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,39 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
function add_transaction (date, currency, amount, status, contract)
|
||||
{
|
||||
let table = document.getElementById('transactions-table');
|
||||
table.className = table.className.replace(/\bhidden\b/, '');
|
||||
let tr = document.createElement('tr');
|
||||
table.appendChild(tr);
|
||||
|
||||
let td_date = document.createElement('td');
|
||||
td_date.className = 'date';
|
||||
let text_date = document.createTextNode(date_format (date));
|
||||
tr.appendChild(td_date).appendChild(text_date);
|
||||
|
||||
let td_amount = document.createElement('td');
|
||||
td_amount.className = 'amount';
|
||||
let text_amount = document.createTextNode(amount +' '+ currency);
|
||||
tr.appendChild(td_amount).appendChild(text_amount);
|
||||
|
||||
let td_status = document.createElement('td');
|
||||
td_status.className = 'status';
|
||||
let text_status = document.createTextNode(status);
|
||||
tr.appendChild(td_status).appendChild(text_status);
|
||||
|
||||
let td_contract = document.createElement('td');
|
||||
td_contract.className = 'contract';
|
||||
let btn_contract = document.createElement('button');
|
||||
btn_contract.appendChild(document.createTextNode('Contract'));
|
||||
tr.appendChild(td_contract).appendChild(btn_contract);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
let no = document.getElementById('no-transactions');
|
||||
|
||||
// FIXME
|
||||
no.className += ' hidden';
|
||||
add_transaction (new Date('2015-12-21 13:37'), 'EUR', 42, 'Completed', {});
|
||||
add_transaction (new Date('2015-12-22 10:01'), 'USD', 23, 'Pending', {});
|
||||
});
|
@ -16,6 +16,7 @@
|
||||
"lib/polyfill-react.ts",
|
||||
"content_scripts/notify.ts",
|
||||
"popup/balance-overview.tsx",
|
||||
"popup/history.tsx",
|
||||
"pages/confirm-contract.tsx",
|
||||
"pages/confirm-create-reserve.tsx"
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user