From fdc03068f277bc65099ff420b1682d273cdfaa44 Mon Sep 17 00:00:00 2001 From: Jefferson Mantovani Date: Wed, 8 Oct 2025 20:55:39 -0300 Subject: [PATCH] refactor: listing component improvements --- .../ListingComponent/BalanceCard.vue | 249 +++++++++++++ .../ListingComponent/ListingComponent.vue | 350 +----------------- .../ListingComponent/TransactionCard.vue | 126 +++++++ 3 files changed, 395 insertions(+), 330 deletions(-) create mode 100644 src/components/ListingComponent/BalanceCard.vue create mode 100644 src/components/ListingComponent/TransactionCard.vue diff --git a/src/components/ListingComponent/BalanceCard.vue b/src/components/ListingComponent/BalanceCard.vue new file mode 100644 index 0000000..a3be4b1 --- /dev/null +++ b/src/components/ListingComponent/BalanceCard.vue @@ -0,0 +1,249 @@ + + + + + + diff --git a/src/components/ListingComponent/ListingComponent.vue b/src/components/ListingComponent/ListingComponent.vue index 157c56e..530aa34 100644 --- a/src/components/ListingComponent/ListingComponent.vue +++ b/src/components/ListingComponent/ListingComponent.vue @@ -3,11 +3,10 @@ import { NetworkEnum } from "@/model/NetworkEnum"; import type { ValidDeposit } from "@/model/ValidDeposit"; import type { WalletTransaction } from "@/model/WalletTransaction"; import { useUser } from "@/composables/useUser"; -import { ref, watch, onMounted } from "vue"; +import { ref, watch } from "vue"; import SpinnerComponent from "../ui/SpinnerComponent.vue"; -import { decimalCount } from "@/utils/decimalCount"; -import { debounce } from "@/utils/debounce"; -import { useFloating, arrow, offset, flip, shift } from "@floating-ui/vue"; +import BalanceCard from "./BalanceCard.vue"; +import TransactionCard from "./TransactionCard.vue"; const user = useUser(); @@ -22,80 +21,10 @@ const emit = defineEmits(["depositWithdrawn"]); const { loadingWalletTransactions } = user; -const remaining = ref(0); const itemsToShow = ref([]); -const withdrawAmount = ref(""); -const withdrawButtonOpacity = ref(0.6); -const withdrawButtonCursor = ref("not-allowed"); -const isCollapsibleOpen = ref(false); -const validDecimals = ref(true); -const validWithdrawAmount = ref(true); -const enableConfirmButton = ref(false); -const showInfoTooltip = ref(false); -const floatingArrow = ref(null); -const reference = ref(null); -const floating = ref(null); -const infoText = ref(null); - -// Debounce methods -const handleInputEvent = (event: any): void => { - const { value } = event.target; - - if (decimalCount(String(value)) > 2) { - validDecimals.value = false; - enableConfirmButton.value = false; - return; - } - validDecimals.value = true; - - if (value > remaining.value) { - validWithdrawAmount.value = false; - enableConfirmButton.value = false; - return; - } - validWithdrawAmount.value = true; - enableConfirmButton.value = true; -}; - -const callWithdraw = () => { - emit("depositWithdrawn", withdrawAmount.value); -}; - -watch(enableConfirmButton, (): void => { - if (!enableConfirmButton.value) { - withdrawButtonOpacity.value = 0.7; - withdrawButtonCursor.value = "not-allowed"; - } else { - withdrawButtonOpacity.value = 1; - withdrawButtonCursor.value = "pointer"; - } -}); - -watch(withdrawAmount, (): void => { - if (!withdrawAmount.value || !enableConfirmButton.value) { - withdrawButtonOpacity.value = 0.7; - withdrawButtonCursor.value = "not-allowed"; - } else { - withdrawButtonOpacity.value = 1; - withdrawButtonCursor.value = "pointer"; - } -}); - -const getRemaining = (): number => { - if (props.validDeposits.length > 0) { - // in this release only the BRL token is being used. - const deposit = props.validDeposits[0]; - remaining.value = deposit ? deposit.remaining : 0; - return deposit ? deposit.remaining : 0; - } - return 0; -}; - -const getExplorer = (): string => { - return user.networkName.value == NetworkEnum.sepolia - ? "Etherscan" - : "Polygonscan"; +const callWithdraw = (amount: string) => { + emit("depositWithdrawn", amount); }; const showInitialItems = (): void => { @@ -118,31 +47,6 @@ const loadMore = (): void => { ); }; -const getEventName = (event: string | undefined): string => { - if (!event) return "Desconhecido"; - - const possibleEventName: { [key: string]: string } = { - DepositAdded: "Oferta", - LockAdded: "Reserva", - LockReleased: "Compra", - DepositWithdrawn: "Retirada", - }; - - return possibleEventName[event]; -}; - -onMounted(() => { - useFloating(reference, floating, { - placement: "right", - middleware: [ - offset(10), - flip(), - shift(), - arrow({ element: floatingArrow }), - ], - }); -}); - // watch props changes watch(props, async (): Promise => { const itemsToShowQty = itemsToShow.value.length; @@ -167,179 +71,23 @@ showInitialItems();
-
-
-
-

- Saldo disponível -

-

- {{ getRemaining() }} {{ user.selectedToken.value }} -

-
- {{ - `com ${activeLockAmount.toFixed(2)} ${ - user.selectedToken.value - } em lock` - }} -
- info image - -
-
-
-
-
- Withdraw image - Sacar -
-
-
-
-
-

Valor do saque

- -
-
- Por favor utilize no máximo 2 casas decimais -
-
- Saldo insuficiente -
-
-
-

- Cancelar -

+ :valid-deposits="props.validDeposits" + :active-lock-amount="activeLockAmount" + :selected-token="user.selectedToken.value" + @withdraw="callWithdraw" + /> -
- Withdraw image - Sacar -
-
-
-
-
-
-
- - {{ getEventName(item.event) }} - - - {{ item.amount }} - - -
-
-
- Em Aberto -
-
- Expirado -
-
- Finalizado -
-
- {{ getExplorer() }} - Redirect image -
-
- Continuar -
-
-
-
+ :selected-token="user.selectedToken.value" + :transaction="item" + :network-name="user.networkName.value" + @open-explorer="openEtherscanUrl" + /> +
Carregar mais @@ -367,63 +115,5 @@ showInitialItems(); diff --git a/src/components/ListingComponent/TransactionCard.vue b/src/components/ListingComponent/TransactionCard.vue new file mode 100644 index 0000000..8c661dd --- /dev/null +++ b/src/components/ListingComponent/TransactionCard.vue @@ -0,0 +1,126 @@ + + + + + +