From c852aa92f84d0c18b1bd7361163498a542461d45 Mon Sep 17 00:00:00 2001 From: Pawel Zelawski Date: Thu, 10 Apr 2025 10:55:22 +0200 Subject: feat(client): implement react frontend application - Created main entry point `src/client/main.tsx`. - Created main `App` component `src/client/App.tsx`. - Implemented state management (`initial`, `waiting`, `success`, `failed`) using `useState`. - Implemented `handleStart` to call backend `/api/digiid/start` and transition to `waiting` state. - Implemented `useEffect` hook for polling backend `/api/digiid/status/:sessionId` in `waiting` state. - Updates UI state based on polling response (`success`/`failed`). - Handles polling errors and cleanup. - Implemented `handleReset` to return to `initial` state. - Implemented views for each state: - `initial`: Welcome message, Start button. - `waiting`: QR code display, status message, Cancel button. - `success`: Success message, verified address, address type, Start Over button. - `failed`: Failure message, error details, Try Again button. - Added client-side address type helper `getDigiByteAddressType` in `src/client/utils.ts`. - Added basic CSS styling in `src/client/index.css` with light/dark mode support. - Added frontend-related scripts (`dev:frontend`, `dev`, `build`, `lint`, `preview`) to `package.json`. - Fixed linter type issue with `setInterval` return value. --- src/client/utils.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/client/utils.ts (limited to 'src/client/utils.ts') diff --git a/src/client/utils.ts b/src/client/utils.ts new file mode 100644 index 0000000..cd9c8ba --- /dev/null +++ b/src/client/utils.ts @@ -0,0 +1,20 @@ +// Simple utility to determine DigiByte address type based on prefix + +export type DigiByteAddressType = 'DigiByte (DGB)' | 'DigiAsset (DGA)' | 'Unknown'; + +export function getDigiByteAddressType(address: string | undefined | null): DigiByteAddressType { + if (!address) { + return 'Unknown'; + } + if (address.startsWith('dgb1')) { + return 'DigiByte (DGB)'; + } + // Add other prefixes if DigiAssets use a distinct one, e.g., 'dga1' + // For now, assume non-DGB is DigiAsset, but this might need refinement + // depending on actual DigiAsset address formats. + else { + // Assuming DigiAssets might start differently or be the fallback + // This is a placeholder assumption. + return 'DigiAsset (DGA)'; // Placeholder - ADJUST BASED ON ACTUAL DGA PREFIX + } +} \ No newline at end of file -- cgit v1.2.3