From a160f3151440106f5dcee11e2c3af2a4d8ed036e Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 20 Dec 2022 15:23:33 -0300 Subject: [PATCH] fix #7291 --- .../src/platform/chrome.ts | 39 ++-- .../src/wallet/ExchangeSelection/index.ts | 6 +- .../src/wallet/ExchangeSelection/state.ts | 38 +++- .../src/wallet/ExchangeSelection/stories.tsx | 12 +- .../src/wallet/ExchangeSelection/views.tsx | 195 ++++++++++++++---- 5 files changed, 235 insertions(+), 55 deletions(-) diff --git a/packages/taler-wallet-webextension/src/platform/chrome.ts b/packages/taler-wallet-webextension/src/platform/chrome.ts index aac3b546c..7785e19ef 100644 --- a/packages/taler-wallet-webextension/src/platform/chrome.ts +++ b/packages/taler-wallet-webextension/src/platform/chrome.ts @@ -311,14 +311,17 @@ async function sendMessageToWalletBackground( chrome.runtime.sendMessage( { operation, payload, id: `id_${i++ % 1000}` }, (backgroundResponse) => { - logger.trace("BUG: got response from background", backgroundResponse); + logger.trace( + "BUG: got response from background", + backgroundResponse, + chrome.runtime.lastError, + ); if (chrome.runtime.lastError) { reject(chrome.runtime.lastError.message); + } else { + resolve(backgroundResponse); } - // const apiResponse = JSON.parse(resp) - resolve(backgroundResponse); - // return true to keep the channel open return true; }, @@ -355,13 +358,21 @@ function sendMessageToAllChannels(message: MessageFromBackend): void { function registerAllIncomingConnections(): void { chrome.runtime.onConnect.addListener((port) => { - allPorts.push(port); - port.onDisconnect.addListener((discoPort) => { - const idx = allPorts.indexOf(discoPort); - if (idx >= 0) { - allPorts.splice(idx, 1); - } - }); + try { + allPorts.push(port); + port.onDisconnect.addListener((discoPort) => { + try { + const idx = allPorts.indexOf(discoPort); + if (idx >= 0) { + allPorts.splice(idx, 1); + } + } catch (e) { + logger.error("error trying to remove connection", e); + } + }); + } catch (e) { + logger.error("error trying to save incoming connection", e); + } }); } @@ -375,7 +386,11 @@ function listenToAllChannels( chrome.runtime.onMessage.addListener((m, s, c) => { cb(m, s, (apiResponse) => { logger.trace("BUG: sending response to client", apiResponse); - c(apiResponse); + try { + c(apiResponse); + } catch (e) { + logger.error("wallet operation ended with error", e); + } }); // keep the connection open diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts index 1bb4fb314..10e44ce7d 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts @@ -77,7 +77,11 @@ export namespace State { export interface Comparing extends BaseInfo { status: "comparing"; - pairTimeline: DenomOperationMap; + coinOperationTimeline: DenomOperationMap; + wireFeeTimeline: Record; + globalFeeTimeline: FeeDescriptionPair[]; + missingWireTYpe: string[]; + newWireType: string[]; onReset: ButtonHandler; onSelect: ButtonHandler; } diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts index 378556b94..3c10febd9 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts @@ -155,7 +155,7 @@ export function useComponentState({ } //this may be expensive, useMemo - const pairTimeline: DenomOperationMap = { + const coinOperationTimeline: DenomOperationMap = { deposit: createPairTimeline( selected.denomFees.deposit, original.denomFees.deposit, @@ -174,6 +174,36 @@ export function useComponentState({ ), }; + const globalFeeTimeline = createPairTimeline( + selected.globalFees, + original.globalFees, + ); + + const allWireType = Object.keys(selected.transferFees).concat( + Object.keys(original.transferFees), + ); + + const wireFeeTimeline: Record = {}; + + const missingWireTYpe: string[] = []; + const newWireType: string[] = []; + + for (const wire of allWireType) { + const selectedWire = selected.transferFees[wire]; + const originalWire = original.transferFees[wire]; + + if (!selectedWire) { + newWireType.push(wire); + continue; + } + if (!originalWire) { + missingWireTYpe.push(wire); + continue; + } + + wireFeeTimeline[wire] = createPairTimeline(selectedWire, originalWire); + } + return { status: "comparing", exchanges: { @@ -205,6 +235,10 @@ export function useComponentState({ }, }, selected, - pairTimeline, + coinOperationTimeline, + wireFeeTimeline, + globalFeeTimeline, + missingWireTYpe, + newWireType, }; } diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/stories.tsx b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/stories.tsx index 3706359a8..05765b50a 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/stories.tsx @@ -120,12 +120,16 @@ export const ComparingBitcoin = createExample(ComparingView, { onShowTerms: {}, onSelect: {}, error: undefined, - pairTimeline: { + coinOperationTimeline: { deposit: [], refresh: [], refund: [], withdraw: [], }, + globalFeeTimeline: [], + newWireType: [], + missingWireTYpe: [], + wireFeeTimeline: {}, }); export const ComparingKudos = createExample(ComparingView, { exchanges: { @@ -144,12 +148,16 @@ export const ComparingKudos = createExample(ComparingView, { onShowTerms: {}, onSelect: {}, error: undefined, - pairTimeline: { + coinOperationTimeline: { deposit: [], refresh: [], refund: [], withdraw: [], }, + globalFeeTimeline: [], + newWireType: [], + missingWireTYpe: [], + wireFeeTimeline: {}, }); function timelineExample() { diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/views.tsx b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/views.tsx index 95ab55261..26ff2c0d3 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/views.tsx @@ -178,7 +178,11 @@ export function ComparingView({ selected, onReset, onSelect, - pairTimeline, + coinOperationTimeline, + globalFeeTimeline, + wireFeeTimeline, + missingWireTYpe, + newWireType, onShowPrivacy, onShowTerms, }: State.Comparing): VNode { @@ -249,8 +253,15 @@ export function ComparingView({

