diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-03-28 09:47:22 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-03-28 09:47:43 +0200 |
commit | e8bec33231a620579ccd1acd30824fd6c3a13dc2 (patch) | |
tree | 0bf17284382e55a29d83e5967d1243b19574d395 /src/pages | |
parent | 2a1ece8417df48c4aac54851397e2f0ee87b9f06 (diff) |
add auditor editing
Diffstat (limited to 'src/pages')
-rw-r--r-- | src/pages/add-auditor.html | 40 | ||||
-rw-r--r-- | src/pages/add-auditor.tsx | 112 | ||||
-rw-r--r-- | src/pages/auditors.tsx | 35 | ||||
-rw-r--r-- | src/pages/confirm-create-reserve.html | 63 |
4 files changed, 177 insertions, 73 deletions
diff --git a/src/pages/add-auditor.html b/src/pages/add-auditor.html new file mode 100644 index 000000000..7966e211f --- /dev/null +++ b/src/pages/add-auditor.html @@ -0,0 +1,40 @@ +<!DOCTYPE html> +<html> + +<head> + <title>Taler Wallet: Add Auditor</title> + + <link rel="stylesheet" type="text/css" href="../style/lang.css"> + <link rel="stylesheet" type="text/css" href="../style/wallet.css"> + + <link rel="icon" href="/img/icon.png"> + + <script src="/src/vendor/URI.js"></script> + <script src="/src/vendor/react.js"></script> + <script src="/src/vendor/react-dom.js"></script> + + <script src="/src/vendor/system-csp-production.src.js"></script> + <script src="/src/moduleTrampoline.js"></script> + + <link rel="stylesheet" type="text/css" href="/src/style/pure.css"> + <link rel="stylesheet" type="text/css" href="/src/style/wallet.css"> + + <style> + .tree-item { + margin: 2em; + border-radius: 5px; + border: 1px solid gray; + padding: 1em; + } + .button-linky { + background: none; + color: black; + text-decoration: underline; + border: none; + } + </style> + + <body> + <div id="container"></div> + </body> +</html> diff --git a/src/pages/add-auditor.tsx b/src/pages/add-auditor.tsx new file mode 100644 index 000000000..2eb98c4c3 --- /dev/null +++ b/src/pages/add-auditor.tsx @@ -0,0 +1,112 @@ +/* + 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 + */ + + +import { ExchangeRecord, DenominationRecord } from "src/types"; +import { AuditorRecord, CurrencyRecord, ReserveRecord, CoinRecord, PreCoinRecord, Denomination } from "src/types"; +import { ImplicitStateComponent, StateHolder } from "src/components"; +import { + getCurrencies, + updateCurrency, +} from "src/wxApi"; +import { prettyAmount } from "src/renderHtml"; +import { getTalerStampDate } from "src/helpers"; + +interface ConfirmAuditorProps { + url: string; + currency: string; + auditorPub: string; + expirationStamp: number; +} + +class ConfirmAuditor extends ImplicitStateComponent<ConfirmAuditorProps> { + addDone: StateHolder<boolean> = this.makeState(false); + constructor() { + super(); + } + + async add() { + let currencies = await getCurrencies(); + let currency: CurrencyRecord|undefined = undefined; + + for (let c of currencies) { + if (c.name == this.props.currency) { + currency = c; + } + } + + if (!currency) { + currency = { name: this.props.currency, auditors: [], fractionalDigits: 2 }; + } + + let newAuditor = { auditorPub: this.props.auditorPub, baseUrl: this.props.url, expirationStamp: this.props.expirationStamp }; + + let auditorFound = false; + for (let idx in currency.auditors) { + let a = currency.auditors[idx]; + if (a.baseUrl == this.props.url) { + auditorFound = true; + // Update auditor if already found by URL. + currency.auditors[idx] = newAuditor; + } + } + + if (!auditorFound) { + currency.auditors.push(newAuditor); + } + + await updateCurrency(currency); + + this.addDone(true); + } + + back() { + window.history.back(); + } + + render(): JSX.Element { + return ( + <div id="main"> + <p>Do you want to let <strong>{this.props.auditorPub}</strong> audit the currency "{this.props.currency}"?</p> + {this.addDone() ? + (<div>Auditor was added! You can also <a href={chrome.extension.getURL("/src/pages/auditors.html")}>view and edit</a> auditors.</div>) + : + (<div> + <button onClick={() => this.add()} className="pure-button pure-button-primary">Yes</button> + <button onClick={() => this.back()} className="pure-button">No</button> + </div>) + } + </div> + ); + } +} + +export function main() { + const walletPageUrl = URI(document.location.href); + const query: any = JSON.parse((URI.parseQuery(walletPageUrl.query()) as any)["req"]); + 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 }; + ReactDOM.render(<ConfirmAuditor {...args} />, document.getElementById("container")!); +} diff --git a/src/pages/auditors.tsx b/src/pages/auditors.tsx index b0bce8fd5..7cffec403 100644 --- a/src/pages/auditors.tsx +++ b/src/pages/auditors.tsx @@ -62,28 +62,39 @@ class CurrencyList extends React.Component<any, CurrencyListState> { } } + renderAuditors(c: CurrencyRecord): any { + if (c.auditors.length == 0) { + return <p>No trusted auditors for this currency.</p> + } + return ( + <div> + <p>Trusted Auditors:</p> + <ul> + {c.auditors.map(a => ( + <li>{a.baseUrl} <button className="pure-button button-destructive" onClick={() => this.confirmRemove(c, a)}>Remove</button> + <ul> + <li>valid until {new Date(a.expirationStamp).toString()}</li> + <li>public key {a.auditorPub}</li> + </ul> + </li> + ))} + </ul> + </div> + ); + } + render(): JSX.Element { let currencies = this.state.currencies; if (!currencies) { return <span>...</span>; } return ( - <div> + <div id="main"> {currencies.map(c => ( <div> <h1>Currency {c.name}</h1> <p>Displayed with {c.fractionalDigits} fractional digits.</p> - <p>Auditors:</p> - <ul> - {c.auditors.map(a => ( - <li>{a.baseUrl} (<button className="button-linky" onClick={() => this.confirmRemove(c, a)}>Remove</button>) - <ul> - <li>valid until {new Date(a.expirationStamp).toString()}</li> - <li>public key {a.auditorPub}</li> - </ul> - </li> - ))} - </ul> + <div>{this.renderAuditors(c)}</div> </div> ))} </div> diff --git a/src/pages/confirm-create-reserve.html b/src/pages/confirm-create-reserve.html index 341b786d8..77efc7036 100644 --- a/src/pages/confirm-create-reserve.html +++ b/src/pages/confirm-create-reserve.html @@ -14,68 +14,9 @@ <script src="/src/vendor/system-csp-production.src.js"></script> <script src="/src/moduleTrampoline.js"></script> + <link rel="icon" href="/img/icon.png"> - <style> - #main { - border: solid 1px black; - border-radius: 10px; - margin: auto; - max-width: 50%; - padding: 2em; - } - - button.accept { - background-color: #5757D2; - border: 1px solid black; - border-radius: 5px; - margin: 1em 0; - padding: 0.5em; - font-weight: bold; - color: white; - } - button.linky { - background:none!important; - border:none; - padding:0!important; - - font-family:arial,sans-serif; - color:#069; - text-decoration:underline; - cursor:pointer; - } - - - button.accept:disabled { - background-color: #dedbe8; - border: 1px solid white; - border-radius: 5px; - margin: 1em 0; - padding: 0.5em; - font-weight: bold; - color: #2C2C2C; - } - - input.url { - width: 25em; - } - - table { - border-collapse: collapse; - } - - td { - border-left: 1px solid black; - border-right: 1px solid black; - text-align: center; - padding: 0.3em; - } - - span.spacer { - padding-left: 0.5em; - padding-right: 0.5em; - } - - </style> + <link rel="stylesheet" type="text/css" href="/src/style/wallet.css"> </head> <body> |