From e1369ff7e8fc02116b9c4261036f0e42e3423cf4 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 2 Dec 2019 00:42:40 +0100 Subject: the giant refactoring: split wallet into multiple parts --- src/webex/pages/add-auditor.tsx | 27 ++++++++++++++++++--------- src/webex/pages/pay.tsx | 13 ++++++------- src/webex/pages/popup.tsx | 20 ++++++++------------ src/webex/pages/refund.tsx | 6 ++---- src/webex/pages/return-coins.tsx | 6 +++--- src/webex/pages/tip.tsx | 10 ++++------ src/webex/pages/withdraw.tsx | 6 ++---- 7 files changed, 43 insertions(+), 45 deletions(-) (limited to 'src/webex/pages') diff --git a/src/webex/pages/add-auditor.tsx b/src/webex/pages/add-auditor.tsx index 7e3e06322..766db9c5d 100644 --- a/src/webex/pages/add-auditor.tsx +++ b/src/webex/pages/add-auditor.tsx @@ -23,7 +23,6 @@ import { CurrencyRecord } from "../../dbTypes"; import { getCurrencies, updateCurrency } from "../wxApi"; import React, { useState } from "react"; -import URI = require("urijs"); import { registerMountPage } from "../renderHtml"; interface ConfirmAuditorProps { @@ -118,14 +117,24 @@ function ConfirmAuditor(props: ConfirmAuditorProps) { registerMountPage(() => { - const walletPageUrl = new 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 walletPageUrl = new URL(document.location.href); + const url = walletPageUrl.searchParams.get("url"); + if (!url) { + throw Error("missign parameter (url)"); + } + const currency = walletPageUrl.searchParams.get("currency"); + if (!currency) { + throw Error("missing parameter (currency)"); + } + const auditorPub = walletPageUrl.searchParams.get("auditorPub"); + if (!auditorPub) { + throw Error("missing parameter (auditorPub)"); + } + const auditorStampStr = walletPageUrl.searchParams.get("expirationStamp"); + if (!auditorStampStr) { + throw Error("missing parameter (auditorStampStr)"); + } + const expirationStamp = Number.parseInt(auditorStampStr); const args = { url, currency, auditorPub, expirationStamp }; return ; }); diff --git a/src/webex/pages/pay.tsx b/src/webex/pages/pay.tsx index 7f2a174b7..cff2f9461 100644 --- a/src/webex/pages/pay.tsx +++ b/src/webex/pages/pay.tsx @@ -30,9 +30,8 @@ import { renderAmount, ProgressButton, registerMountPage } from "../renderHtml"; import * as wxApi from "../wxApi"; import React, { useState, useEffect } from "react"; -import URI = require("urijs"); -import * as Amounts from "../../amounts"; +import * as Amounts from "../../util/amounts"; function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) { const [payStatus, setPayStatus] = useState(); @@ -164,10 +163,10 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) { } registerMountPage(() => { - const url = new URI(document.location.href); - const query: any = URI.parseQuery(url.query()); - - let talerPayUri = query.talerPayUri; - + const url = new URL(document.location.href); + const talerPayUri = url.searchParams.get("talerPayUri"); + if (!talerPayUri) { + throw Error("invalid parameter"); + } return ; }); diff --git a/src/webex/pages/popup.tsx b/src/webex/pages/popup.tsx index 78b7374b3..27d5dddba 100644 --- a/src/webex/pages/popup.tsx +++ b/src/webex/pages/popup.tsx @@ -26,8 +26,8 @@ */ import * as i18n from "../../i18n"; -import { AmountJson } from "../../amounts"; -import * as Amounts from "../../amounts"; +import { AmountJson } from "../../util/amounts"; +import * as Amounts from "../../util/amounts"; import { HistoryEvent, @@ -44,9 +44,6 @@ import { import * as wxApi from "../wxApi"; import * as React from "react"; -import * as ReactDOM from "react-dom"; - -import URI = require("urijs"); function onUpdateNotification(f: () => void): () => void { const port = chrome.runtime.connect({ name: "notifications" }); @@ -339,7 +336,7 @@ function formatHistoryItem(historyItem: HistoryEvent) { ); case "confirm-reserve": { - const exchange = new URI(d.exchangeBaseUrl).host(); + const exchange = new URL(d.exchangeBaseUrl).host; const pub = abbrev(d.reservePub); return ( @@ -359,7 +356,7 @@ function formatHistoryItem(historyItem: HistoryEvent) { } case "depleted-reserve": { const exchange = d.exchangeBaseUrl - ? new URI(d.exchangeBaseUrl).host() + ? new URL(d.exchangeBaseUrl).host : "??"; const amount = renderAmount(d.requestedAmount); const pub = abbrev(d.reservePub); @@ -396,11 +393,10 @@ function formatHistoryItem(historyItem: HistoryEvent) { ); } case "tip": { - const tipPageUrl = new URI( - chrome.extension.getURL("/src/webex/pages/tip.html"), - ); - const params = { tip_id: d.tipId, merchant_domain: d.merchantDomain }; - const url = tipPageUrl.query(params).href(); + const tipPageUrl = new URL(chrome.extension.getURL("/src/webex/pages/tip.html")); + tipPageUrl.searchParams.set("tip_id", d.tipId); + tipPageUrl.searchParams.set("merchant_domain", d.merchantDomain); + const url = tipPageUrl.href; const tipLink = {i18n.str`tip`}; // i18n: Tip return ( diff --git a/src/webex/pages/refund.tsx b/src/webex/pages/refund.tsx index 79cadcdc9..5196c9ea6 100644 --- a/src/webex/pages/refund.tsx +++ b/src/webex/pages/refund.tsx @@ -22,7 +22,6 @@ import React, { useEffect, useState } from "react"; import ReactDOM from "react-dom"; -import URI = require("urijs"); import * as wxApi from "../wxApi"; import { PurchaseDetails } from "../../walletTypes"; @@ -76,8 +75,7 @@ function RefundStatusView(props: { talerRefundUri: string }) { } async function main() { - const url = new URI(document.location.href); - const query: any = URI.parseQuery(url.query()); + const url = new URL(document.location.href); const container = document.getElementById("container"); if (!container) { @@ -85,7 +83,7 @@ async function main() { return; } - const talerRefundUri = query.talerRefundUri; + const talerRefundUri = url.searchParams.get("talerRefundUri"); if (!talerRefundUri) { console.error("taler refund URI requred"); return; diff --git a/src/webex/pages/return-coins.tsx b/src/webex/pages/return-coins.tsx index b5d53c31e..be65b4121 100644 --- a/src/webex/pages/return-coins.tsx +++ b/src/webex/pages/return-coins.tsx @@ -25,8 +25,8 @@ * Imports. */ -import { AmountJson } from "../../amounts"; -import * as Amounts from "../../amounts"; +import { AmountJson } from "../../util/amounts"; +import * as Amounts from "../../util/amounts"; import { SenderWireInfos, @@ -35,7 +35,7 @@ import { import * as i18n from "../../i18n"; -import * as wire from "../../wire"; +import * as wire from "../../util/wire"; import { getBalance, diff --git a/src/webex/pages/tip.tsx b/src/webex/pages/tip.tsx index 148b8203c..ac904cf0d 100644 --- a/src/webex/pages/tip.tsx +++ b/src/webex/pages/tip.tsx @@ -23,7 +23,6 @@ import * as React from "react"; import * as ReactDOM from "react-dom"; -import URI = require("urijs"); import * as i18n from "../../i18n"; @@ -31,7 +30,7 @@ import { acceptTip, getReserveCreationInfo, getTipStatus } from "../wxApi"; import { WithdrawDetailView, renderAmount, ProgressButton } from "../renderHtml"; -import * as Amounts from "../../amounts"; +import * as Amounts from "../../util/amounts"; import { useState, useEffect } from "react"; import { TipStatus } from "../../walletTypes"; @@ -68,7 +67,7 @@ function TipDisplay(props: { talerTipUri: string }) { const accept = async () => { setLoading(true); - await acceptTip(props.talerTipUri); + await acceptTip(tipStatus.tipId); setFinished(true); }; @@ -101,9 +100,8 @@ function TipDisplay(props: { talerTipUri: string }) { async function main() { try { - const url = new URI(document.location.href); - const query: any = URI.parseQuery(url.query()); - const talerTipUri = query.talerTipUri; + const url = new URL(document.location.href); + const talerTipUri = url.searchParams.get("talerTipUri"); if (typeof talerTipUri !== "string") { throw Error("talerTipUri must be a string"); } diff --git a/src/webex/pages/withdraw.tsx b/src/webex/pages/withdraw.tsx index 39b27f2d8..6b7152dc2 100644 --- a/src/webex/pages/withdraw.tsx +++ b/src/webex/pages/withdraw.tsx @@ -32,7 +32,6 @@ import { WithdrawDetailView, renderAmount } from "../renderHtml"; import React, { useState, useEffect } from "react"; import * as ReactDOM from "react-dom"; -import URI = require("urijs"); import { getWithdrawDetails, acceptWithdrawal } from "../wxApi"; function NewExchangeSelection(props: { talerWithdrawUri: string }) { @@ -199,9 +198,8 @@ function NewExchangeSelection(props: { talerWithdrawUri: string }) { async function main() { try { - const url = new URI(document.location.href); - const query: any = URI.parseQuery(url.query()); - let talerWithdrawUri = query.talerWithdrawUri; + const url = new URL(document.location.href); + const talerWithdrawUri = url.searchParams.get("talerWithdrawUri"); if (!talerWithdrawUri) { throw Error("withdraw URI required"); } -- cgit v1.2.3