- Operations + Coin operations

+

+ + Every operation in this section may be different by denomination + value and is valid for a period of time. The exchange will charge + the indicated amount every time a coin is used in such operation. + +

Deposits

@@ -274,7 +285,7 @@ export function ComparingView({ Number(a) - Number(b)} /> @@ -290,7 +301,10 @@ export function ComparingView({ Denomination - Fee + Current + + + Selected Until @@ -299,7 +313,7 @@ export function ComparingView({ Number(a) - Number(b)} /> @@ -315,7 +329,10 @@ export function ComparingView({ Denomination - Fee + Current + + + Selected Until @@ -324,7 +341,7 @@ export function ComparingView({ Number(a) - Number(b)} /> @@ -340,7 +357,10 @@ export function ComparingView({ Denomination - Fee + Current + + + Selected Until @@ -349,12 +369,140 @@ export function ComparingView({ Number(a) - Number(b)} /> {" "}
+
+

+ Transfer operations +

+

+ + Every operation in this section may be different by transfer type + and is valid for a period of time. The exchange will charge the + indicated amount every time a transfer is made. + +

+ {missingWireTYpe.map((type) => { + return ( +

+ Wire {type} is not supported for this exchange. +

+ ); + })} + {newWireType.map((type) => { + return ( + +

+ Wire {type} is not supported for the previous exchange. +

+ + + +   + + Operation + + + Fee + + + Until + + + + + + + +
+ ); + })} + {Object.entries(wireFeeTimeline).map(([type, fees], idx) => { + return ( + +

{type}

+ + + +   + + Operation + + + Current + + + Selected + + + Until + + + + + a.localeCompare(b)} + /> + + +
+ ); + })} +
+
+

+ Wallet operations +

+

+ + Every operation in this section may be different by transfer type + and is valid for a period of time. The exchange will charge the + indicated amount every time a transfer is made. + +

+ + + +   + + Feature + + + Current + + + Selected + + + Until + + + + + a.localeCompare(b)} + /> + + +
+
+ + + + +