From 920a384e90bc35f262361920aa8ddd1046abac34 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 23 Apr 2024 00:16:35 +0200 Subject: wallet-core: avoid use of plain 'id' field, misc. fixes --- .../src/components/WalletActivity.tsx | 1318 ++++++++++++-------- .../taler-wallet-webextension/src/wxBackend.ts | 5 - 2 files changed, 792 insertions(+), 531 deletions(-) (limited to 'packages/taler-wallet-webextension') diff --git a/packages/taler-wallet-webextension/src/components/WalletActivity.tsx b/packages/taler-wallet-webextension/src/components/WalletActivity.tsx index 1c566c3e4..69a2c0675 100644 --- a/packages/taler-wallet-webextension/src/components/WalletActivity.tsx +++ b/packages/taler-wallet-webextension/src/components/WalletActivity.tsx @@ -22,7 +22,7 @@ import { TalerErrorDetail, TaskProgressNotification, WalletNotification, - assertUnreachable + assertUnreachable, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; @@ -37,61 +37,80 @@ import { WxApiType } from "../wxApi.js"; import { Modal } from "./Modal.js"; import { Time } from "./Time.js"; -interface Props extends JSX.HTMLAttributes { -} +interface Props extends JSX.HTMLAttributes {} -export function WalletActivity({ }: Props): VNode { - const { i18n } = useTranslationContext() - const [settings, updateSettings] = useSettings() +export function WalletActivity({}: Props): VNode { + const { i18n } = useTranslationContext(); + const [settings, updateSettings] = useSettings(); const api = useBackendContext(); useEffect(() => { - document.body.style.marginBottom = "250px" + document.body.style.marginBottom = "250px"; return () => { - document.body.style.marginBottom = "0px" - } - }) - const [table, setTable] = useState<"tasks" | "events">("tasks") + document.body.style.marginBottom = "0px"; + }; + }); + const [table, setTable] = useState<"tasks" | "events">("tasks"); return ( -
-
+
+
-
{ - updateSettings("showWalletActivity", false) - }}> +
{ + updateSettings("showWalletActivity", false); + }} + > close
- - -
{(function (): VNode { switch (table) { case "events": { - return + return ; } case "tasks": { - return + return ; } default: { - assertUnreachable(table) + assertUnreachable(table); } } })()} @@ -99,398 +118,554 @@ export function WalletActivity({ }: Props): VNode { ); } -interface MoreInfoPRops { events: (WalletNotification & { when: AbsoluteTime })[], onClick: (content: VNode) => void } +interface MoreInfoPRops { + events: (WalletNotification & { when: AbsoluteTime })[]; + onClick: (content: VNode) => void; +} type Notif = { id: string; events: (WalletNotification & { when: AbsoluteTime })[]; description: string; start: AbsoluteTime; end: AbsoluteTime; - reference: { - eventType: NotificationType, - referenceType: "task" | "transaction" | "operation" | "exchange", - id: string; - } | undefined, + reference: + | { + eventType: NotificationType; + referenceType: "task" | "transaction" | "operation" | "exchange"; + id: string; + } + | undefined; MoreInfo: (p: MoreInfoPRops) => VNode; -} +}; function ShowBalanceChange({ events }: MoreInfoPRops): VNode { if (!events.length) return ; const not = events[0]; if (not.type !== NotificationType.BalanceChange) return ; - return -
Transaction
-
- {not.hintTransactionId.substring(0, 10)} -
-
+ return ( + +
Transaction
+
+ + {not.hintTransactionId.substring(0, 10)} + +
+
+ ); } function ShowBackupOperationError({ events, onClick }: MoreInfoPRops): VNode { if (!events.length) return ; const not = events[0]; if (not.type !== NotificationType.BackupOperationError) return ; - return -
Error
-
- { - e.preventDefault(); - const error = not.error - onClick( -
-
Code
-
{TalerErrorCode[error.code]} ({error.code})
-
Hint
-
{error.hint ?? "--"}
-
Time
-
-
-
-            {JSON.stringify(error, undefined, 2)}
-          
-
) - }}>{TalerErrorCode[not.error.code]}
-
-
-} - -function ShowTransactionStateTransition({ events, onClick }: MoreInfoPRops): VNode { - if (!events.length) return ; - const not = events[0]; - if (not.type !== NotificationType.TransactionStateTransition) return ; - return -
Old state
-
- {not.oldTxState.major} - {not.oldTxState.minor ?? ""} -
-
New state
-
- {not.newTxState.major} - {not.newTxState.minor ?? ""} -
-
Transaction
-
- {not.transactionId.substring(0, 10)} -
- {not.errorInfo ? + return ( +
Error
- { - if (!not.errorInfo) return; - e.preventDefault(); - const error = not.errorInfo; - onClick( -
-
Code
-
{TalerErrorCode[error.code]} ({error.code})
-
Hint
-
{error.hint ?? "--"}
-
Message
-
{error.message ?? "--"}
-
-
) - - }}>{TalerErrorCode[not.errorInfo.code]}
+ { + e.preventDefault(); + const error = not.error; + onClick( + +
+
Code
+
+ {TalerErrorCode[error.code]} ({error.code}) +
+
Hint
+
{error.hint ?? "--"}
+
Time
+
+
+
+
+                  {JSON.stringify(error, undefined, 2)}
+                
+
, + ); + }} + > + {TalerErrorCode[not.error.code]} +
-
: undefined} -
Experimental
-
-
-        {JSON.stringify(not.experimentalUserData, undefined, 2)}
-      
-
- - -
+
+ ); } -function ShowExchangeStateTransition({ events, onClick }: MoreInfoPRops): VNode { + +function ShowTransactionStateTransition({ + events, + onClick, +}: MoreInfoPRops): VNode { if (!events.length) return ; const not = events[0]; - if (not.type !== NotificationType.ExchangeStateTransition) return ; - return -
Exchange
-
- {not.exchangeBaseUrl} -
- {not.oldExchangeState && not.newExchangeState.exchangeEntryStatus !== not.oldExchangeState?.exchangeEntryStatus && -
Entry status
+ if (not.type !== NotificationType.TransactionStateTransition) + return ; + return ( + +
Old state
- from {not.oldExchangeState.exchangeEntryStatus} to {not.newExchangeState.exchangeEntryStatus} + {not.oldTxState.major} - {not.oldTxState.minor ?? ""}
-
} - {not.oldExchangeState && not.newExchangeState.exchangeUpdateStatus !== not.oldExchangeState?.exchangeUpdateStatus && -
Update status
+
New state
- from {not.oldExchangeState.exchangeUpdateStatus} to {not.newExchangeState.exchangeUpdateStatus} + {not.newTxState.major} - {not.newTxState.minor ?? ""}
-
} - {not.oldExchangeState && not.newExchangeState.tosStatus !== not.oldExchangeState?.tosStatus && -
Tos status
+
Transaction
- from {not.oldExchangeState.tosStatus} to {not.newExchangeState.tosStatus} + + {not.transactionId.substring(0, 10)} +
-
} -
+ {not.errorInfo ? ( + +
Error
+
+ { + if (!not.errorInfo) return; + e.preventDefault(); + const error = not.errorInfo; + onClick( + +
+
Code
+
+ {TalerErrorCode[error.code]} ({error.code}) +
+
Hint
+
{error.hint ?? "--"}
+
Message
+
{error.message ?? "--"}
+
+
, + ); + }} + > + {TalerErrorCode[not.errorInfo.code]} +
+
+
+ ) : undefined} +
Experimental
+
+
+          {JSON.stringify(not.experimentalUserData, undefined, 2)}
+        
+
+
+ ); +} +function ShowExchangeStateTransition({ + events, + onClick, +}: MoreInfoPRops): VNode { + if (!events.length) return ; + const not = events[0]; + if (not.type !== NotificationType.ExchangeStateTransition) + return ; + return ( + +
Exchange
+
{not.exchangeBaseUrl}
+ {not.oldExchangeState && + not.newExchangeState.exchangeEntryStatus !== + not.oldExchangeState?.exchangeEntryStatus && ( + +
Entry status
+
+ from {not.oldExchangeState.exchangeEntryStatus} to{" "} + {not.newExchangeState.exchangeEntryStatus} +
+
+ )} + {not.oldExchangeState && + not.newExchangeState.exchangeUpdateStatus !== + not.oldExchangeState?.exchangeUpdateStatus && ( + +
Update status
+
+ from {not.oldExchangeState.exchangeUpdateStatus} to{" "} + {not.newExchangeState.exchangeUpdateStatus} +
+
+ )} + {not.oldExchangeState && + not.newExchangeState.tosStatus !== not.oldExchangeState?.tosStatus && ( + +
Tos status
+
+ from {not.oldExchangeState.tosStatus} to{" "} + {not.newExchangeState.tosStatus} +
+
+ )} +
+ ); } -type ObservaNotifWithTime = ((TaskProgressNotification | RequestProgressNotification) & { +type ObservaNotifWithTime = ( + | TaskProgressNotification + | RequestProgressNotification +) & { when: AbsoluteTime; -}) +}; function ShowObservabilityEvent({ events, onClick }: MoreInfoPRops): VNode { // let prev: ObservaNotifWithTime; - const asd = events.map(not => { - if (not.type !== NotificationType.RequestObservabilityEvent && not.type !== NotificationType.TaskObservabilityEvent) return ; + const asd = events.map((not) => { + if ( + not.type !== NotificationType.RequestObservabilityEvent && + not.type !== NotificationType.TaskObservabilityEvent + ) + return ; const title = (function () { switch (not.event.type) { case ObservabilityEventType.HttpFetchFinishError: case ObservabilityEventType.HttpFetchFinishSuccess: - case ObservabilityEventType.HttpFetchStart: return "HTTP Request" + case ObservabilityEventType.HttpFetchStart: + return "HTTP Request"; case ObservabilityEventType.DbQueryFinishSuccess: case ObservabilityEventType.DbQueryFinishError: - case ObservabilityEventType.DbQueryStart: return "Database" + case ObservabilityEventType.DbQueryStart: + return "Database"; case ObservabilityEventType.RequestFinishSuccess: case ObservabilityEventType.RequestFinishError: - case ObservabilityEventType.RequestStart: return "Wallet" + case ObservabilityEventType.RequestStart: + return "Wallet"; case ObservabilityEventType.CryptoFinishSuccess: case ObservabilityEventType.CryptoFinishError: - case ObservabilityEventType.CryptoStart: return "Crypto" - case ObservabilityEventType.TaskStart: return "Task start" - case ObservabilityEventType.TaskStop: return "Task stop" - case ObservabilityEventType.TaskReset: return "Task reset" - case ObservabilityEventType.ShepherdTaskResult: return "Schedule" - case ObservabilityEventType.DeclareTaskDependency: return "Task dependency" - case ObservabilityEventType.Message: return "Message" + case ObservabilityEventType.CryptoStart: + return "Crypto"; + case ObservabilityEventType.TaskStart: + return "Task start"; + case ObservabilityEventType.TaskStop: + return "Task stop"; + case ObservabilityEventType.TaskReset: + return "Task reset"; + case ObservabilityEventType.ShepherdTaskResult: + return "Schedule"; + case ObservabilityEventType.DeclareTaskDependency: + return "Task dependency"; + case ObservabilityEventType.Message: + return "Message"; } })(); - return - - }) - return - - - - - - - - {asd} - -
EventInfoStartEnd
+ return ( + + ); + }); + return ( + + + + + + + + {asd} +
EventInfoStartEnd
+ ); } -function ShowObervavilityDetails({ title, notif, onClick, prev }: { title: string, notif: ObservaNotifWithTime, prev?: ObservaNotifWithTime, onClick: (content: VNode) => void }): VNode { +function ShowObervavilityDetails({ + title, + notif, + onClick, + prev, +}: { + title: string; + notif: ObservaNotifWithTime; + prev?: ObservaNotifWithTime; + onClick: (content: VNode) => void; +}): VNode { switch (notif.event.type) { case ObservabilityEventType.HttpFetchStart: case ObservabilityEventType.HttpFetchFinishError: case ObservabilityEventType.HttpFetchFinishSuccess: { - return - { - e.preventDefault(); - onClick( -
-              {JSON.stringify({ event: notif, prev }, undefined, 2)}
-            
-
); - }}>{title}
- - {notif.event.url} { - prev?.event.type === ObservabilityEventType.HttpFetchFinishSuccess ? `(${prev.event.status})` - : prev?.event.type === ObservabilityEventType.HttpFetchFinishError ? { + return ( + + + { e.preventDefault(); - if (prev.event.type !== ObservabilityEventType.HttpFetchFinishError) return; - const error = prev.event.error - onClick( -
-
Code
-
{TalerErrorCode[error.code]} ({error.code})
-
Hint
-
{error.hint ?? "--"}
-
Time
-
-
-
-                    {JSON.stringify(error, undefined, 2)}
-                  
- -
) - }}>fail
: undefined - } - -
); - }}>{title} - - {notif.event.location} {notif.event.name} - - -
); - }}>{title} - - {notif.event.taskId} - - -
); - }}>{title} - - {notif.event.resultType} - - -
); - }}>{title} - - {notif.event.operation} - - -
); - }}>{title} - - {notif.event.type} - - -