From a7bfff65be03808db611e7f8e093d64698f23368 Mon Sep 17 00:00:00 2001 From: QSchlegel Date: Fri, 9 Jan 2026 14:56:11 +0100 Subject: [PATCH] Update wallet handling and enhance error management - Improved address fetching logic in the Retire component to accommodate both legacy and SDK wallets, ensuring better compatibility. - Enhanced error handling for missing addresses and scripts, providing clearer feedback to users during transaction processes. - Added new references in drepMetadata for improved metadata handling. --- .dockerignore | 3 + Dockerfile.dev | 22 +++++ docker/ensure-roles.sh | 18 ++++ docker/fix-crowdfund-rls.sh | 14 ++++ docker/init-db.sh | 9 ++ .../wallet/governance/drep/drepMetadata.tsx | 2 + .../pages/wallet/governance/drep/retire.tsx | 82 +++++++++++++------ 7 files changed, 127 insertions(+), 23 deletions(-) create mode 100644 Dockerfile.dev create mode 100755 docker/ensure-roles.sh create mode 100755 docker/fix-crowdfund-rls.sh create mode 100755 docker/init-db.sh diff --git a/.dockerignore b/.dockerignore index bd9cc2b..32f1946 100644 --- a/.dockerignore +++ b/.dockerignore @@ -62,3 +62,6 @@ tsconfig.tsbuildinfo + + + diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..aaf893e --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,22 @@ +FROM node:20-alpine + +# Install PostgreSQL client tools for health checks +RUN apk add --no-cache postgresql-client + +# Set working directory +WORKDIR /app + +# Copy package files +COPY package.json package-lock.json* ./ + +# Copy Prisma schema (needed for postinstall script) +COPY prisma ./prisma + +# Install dependencies (postinstall will run prisma generate) +RUN npm ci + +# Expose port +EXPOSE 3000 + +# Default command (can be overridden in docker-compose) +CMD ["npm", "run", "dev"] diff --git a/docker/ensure-roles.sh b/docker/ensure-roles.sh new file mode 100755 index 0000000..fafa8b1 --- /dev/null +++ b/docker/ensure-roles.sh @@ -0,0 +1,18 @@ +#!/bin/sh +set -e + +echo "Ensuring required database roles exist..." + +# Connect to PostgreSQL and ensure required roles exist +# This is a placeholder - adjust based on your actual requirements +psql "${DATABASE_URL}" -c " +DO \$\$ +BEGIN + -- Add any role creation logic here if needed + -- Example: CREATE ROLE IF NOT EXISTS app_user; + NULL; +END +\$\$; +" || true + +echo "Database roles check complete." diff --git a/docker/fix-crowdfund-rls.sh b/docker/fix-crowdfund-rls.sh new file mode 100755 index 0000000..17d1b53 --- /dev/null +++ b/docker/fix-crowdfund-rls.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +echo "Applying Crowdfund RLS fixes..." + +# This script fixes Row Level Security (RLS) issues with the Crowdfund table +# Adjust the SQL based on your actual schema requirements +psql "${DATABASE_URL}" -c " +-- Add any RLS policy fixes here +-- Example: ALTER TABLE \"Crowdfund\" ENABLE ROW LEVEL SECURITY; +SELECT 1; +" || true + +echo "Crowdfund RLS fixes applied." diff --git a/docker/init-db.sh b/docker/init-db.sh new file mode 100755 index 0000000..b4d7fa7 --- /dev/null +++ b/docker/init-db.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +echo "Initializing database..." + +# This script runs automatically when PostgreSQL container starts for the first time +# Add any custom initialization SQL here if needed + +echo "Database initialization complete." diff --git a/src/components/pages/wallet/governance/drep/drepMetadata.tsx b/src/components/pages/wallet/governance/drep/drepMetadata.tsx index 4137d3f..01452a5 100644 --- a/src/components/pages/wallet/governance/drep/drepMetadata.tsx +++ b/src/components/pages/wallet/governance/drep/drepMetadata.tsx @@ -59,6 +59,8 @@ export async function getDRepMetadata( "@context": { GovernanceMetadata: "CIP100:GovernanceMetadataReference", Other: "CIP100:OtherReference", + Link: "CIP100:OtherReference", + Identity: "CIP100:OtherReference", label: "CIP100:reference-label", uri: "CIP100:reference-uri", referenceHash: { diff --git a/src/components/pages/wallet/governance/drep/retire.tsx b/src/components/pages/wallet/governance/drep/retire.tsx index 7e2c00b..4d723b8 100644 --- a/src/components/pages/wallet/governance/drep/retire.tsx +++ b/src/components/pages/wallet/governance/drep/retire.tsx @@ -155,7 +155,17 @@ export default function Retire({ appWallet, manualUtxos }: { appWallet: Wallet; try { const blockchainProvider = getProvider(network); - const utxos = await blockchainProvider.fetchAddressUTxOs(multisigWallet.getScript().address); + // For legacy wallets, use appWallet address; for SDK wallets, use multisig address + const addressToFetch = multisigWallet?.getScript().address || appWallet.address; + if (!addressToFetch) { + toast({ + title: "Address Error", + description: "No address available to fetch UTxOs", + variant: "destructive", + }); + return; + } + const utxos = await blockchainProvider.fetchAddressUTxOs(addressToFetch); const assetMap = new Map(); assetMap.set("lovelace", "5000000"); @@ -171,32 +181,58 @@ export default function Retire({ appWallet, manualUtxos }: { appWallet: Wallet; const txBuilder = getTxBuilder(network); - const drepData = multisigWallet?.getDRep(appWallet); - if (!drepData) { - toast({ - title: "DRep Error", - description: "DRep not found", - variant: "destructive", - }); - return; - } - const { dRepId, drepCbor } = drepData; - - const scriptCbor = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getScript().scriptCbor : appWallet.scriptCbor; - const changeAddress = multisigWallet?.getKeysByRole(3) ? multisigWallet?.getScript().address : appWallet.address; + // For legacy wallets (no multisigWallet), use appWallet values directly (preserves input order) + // For SDK wallets, use multisigWallet to compute DRep ID and script + let dRepId: string; + let drepCbor: string; + let scriptCbor: string; + let changeAddress: string; - if (!changeAddress) { - toast({ - title: "Address Error", - description: "Change address not found", - variant: "destructive", - }); - return; + if (multisigWallet) { + const drepData = multisigWallet.getDRep(appWallet); + if (!drepData) { + toast({ + title: "DRep Error", + description: "DRep not found", + variant: "destructive", + }); + return; + } + dRepId = drepData.dRepId; + drepCbor = drepData.drepCbor; + const multisigScript = multisigWallet.getScript(); + const multisigScriptCbor = multisigScript.scriptCbor; + const appScriptCbor = appWallet.scriptCbor; + if (!multisigScriptCbor && !appScriptCbor) { + toast({ + title: "Script Error", + description: "Script CBOR not found", + variant: "destructive", + }); + return; + } + scriptCbor = multisigWallet.getKeysByRole(3) ? (multisigScriptCbor || appScriptCbor!) : (appScriptCbor || multisigScriptCbor!); + changeAddress = multisigScript.address; + } else { + // Legacy wallet: use appWallet values (computed with input order preserved) + if (!appWallet.dRepId || !appWallet.scriptCbor) { + toast({ + title: "DRep Error", + description: "DRep ID or script not found for legacy wallet", + variant: "destructive", + }); + return; + } + dRepId = appWallet.dRepId; + drepCbor = appWallet.scriptCbor; // Use payment script CBOR for legacy wallets + scriptCbor = appWallet.scriptCbor; + changeAddress = appWallet.address; } - if (!scriptCbor) { + + if (!scriptCbor || !changeAddress) { toast({ title: "Script Error", - description: "Script not found", + description: "Script or change address not found", variant: "destructive", }); return;