Skip to content

Commit 8d814b9

Browse files
Ernest/Fix wallets displaying when balances dont exist (#518)
* feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default entry for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default entry for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets without balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets without balances #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets without balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are added with defaults #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets without balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are added with defaults #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default entry for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default entry for wallets with no balances #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: ensure wallets with empty balances are processed Add default values for wallets with no balances in loadWallets. Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, calculate labels, and update wallet entries. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, calculate labels, and update wallet entries. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, calculate labels and names using existing logic. Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, calculate labels, and update wallet entries. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, calculate labels, and update wallet entries. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, calculate labels, and update wallet entries. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, calculate labels and names, use currency logos. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, apply existing balance logic for labels and names. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, calculate labels, and update wallet entries. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, calculate labels, and update wallet entries. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies for wallet processing. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, calculate labels, and update wallet entries. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, calculate labels, and update wallet entries. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, calculate labels and names, use currency logos. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, calculate labels and names using existing logic. Co-authored-by: null <[email protected]> * feat: update empty balances logic for USD currencies Filter and map USD currencies, apply existing balance logic for labels and names. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state for API call progress and update buttons for feedback. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state and update buttons for visual feedback during API calls. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state for API call progress and update buttons for feedback. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state for API call progress and update buttons for feedback. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state for API call progress and update buttons for feedback. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state for API call progress and update buttons for feedback. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state for API call progress and update buttons for feedback. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state and update buttons for visual feedback during API calls. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state for API call progress and update buttons for feedback. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state and update buttons for visual feedback during API calls. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state and update buttons for visual feedback during API calls. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state for API call progress and update buttons for feedback. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state for API call progress and update buttons for feedback. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state for API call progress and update buttons for feedback. #VERCEL_SKIP Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state for API call progress and update button UI. Co-authored-by: null <[email protected]> * feat: add loading state to Confirm buttons in transfer component Add `isSubmitting` state for API call progress and update buttons for feedback. #VERCEL_SKIP Co-authored-by: null <[email protected]> --------- Co-authored-by: v0 <v0[bot]@users.noreply.github.com>
1 parent 950eb46 commit 8d814b9

File tree

1 file changed

+71
-54
lines changed

1 file changed

+71
-54
lines changed

app/wallet/components/transfer.tsx

Lines changed: 71 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
149149
const [sourceMinAmount, setSourceMinAmount] = useState<number>(0)
150150
const [destinationMinAmount, setDestinationMinAmount] = useState<number>(0)
151151

152+
const [isSubmitting, setIsSubmitting] = useState(false)
153+
152154
const toEnterAmount = () => setStep("enterAmount")
153155
const toConfirm = () => {
154156
if (window.innerWidth >= 768) {
@@ -211,26 +213,45 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
211213
const processedWallets: ProcessedWallet[] = []
212214

213215
response.data.wallets.forEach((wallet: any) => {
214-
wallet.balances.forEach((balance: any) => {
215-
if ((wallet.type || "").toLowerCase() === "p2p" && balance.currency !== "USD") {
216-
return
217-
}
216+
if (!wallet.balances || wallet.balances.length === 0) {
217+
currencies
218+
.filter((currency) => currency.code === "USD")
219+
.forEach((currency) => {
220+
const currencyLabel = currenciesData?.data?.[currency.code]?.label || currency.code
221+
const walletName =
222+
(wallet.type || "").toLowerCase() === "p2p" ? `P2P ${currencyLabel}` : currencyLabel
223+
224+
processedWallets.push({
225+
wallet_id: wallet.wallet_id,
226+
name: walletName,
227+
balance: "0",
228+
currency: currency.code,
229+
icon: currency.logo,
230+
type: wallet.type,
231+
})
232+
})
233+
} else {
234+
wallet.balances.forEach((balance: any) => {
235+
if ((wallet.type || "").toLowerCase() === "p2p" && balance.currency !== "USD") {
236+
return
237+
}
218238

219-
const currencyLabel = currenciesData?.data?.[balance.currency]?.label || balance.currency
239+
const currencyLabel = currenciesData?.data?.[balance.currency]?.label || balance.currency
220240

221-
const walletName = (wallet.type || "").toLowerCase() === "p2p" ? `P2P ${currencyLabel}` : currencyLabel
241+
const walletName = (wallet.type || "").toLowerCase() === "p2p" ? `P2P ${currencyLabel}` : currencyLabel
222242

223-
if (balance.currency ==="USD") {
224-
processedWallets.push({
225-
wallet_id: wallet.wallet_id,
226-
name: walletName,
227-
balance: balance.balance,
228-
currency: balance.currency,
229-
icon: "/icons/usd-flag.png",
230-
type: wallet.type,
231-
})
232-
}
233-
})
243+
if (balance.currency === "USD") {
244+
processedWallets.push({
245+
wallet_id: wallet.wallet_id,
246+
name: walletName,
247+
balance: balance.balance,
248+
currency: balance.currency,
249+
icon: "/icons/usd-flag.png",
250+
type: wallet.type,
251+
})
252+
}
253+
})
254+
}
234255
})
235256

236257
setWallets(processedWallets)
@@ -466,6 +487,8 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
466487
return
467488
}
468489

490+
setIsSubmitting(true)
491+
469492
try {
470493
const generatedRequestId = crypto.randomUUID()
471494
setRequestId(generatedRequestId)
@@ -477,6 +500,7 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
477500
if (isSameWallet) {
478501
if (!exchangeRateData) {
479502
console.error("Exchange rate data is required for same-wallet transfers")
503+
setIsSubmitting(false)
480504
return
481505
}
482506

@@ -533,6 +557,8 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
533557
setShowDesktopConfirmPopup(false)
534558
setShowMobileConfirmSheet(false)
535559
toUnsuccessful()
560+
} finally {
561+
setIsSubmitting(false)
536562
}
537563
}
538564

@@ -918,9 +944,7 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
918944
<div className="w-[10.5px] h-[10.5px] rounded-full bg-white flex items-center justify-center">
919945
<Image
920946
src={
921-
getCurrencyImage(sourceWalletData.name, sourceWalletData.currency) ||
922-
"/placeholder.svg"
923-
}
947+
getCurrencyImage(sourceWalletData.name, sourceWalletData.currency)}
924948
alt={sourceWalletData.currency}
925949
width={9}
926950
height={9}
@@ -930,11 +954,10 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
930954
</div>
931955
</div>
932956
) : (
933-
<div className="w-6 h-6 rounded-full overflow-hidden flex-shrink-0">
957+
<div className="w-6 h-6 rounded-full overflow-hidden flex-shrink-0 mb-3 mt-1">
934958
<Image
935959
src={
936-
getCurrencyImage(sourceWalletData.name, sourceWalletData.currency) || "/placeholder.svg"
937-
}
960+
getCurrencyImage(sourceWalletData.name, sourceWalletData.currency)}
938961
alt={sourceWalletData.currency}
939962
width={24}
940963
height={24}
@@ -964,9 +987,7 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
964987
<div className="w-[10.5px] h-[10.5px] rounded-full bg-white flex items-center justify-center">
965988
<Image
966989
src={
967-
getCurrencyImage(destinationWalletData.name, destinationWalletData.currency) ||
968-
"/placeholder.svg"
969-
}
990+
getCurrencyImage(destinationWalletData.name, destinationWalletData.currency)}
970991
alt={destinationWalletData.currency}
971992
width={9}
972993
height={9}
@@ -976,12 +997,10 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
976997
</div>
977998
</div>
978999
) : (
979-
<div className="w-6 h-6 rounded-full overflow-hidden flex-shrink-0">
1000+
<div className="w-6 h-6 rounded-full overflow-hidden flex-shrink-0 mb-3 mt-1">
9801001
<Image
9811002
src={
982-
getCurrencyImage(destinationWalletData.name, destinationWalletData.currency) ||
983-
"/placeholder.svg"
984-
}
1003+
getCurrencyImage(destinationWalletData.name, destinationWalletData.currency) }
9851004
alt={destinationWalletData.currency}
9861005
width={24}
9871006
height={24}
@@ -1074,9 +1093,14 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
10741093
<div className="space-y-2 mt-12">
10751094
<Button
10761095
onClick={handleConfirmTransfer}
1096+
disabled={isSubmitting}
10771097
className="w-full h-12 min-w-24 min-h-12 max-h-12 px-7 flex justify-center items-center gap-2"
10781098
>
1079-
Confirm
1099+
{isSubmitting ? (
1100+
<Image src="/icons/spinner.png" alt="Loading" width={20} height={20} className="animate-spin" />
1101+
) : (
1102+
"Confirm"
1103+
)}
10801104
</Button>
10811105
</div>
10821106
</div>
@@ -1120,9 +1144,7 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
11201144
<div className="w-[10.5px] h-[10.5px] rounded-full bg-white flex items-center justify-center">
11211145
<Image
11221146
src={
1123-
getCurrencyImage(sourceWalletData.name, sourceWalletData.currency) ||
1124-
"/placeholder.svg"
1125-
}
1147+
getCurrencyImage(sourceWalletData.name, sourceWalletData.currency)}
11261148
alt={sourceWalletData.currency}
11271149
width={9}
11281150
height={9}
@@ -1132,11 +1154,10 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
11321154
</div>
11331155
</div>
11341156
) : (
1135-
<div className="w-6 h-6 rounded-full overflow-hidden flex-shrink-0">
1157+
<div className="w-6 h-6 rounded-full overflow-hidden flex-shrink-0 mb-3 mt-1">
11361158
<Image
11371159
src={
1138-
getCurrencyImage(sourceWalletData.name, sourceWalletData.currency) || "/placeholder.svg"
1139-
}
1160+
getCurrencyImage(sourceWalletData.name, sourceWalletData.currency)}
11401161
alt={sourceWalletData.currency}
11411162
width={24}
11421163
height={24}
@@ -1166,9 +1187,7 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
11661187
<div className="w-[10.5px] h-[10.5px] rounded-full bg-white flex items-center justify-center">
11671188
<Image
11681189
src={
1169-
getCurrencyImage(destinationWalletData.name, destinationWalletData.currency) ||
1170-
"/placeholder.svg"
1171-
}
1190+
getCurrencyImage(destinationWalletData.name, destinationWalletData.currency) }
11721191
alt={destinationWalletData.currency}
11731192
width={9}
11741193
height={9}
@@ -1178,12 +1197,10 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
11781197
</div>
11791198
</div>
11801199
) : (
1181-
<div className="w-6 h-6 rounded-full overflow-hidden flex-shrink-0">
1200+
<div className="w-6 h-6 rounded-full overflow-hidden flex-shrink-0 mb-3 mt-1">
11821201
<Image
11831202
src={
1184-
getCurrencyImage(destinationWalletData.name, destinationWalletData.currency) ||
1185-
"/placeholder.svg"
1186-
}
1203+
getCurrencyImage(destinationWalletData.name, destinationWalletData.currency) }
11871204
alt={destinationWalletData.currency}
11881205
width={24}
11891206
height={24}
@@ -1276,9 +1293,14 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
12761293
<div className="space-y-3 mt-8">
12771294
<Button
12781295
onClick={handleConfirmTransfer}
1296+
disabled={isSubmitting}
12791297
className="w-full h-12 min-w-24 min-h-12 max-h-12 px-7 flex justify-center items-center gap-2"
12801298
>
1281-
Confirm
1299+
{isSubmitting ? (
1300+
<Image src="/icons/spinner.png" alt="Loading" width={20} height={20} className="animate-spin" />
1301+
) : (
1302+
"Confirm"
1303+
)}
12821304
</Button>
12831305
</div>
12841306
</div>
@@ -1382,8 +1404,7 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
13821404
<div className="w-[10.5px] h-[10.5px] rounded-full bg-white flex items-center justify-center">
13831405
<Image
13841406
src={
1385-
getCurrencyImage(sourceWalletData.name, sourceWalletData.currency) || "/placeholder.svg"
1386-
}
1407+
getCurrencyImage(sourceWalletData.name, sourceWalletData.currency)}
13871408
alt={sourceWalletData.currency}
13881409
width={9}
13891410
height={9}
@@ -1395,7 +1416,7 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
13951416
) : (
13961417
<div className="w-6 h-6 rounded-full overflow-hidden flex-shrink-0 mb-3 mt-1">
13971418
<Image
1398-
src={getCurrencyImage(sourceWalletData.name, sourceWalletData.currency) || "/placeholder.svg"}
1419+
src={getCurrencyImage(sourceWalletData.name, sourceWalletData.currency)}
13991420
alt={sourceWalletData.currency}
14001421
width={24}
14011422
height={24}
@@ -1444,9 +1465,7 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
14441465
<div className="w-[10.5px] h-[10.5px] rounded-full bg-white flex items-center justify-center">
14451466
<Image
14461467
src={
1447-
getCurrencyImage(destinationWalletData.name, destinationWalletData.currency) ||
1448-
"/placeholder.svg"
1449-
}
1468+
getCurrencyImage(destinationWalletData.name, destinationWalletData.currency)}
14501469
alt={destinationWalletData.currency}
14511470
width={9}
14521471
height={9}
@@ -1459,9 +1478,7 @@ export default function Transfer({ currencySelected, onClose, stepVal = "enterAm
14591478
<div className="w-6 h-6 rounded-full overflow-hidden flex-shrink-0 mb-3 mt-1">
14601479
<Image
14611480
src={
1462-
getCurrencyImage(destinationWalletData.name, destinationWalletData.currency) ||
1463-
"/placeholder.svg"
1464-
}
1481+
getCurrencyImage(destinationWalletData.name, destinationWalletData.currency)}
14651482
alt={destinationWalletData.currency}
14661483
width={24}
14671484
height={24}

0 commit comments

Comments
 (0)