2017-05-01 04:05:16 +02:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
|
|
|
(C) 2017 Inria
|
|
|
|
|
|
|
|
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, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* View and edit auditors.
|
|
|
|
*
|
|
|
|
* @author Florian Dold
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2017-05-29 16:27:53 +02:00
|
|
|
/**
|
|
|
|
* Imports.
|
|
|
|
*/
|
2017-06-04 17:56:55 +02:00
|
|
|
import { renderAmount } from "../renderHtml";
|
2017-05-01 04:05:16 +02:00
|
|
|
import {
|
2017-05-29 16:27:53 +02:00
|
|
|
ReserveRecord,
|
2017-05-28 23:15:41 +02:00
|
|
|
} from "../../types";
|
|
|
|
|
2017-05-01 04:05:16 +02:00
|
|
|
import { ImplicitStateComponent, StateHolder } from "../components";
|
|
|
|
import {
|
|
|
|
getPaybackReserves,
|
|
|
|
withdrawPaybackReserve,
|
|
|
|
} from "../wxApi";
|
2017-05-28 23:15:41 +02:00
|
|
|
|
2017-05-01 04:05:16 +02:00
|
|
|
import * as React from "react";
|
|
|
|
import * as ReactDOM from "react-dom";
|
|
|
|
|
|
|
|
class Payback extends ImplicitStateComponent<any> {
|
2017-05-29 16:27:53 +02:00
|
|
|
private reserves: StateHolder<ReserveRecord[]|null> = this.makeState(null);
|
2017-05-01 04:05:16 +02:00
|
|
|
constructor() {
|
|
|
|
super();
|
2017-05-29 16:27:53 +02:00
|
|
|
const port = chrome.runtime.connect();
|
2017-05-01 04:05:16 +02:00
|
|
|
port.onMessage.addListener((msg: any) => {
|
|
|
|
if (msg.notify) {
|
|
|
|
console.log("got notified");
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
async update() {
|
2017-05-29 16:27:53 +02:00
|
|
|
const reserves = await getPaybackReserves();
|
2017-05-01 04:05:16 +02:00
|
|
|
this.reserves(reserves);
|
|
|
|
}
|
|
|
|
|
|
|
|
withdrawPayback(pub: string) {
|
2017-05-29 16:27:53 +02:00
|
|
|
withdrawPaybackReserve(pub);
|
2017-05-01 04:05:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render(): JSX.Element {
|
2017-05-29 16:27:53 +02:00
|
|
|
const reserves = this.reserves();
|
2017-05-01 04:05:16 +02:00
|
|
|
if (!reserves) {
|
|
|
|
return <span>loading ...</span>;
|
|
|
|
}
|
2017-05-29 16:27:53 +02:00
|
|
|
if (reserves.length === 0) {
|
2017-05-01 04:05:16 +02:00
|
|
|
return <span>No reserves with payback available.</span>;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div>
|
2017-05-29 16:27:53 +02:00
|
|
|
{reserves.map((r) => (
|
2017-05-01 04:05:16 +02:00
|
|
|
<div>
|
2017-06-04 17:56:55 +02:00
|
|
|
<h2>Reserve for ${renderAmount(r.current_amount!)}</h2>
|
2017-05-01 04:05:16 +02:00
|
|
|
<ul>
|
|
|
|
<li>Exchange: ${r.exchange_base_url}</li>
|
|
|
|
</ul>
|
|
|
|
<button onClick={() => this.withdrawPayback(r.reserve_pub)}>Withdraw again</button>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-29 16:27:53 +02:00
|
|
|
function main() {
|
2017-05-01 04:05:16 +02:00
|
|
|
ReactDOM.render(<Payback />, document.getElementById("container")!);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", main);
|