2017-03-28 09:47:22 +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
|
|
|
|
*/
|
|
|
|
|
2019-09-05 16:10:53 +02:00
|
|
|
import { CurrencyRecord } from "../../dbTypes";
|
|
|
|
import { getCurrencies, updateCurrency } from "../wxApi";
|
|
|
|
import React, { useState } from "react";
|
2017-04-20 03:09:25 +02:00
|
|
|
import URI = require("urijs");
|
2019-09-05 16:10:53 +02:00
|
|
|
import { registerMountPage } from "../renderHtml";
|
2017-03-28 09:47:22 +02:00
|
|
|
|
|
|
|
interface ConfirmAuditorProps {
|
|
|
|
url: string;
|
|
|
|
currency: string;
|
|
|
|
auditorPub: string;
|
|
|
|
expirationStamp: number;
|
|
|
|
}
|
|
|
|
|
2019-09-05 16:10:53 +02:00
|
|
|
function ConfirmAuditor(props: ConfirmAuditorProps) {
|
|
|
|
const [addDone, setAddDone] = useState(false);
|
|
|
|
|
2017-03-28 09:47:22 +02:00
|
|
|
|
2019-09-05 16:10:53 +02:00
|
|
|
const add = async() => {
|
2017-05-29 16:58:03 +02:00
|
|
|
const currencies = await getCurrencies();
|
2019-09-05 16:10:53 +02:00
|
|
|
let currency: CurrencyRecord | undefined;
|
2017-03-28 09:47:22 +02:00
|
|
|
|
2017-05-29 16:58:03 +02:00
|
|
|
for (const c of currencies) {
|
2019-09-05 16:10:53 +02:00
|
|
|
if (c.name === props.currency) {
|
2017-03-28 09:47:22 +02:00
|
|
|
currency = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!currency) {
|
2019-09-05 16:10:53 +02:00
|
|
|
currency = {
|
|
|
|
name: props.currency,
|
|
|
|
auditors: [],
|
|
|
|
fractionalDigits: 2,
|
|
|
|
exchanges: [],
|
|
|
|
};
|
2017-03-28 09:47:22 +02:00
|
|
|
}
|
|
|
|
|
2017-05-29 16:58:03 +02:00
|
|
|
const newAuditor = {
|
2019-09-05 16:10:53 +02:00
|
|
|
auditorPub: props.auditorPub,
|
|
|
|
baseUrl: props.url,
|
|
|
|
expirationStamp: props.expirationStamp,
|
2017-05-29 16:58:03 +02:00
|
|
|
};
|
2017-03-28 09:47:22 +02:00
|
|
|
|
|
|
|
let auditorFound = false;
|
2017-05-29 16:58:03 +02:00
|
|
|
for (const idx in currency.auditors) {
|
|
|
|
const a = currency.auditors[idx];
|
2019-09-05 16:10:53 +02:00
|
|
|
if (a.baseUrl === props.url) {
|
2017-03-28 09:47:22 +02:00
|
|
|
auditorFound = true;
|
|
|
|
// Update auditor if already found by URL.
|
|
|
|
currency.auditors[idx] = newAuditor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!auditorFound) {
|
|
|
|
currency.auditors.push(newAuditor);
|
|
|
|
}
|
|
|
|
|
|
|
|
await updateCurrency(currency);
|
|
|
|
|
2019-09-05 16:10:53 +02:00
|
|
|
setAddDone(true);
|
2017-03-28 09:47:22 +02:00
|
|
|
}
|
|
|
|
|
2019-09-05 16:10:53 +02:00
|
|
|
const back = () => {
|
2017-03-28 09:47:22 +02:00
|
|
|
window.history.back();
|
2019-09-05 16:10:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div id="main">
|
|
|
|
<p>
|
|
|
|
Do you want to let <strong>{props.auditorPub}</strong> audit the
|
|
|
|
currency "{props.currency}"?
|
|
|
|
</p>
|
|
|
|
{addDone ? (
|
|
|
|
<div>
|
|
|
|
Auditor was added! You can also{" "}
|
|
|
|
<a href={chrome.extension.getURL("/src/webex/pages/auditors.html")}>
|
|
|
|
view and edit
|
|
|
|
</a>{" "}
|
|
|
|
auditors.
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div>
|
|
|
|
<button
|
|
|
|
onClick={() => add()}
|
|
|
|
className="pure-button pure-button-primary"
|
|
|
|
>
|
|
|
|
Yes
|
|
|
|
</button>
|
|
|
|
<button onClick={() => back()} className="pure-button">
|
|
|
|
No
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
2017-03-28 09:47:22 +02:00
|
|
|
}
|
|
|
|
|
2019-09-05 16:10:53 +02:00
|
|
|
|
|
|
|
registerMountPage(() => {
|
2017-04-20 03:09:25 +02:00
|
|
|
const walletPageUrl = new URI(document.location.href);
|
2019-09-05 16:10:53 +02:00
|
|
|
const query: any = JSON.parse(
|
|
|
|
(URI.parseQuery(walletPageUrl.query()) as any).req,
|
|
|
|
);
|
2017-03-28 09:47:22 +02:00
|
|
|
const url = query.url;
|
|
|
|
const currency: string = query.currency;
|
|
|
|
const auditorPub: string = query.auditorPub;
|
|
|
|
const expirationStamp = Number.parseInt(query.expirationStamp);
|
|
|
|
const args = { url, currency, auditorPub, expirationStamp };
|
2019-09-05 16:10:53 +02:00
|
|
|
return <ConfirmAuditor {...args}/>;
|
|
|
|
});
|