From bc1c33e1ce4ea760fb87de0dee66ca22cce9b7b7 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 1 Feb 2022 13:26:56 -0300 Subject: [PATCH] fix remove provider from backup and #7167 --- .../taler-wallet-webextension/src/compat.ts | 1 + .../src/components/TransactionItem.tsx | 2 +- .../src/hooks/useExtendedPermissions.ts | 41 +++++++++++-------- .../src/wallet/ProviderDetailPage.tsx | 2 +- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/packages/taler-wallet-webextension/src/compat.ts b/packages/taler-wallet-webextension/src/compat.ts index 36846e615..b17d0fb80 100644 --- a/packages/taler-wallet-webextension/src/compat.ts +++ b/packages/taler-wallet-webextension/src/compat.ts @@ -81,6 +81,7 @@ export function getPermissionsApi(): CrossBrowserPermissionsApi { ) { return { addPermissionsListener: () => { + console.log("not supported for firefox") // Not supported yet. }, contains: myBrowser.permissions.contains, diff --git a/packages/taler-wallet-webextension/src/components/TransactionItem.tsx b/packages/taler-wallet-webextension/src/components/TransactionItem.tsx index db26abec6..89d6235aa 100644 --- a/packages/taler-wallet-webextension/src/components/TransactionItem.tsx +++ b/packages/taler-wallet-webextension/src/components/TransactionItem.tsx @@ -111,7 +111,7 @@ export function TransactionItem(props: { tx: Transaction }): VNode { debitCreditIndicator={"debit"} title={tx.targetPaytoUri} timestamp={tx.timestamp} - iconPath={imageRefresh} + iconPath={imageBank} pending={tx.pending} /> ); diff --git a/packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.ts b/packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.ts index 12a913b1f..6bf6a7bdf 100644 --- a/packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.ts +++ b/packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.ts @@ -19,11 +19,11 @@ import * as wxApi from "../wxApi"; import { getPermissionsApi } from "../compat"; import { getReadRequestPermissions } from "../permissions"; -export function useExtendedPermissions(): [boolean, () => void] { +export function useExtendedPermissions(): [boolean, () => Promise] { const [enabled, setEnabled] = useState(false); - const toggle = () => { - handleExtendedPerm(enabled, setEnabled) + const toggle = async () => { + return handleExtendedPerm(enabled, setEnabled) }; useEffect(() => { @@ -36,22 +36,29 @@ export function useExtendedPermissions(): [boolean, () => void] { return [enabled, toggle]; } -function handleExtendedPerm(isEnabled: boolean, onChange: (value: boolean) => void): void { +async function handleExtendedPerm(isEnabled: boolean, onChange: (value: boolean) => void): Promise { if (!isEnabled) { // We set permissions here, since apparently FF wants this to be done // as the result of an input event ... - getPermissionsApi().request(getReadRequestPermissions(), async (granted: boolean) => { - if (chrome.runtime.lastError) { - console.error("error requesting permissions"); - console.error(chrome.runtime.lastError); - onChange(false); - return; - } - console.log("permissions granted:", granted); - const res = await wxApi.setExtendedPermissions(granted); - onChange(res.newValue); - }); - } else { - wxApi.setExtendedPermissions(false).then(r => onChange(r.newValue)); + return new Promise((res) => { + getPermissionsApi().request(getReadRequestPermissions(), async (granted: boolean) => { + console.log("permissions granted:", granted); + if (chrome.runtime.lastError) { + console.error("error requesting permissions"); + console.error(chrome.runtime.lastError); + onChange(false); + return; + } + try { + const res = await wxApi.setExtendedPermissions(granted); + onChange(res.newValue); + } finally { + res() + } + + }); + }) } + await wxApi.setExtendedPermissions(false).then(r => onChange(r.newValue)); + return } diff --git a/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx b/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx index d14429ee5..239a7b31d 100644 --- a/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx @@ -83,7 +83,7 @@ export function ProviderDetailPage({ pid: providerURL, onBack }: Props): VNode { wxApi.syncOneProvider(providerURL)} - onDelete={async () => wxApi.syncOneProvider(providerURL).then(onBack)} + onDelete={async () => wxApi.removeProvider(providerURL).then(onBack)} onBack={onBack} onExtend={() => { null;