Skip to content

Commit 73bc9a0

Browse files
committed
Refactor wallet handling to use DbWalletWithLegacy type
- Updated wallet construction logic across multiple components and hooks to utilize the DbWalletWithLegacy type for improved type safety. - Enhanced proxy data validation checks to ensure consistent handling of proxy-related logic. - Adjusted API routes to accommodate the new type, ensuring compatibility with existing wallet structures.
1 parent 242d18c commit 73bc9a0

File tree

14 files changed

+24
-17
lines changed

14 files changed

+24
-17
lines changed

src/components/pages/homepage/wallets/new-wallet-flow/ready/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { Button } from "@/components/ui/button";
2020
import ProgressIndicator from "@/components/pages/homepage/wallets/new-wallet-flow/shared/ProgressIndicator";
2121
import WalletFlowPageLayout from "@/components/pages/homepage/wallets/new-wallet-flow/shared/WalletFlowPageLayout";
2222
import { buildMultisigWallet } from "@/utils/common";
23+
import { DbWalletWithLegacy } from "@/types/wallet";
2324

2425
export default function PageSuccessWallet() {
2526
const router = useRouter();
@@ -36,7 +37,7 @@ export default function PageSuccessWallet() {
3637
);
3738

3839
// Build wallet with address and other computed fields
39-
const wallet = walletData ? buildMultisigWallet(walletData, network) : null;
40+
const wallet = walletData ? buildMultisigWallet(walletData as DbWalletWithLegacy, network) : null;
4041

4142
const handleViewWallets = () => {
4243
setLoading(true);

src/components/pages/wallet/governance/ballot/ballot.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default function BallotCard({
8181
);
8282

8383
// Check if we have valid proxy data (proxy enabled, selected, proxies exist, and selected proxy is found)
84-
const hasValidProxy = isProxyEnabled && selectedProxyId && proxies && proxies.length > 0 && proxies.find((p: any) => p.id === selectedProxyId);
84+
const hasValidProxy = !!(isProxyEnabled && selectedProxyId && proxies && proxies.length > 0 && proxies.find((p: any) => p.id === selectedProxyId));
8585

8686
// CreateBallot mutation
8787
const createBallot = api.ballot.create.useMutation();

src/components/pages/wallet/governance/card-info.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default function CardInfo({ appWallet, manualUtxos }: { appWallet: Wallet
132132
}, [isProxyEnabled, selectedProxyId, appWallet?.scriptCbor, network, proxies]);
133133

134134
// Use proxy DRep info only if proxy is enabled AND we have valid proxy data, otherwise use standard DRep info
135-
const hasValidProxyData = isProxyEnabled && proxyDrepId && proxies.length > 0 && proxies.find(p => p.id === selectedProxyId);
135+
const hasValidProxyData = !!(isProxyEnabled && proxyDrepId && proxies.length > 0 && proxies.find(p => p.id === selectedProxyId));
136136
const displayDrepId = hasValidProxyData ? proxyDrepId : currentDrepId;
137137
const displayDrepInfo = hasValidProxyData ? proxyDrepInfo : currentDrepInfo;
138138

src/components/pages/wallet/governance/drep/registerDrep.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default function RegisterDRep() {
4545
);
4646

4747
// Check if we have valid proxy data (proxy enabled, selected, proxies exist, and selected proxy is found)
48-
const hasValidProxy = isProxyEnabled && selectedProxyId && proxies && proxies.length > 0 && proxies.find((p: any) => p.id === selectedProxyId);
48+
const hasValidProxy = !!(isProxyEnabled && selectedProxyId && proxies && proxies.length > 0 && proxies.find((p: any) => p.id === selectedProxyId));
4949

5050
const [manualUtxos, setManualUtxos] = useState<UTxO[]>([]);
5151
const [formState, setFormState] = useState({

src/components/pages/wallet/governance/drep/retire.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default function Retire({ appWallet, manualUtxos }: { appWallet: Wallet;
3838
);
3939

4040
// Check if we have valid proxy data (proxy enabled, selected, proxies exist, and selected proxy is found)
41-
const hasValidProxy = isProxyEnabled && selectedProxyId && proxies && proxies.length > 0 && proxies.find((p: any) => p.id === selectedProxyId);
41+
const hasValidProxy = !!(isProxyEnabled && selectedProxyId && proxies && proxies.length > 0 && proxies.find((p: any) => p.id === selectedProxyId));
4242

4343
// Helper function to get multisig inputs (like in register component)
4444
const getMsInputs = useCallback(async (): Promise<{ utxos: UTxO[]; walletAddress: string }> => {

src/components/pages/wallet/governance/drep/updateDrep.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function UpdateDRep() {
4646
);
4747

4848
// Check if we have valid proxy data (proxy enabled, selected, proxies exist, and selected proxy is found)
49-
const hasValidProxy = isProxyEnabled && selectedProxyId && proxies && proxies.length > 0 && proxies.find((p: any) => p.id === selectedProxyId);
49+
const hasValidProxy = !!(isProxyEnabled && selectedProxyId && proxies && proxies.length > 0 && proxies.find((p: any) => p.id === selectedProxyId));
5050

5151
// Helper function to get multisig inputs (like in register component)
5252
const getMsInputs = useCallback(async (): Promise<{ utxos: UTxO[]; walletAddress: string }> => {

src/components/pages/wallet/governance/proposal/voteButtton.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default function VoteButton({
8888
);
8989

9090
// Check if we have valid proxy data (proxy enabled, selected, proxies exist, and selected proxy is found)
91-
const hasValidProxy = isProxyEnabled && selectedProxyId && proxies && proxies.length > 0 && proxies.find((p: any) => p.id === selectedProxyId);
91+
const hasValidProxy = !!(isProxyEnabled && selectedProxyId && proxies && proxies.length > 0 && proxies.find((p: any) => p.id === selectedProxyId));
9292

9393
async function voteProxy() {
9494
if (!hasValidProxy) {
@@ -120,14 +120,14 @@ export default function VoteButton({
120120
);
121121
proxyContract.proxyAddress = proxy.proxyAddress;
122122

123-
// Prepare vote
124-
const vote = {
123+
// Prepare vote data
124+
const voteData = {
125125
proposalId,
126126
voteKind: voteKind,
127127
};
128128

129129
// Vote using proxy
130-
const txBuilderResult = await proxyContract.voteProxyDrep([vote], utxos, multisigWallet?.getScript().address);
130+
const txBuilderResult = await proxyContract.voteProxyDrep([voteData], utxos, multisigWallet?.getScript().address);
131131

132132
await newTransaction({
133133
txBuilder: txBuilderResult,

src/hooks/useAppWallet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { buildWallet } from "./common";
44
import { useSiteStore } from "@/lib/zustand/site";
55
import { useRouter } from "next/router";
66
import { useWalletsStore } from "@/lib/zustand/wallets";
7+
import { DbWalletWithLegacy } from "@/types/wallet";
78

89
export default function useAppWallet() {
910
const router = useRouter();
@@ -21,7 +22,7 @@ export default function useAppWallet() {
2122
);
2223

2324
if (wallet) {
24-
return { appWallet: buildWallet(wallet, network, walletsUtxos[walletId]), isLoading };
25+
return { appWallet: buildWallet(wallet as DbWalletWithLegacy, network, walletsUtxos[walletId]), isLoading };
2526
}
2627

2728
return { appWallet: undefined, isLoading };

src/hooks/useMultisigWallet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { api } from "@/utils/api";
44
import { useSiteStore } from "@/lib/zustand/site";
55
import { useUserStore } from "@/lib/zustand/user";
66
import { buildMultisigWallet } from "./common";
7+
import { DbWalletWithLegacy } from "@/types/wallet";
78

89
export default function useMultisigWallet() {
910
const router = useRouter();
@@ -19,7 +20,7 @@ export default function useMultisigWallet() {
1920
},
2021
);
2122
if (wallet) {
22-
return { multisigWallet: buildMultisigWallet(wallet, network), wallet, isLoading };
23+
return { multisigWallet: buildMultisigWallet(wallet as DbWalletWithLegacy, network), wallet, isLoading };
2324
}
2425

2526
return { multisigWallet: undefined, wallet: undefined, isLoading };

src/hooks/useUserWallets.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useUserStore } from "@/lib/zustand/user";
22
import { useSiteStore } from "@/lib/zustand/site";
33
import { api } from "@/utils/api";
44
import { buildWallet } from "./common";
5+
import { DbWalletWithLegacy } from "@/types/wallet";
56

67
export default function useUserWallets() {
78
const network = useSiteStore((state) => state.network);
@@ -17,7 +18,7 @@ export default function useUserWallets() {
1718

1819
if (wallets) {
1920
_wallets = wallets.map((wallet) => {
20-
return buildWallet(wallet, network);
21+
return buildWallet(wallet as DbWalletWithLegacy, network);
2122
});
2223
return { wallets: _wallets, isLoading };
2324
}

0 commit comments

Comments
 (0)