11"use client" ;
22
33import React , { useEffect , useState } from "react" ;
4+ import toast , { Toaster } from "react-hot-toast" ;
45import {
56 Wallet as WalletIcon ,
67 PlusCircle ,
@@ -27,7 +28,7 @@ type WalletUI = Wallet & {
2728
2829export const DashboardPage : React . FC < DashboardPageProps > = ( { username } ) => {
2930 const { account, isConnected } = useStarknetWallet ( ) ;
30- const { getUserWallets, addWallet } = useStarknetContract ( ) ;
31+ const { getUserWallets, addWallet, removeWallet } = useStarknetContract ( ) ;
3132
3233 const [ wallets , setWallets ] = useState < WalletUI [ ] > ( [ ] ) ;
3334 const [ isLoadingWallets , setIsLoadingWallets ] = useState < boolean > ( true ) ;
@@ -84,6 +85,7 @@ export const DashboardPage: React.FC<DashboardPageProps> = ({ username }) => {
8485 } catch ( err ) {
8586 console . error ( "Failed to fetch wallets:" , err ) ;
8687 if ( mounted ) setError ( "Failed to fetch wallets. Please try again." ) ;
88+ toast . error ( "Failed to fetch wallets." ) ;
8789 } finally {
8890 if ( mounted ) setIsLoadingWallets ( false ) ;
8991 }
@@ -99,32 +101,33 @@ export const DashboardPage: React.FC<DashboardPageProps> = ({ username }) => {
99101 const copyToClipboard = ( text : string ) => {
100102 navigator . clipboard . writeText ( text ) ;
101103 setCopied ( text ) ;
104+ toast . success ( "Copied" ) ;
102105 setTimeout ( ( ) => setCopied ( null ) , 1500 ) ;
103106 } ;
104107
105108 // Add wallet (UI + contract)
106109 const handleAddWallet = async ( ) => {
107110 const { chainId, address, memo, tag, metadata } = newWalletForm ;
108111 if ( ! chainId || ! address ) {
109- alert ( "Please select chain and enter wallet address." ) ;
112+ toast . error ( "Please select chain and enter wallet address." ) ;
110113 return ;
111114 }
112115 if ( ! isConnected || ! account ) {
113- alert ( "Please connect your wallet to add linked wallets." ) ;
116+ toast . error ( "Please connect your wallet to add linked wallets." ) ;
114117 return ;
115118 }
116119
117120 const selected = chainOptions . find ( ( c ) => c . id === chainId ) ;
118121 if ( ! selected ) {
119- alert ( "Selected chain not found." ) ;
122+ toast . error ( "Selected chain not found." ) ;
123+
120124 return ;
121125 }
122126
123127 setIsAddingWallet ( true ) ;
124128 setError ( null ) ;
125129
126130 try {
127- // Call contract to add wallet
128131 await addWallet (
129132 account ,
130133 selected . symbol ,
@@ -134,7 +137,6 @@ export const DashboardPage: React.FC<DashboardPageProps> = ({ username }) => {
134137 metadata || undefined
135138 ) ;
136139
137- // Update local state after successful transaction
138140 const newEntry : WalletUI = {
139141 chainSymbol : selected . symbol ,
140142 address,
@@ -153,10 +155,11 @@ export const DashboardPage: React.FC<DashboardPageProps> = ({ username }) => {
153155 tag : "" ,
154156 metadata : "" ,
155157 } ) ;
156- alert ( "Wallet added successfully!" ) ;
158+ toast . success ( "Wallet added successfully!" ) ;
157159 } catch ( err ) {
158160 console . error ( "Add wallet failed:" , err ) ;
159161 setError ( "Failed to add wallet. See console for details." ) ;
162+ toast . error ( "Failed to add wallet." ) ;
160163 } finally {
161164 setIsAddingWallet ( false ) ;
162165 }
@@ -165,12 +168,13 @@ export const DashboardPage: React.FC<DashboardPageProps> = ({ username }) => {
165168 // Remove wallet (UI + contract)
166169 const handleRemoveWallet = async ( addressToRemove : string ) => {
167170 if ( ! isConnected || ! account ) {
168- alert ( "Please connect your wallet to remove linked wallets." ) ;
171+ toast . error ( "Please connect your wallet to remove linked wallets." ) ;
169172 return ;
170173 }
171174
172175 const found = wallets . find ( ( w ) => w . address === addressToRemove ) ;
173176 if ( ! found ) return ;
177+
174178 const selectedChain = chainOptions . find (
175179 ( c ) => c . symbol . toLowerCase ( ) === found . chainSymbol . toLowerCase ( )
176180 ) ;
@@ -185,18 +189,17 @@ export const DashboardPage: React.FC<DashboardPageProps> = ({ username }) => {
185189 setError ( null ) ;
186190
187191 try {
188- // TODO: Replace with actual contract remove call
189- // const tx = await removeWalletFromUser({ owner: account, chainSymbol: found.chainSymbol, address: addressToRemove });
190- // await waitForTx(tx);
192+ await removeWallet ( account , found . chainSymbol ) ;
191193
192- // Update local state
193194 setWallets ( ( prev ) => prev . filter ( ( w ) => w . address !== addressToRemove ) ) ;
194- alert (
195- "Wallet removed (UI-only). Replace placeholder with on-chain call."
196- ) ;
195+
196+ toast . success ( `Removed from ${ found . chainName } ` ) ;
197197 } catch ( err ) {
198198 console . error ( "Remove wallet failed:" , err ) ;
199- setError ( "Failed to remove wallet. See console for details." ) ;
199+ const errorMsg =
200+ err instanceof Error ? err . message : "Failed to remove wallet" ;
201+ setError ( errorMsg ) ;
202+ toast . error ( `Failed to remove wallet: ${ errorMsg } ` ) ;
200203 } finally {
201204 setRemovingAddress ( null ) ;
202205 }
0 commit comments