From 481803e643787558f75a6469b4a51ed7b55f28a2 Mon Sep 17 00:00:00 2001 From: RcleydsonR Date: Mon, 27 Feb 2023 20:41:58 -0300 Subject: [PATCH] add continue button on manage bids that allow user to continue lock and release it, also fix some responsive points Co-authored-by: enzoggqs --- src/blockchain/events.ts | 25 +++++++++- src/blockchain/wallet.ts | 3 ++ .../ListingComponent/ListingComponent.vue | 48 ++++++++++++++----- src/model/WalletTransaction.ts | 1 + src/router/index.ts | 6 +++ src/views/HomeView.vue | 29 ++++++++--- 6 files changed, 92 insertions(+), 20 deletions(-) diff --git a/src/blockchain/events.ts b/src/blockchain/events.ts index 897e087..18ae3be 100644 --- a/src/blockchain/events.ts +++ b/src/blockchain/events.ts @@ -7,6 +7,8 @@ import { getContract } from "./provider"; import type { ValidDeposit } from "@/model/ValidDeposit"; import { getP2PixAddress, getTokenAddress } from "./addresses"; import { NetworkEnum } from "@/model/NetworkEnum"; +import type { UnreleasedLock } from "@/model/UnreleasedLock"; +import type { Pix } from "@/model/Pix"; const getNetworksLiquidity = async (): Promise => { const etherStore = useEtherStore(); @@ -100,4 +102,25 @@ const getValidDeposits = async ( return Object.values(depositList); }; -export { getValidDeposits, getNetworksLiquidity }; +const getUnreleasedLockById = async ( + lockID: string +): Promise => { + const p2pContract = getContract(); + const pixData: Pix = { + pixKey: "", + }; + + const lock = await p2pContract.mapLocks(lockID); + + const pixTarget = lock.pixTarget; + const amount = formatEther(lock?.amount); + pixData.pixKey = String(Number(pixTarget)); + pixData.value = Number(amount); + + return { + lockID: lockID, + pix: pixData, + }; +}; + +export { getValidDeposits, getNetworksLiquidity, getUnreleasedLockById }; diff --git a/src/blockchain/wallet.ts b/src/blockchain/wallet.ts index 51146ce..d29afb9 100644 --- a/src/blockchain/wallet.ts +++ b/src/blockchain/wallet.ts @@ -80,6 +80,9 @@ const filterLockStatus = async ( transactionHash: transaction.transactionHash ? transaction.transactionHash : "", + transactionID: transaction.args?.lockID + ? String(transaction.args?.lockID) + : "", }; return tx; diff --git a/src/components/ListingComponent/ListingComponent.vue b/src/components/ListingComponent/ListingComponent.vue index 1d33adf..2ad8217 100644 --- a/src/components/ListingComponent/ListingComponent.vue +++ b/src/components/ListingComponent/ListingComponent.vue @@ -174,7 +174,7 @@ showInitialItems();

{{ getRemaining() }} BRZ

-
+
{{ `com ${activeLockAmount.toFixed(2)} BRZ em lock` }} @@ -272,22 +272,23 @@ showInitialItems(); :key="item.blockNumber" >
-
-

+

+ {{ getEventName(item.event) }} -

-

+ + {{ item.amount }} BRZ -

-

+
- Ativo + Em Aberto
{{ getExplorer() }} - Redirect image + Redirect image +
+
+ Continuar
@@ -358,7 +378,7 @@ p { } .status-text { - @apply text-base font-medium text-gray-900 rounded-lg text-center mb-2 p-1; + @apply text-xs sm:text-base font-medium text-gray-900 rounded-lg text-center mb-2 px-2 py-1 mt-4; } .text { @apply text-white text-center; @@ -373,13 +393,17 @@ p { } .last-release-info { - @apply font-medium text-sm sm:text-base text-gray-900 justify-self-center; + @apply font-medium text-xs sm:text-sm text-gray-900 justify-self-center; } .tooltip { @apply bg-white text-gray-900 font-medium text-xs md:text-base px-3 py-2 rounded border-2 border-emerald-500 left-5 top-[-3rem]; } +.router-button { + @apply rounded-lg border-amber-300 border-2 px-3 py-2 text-gray-900 font-semibold sm:text-base text-xs hover:bg-transparent w-full text-center; +} + .withdraw-button { opacity: v-bind(withdrawButtonOpacity); cursor: v-bind(withdrawButtonCursor); diff --git a/src/model/WalletTransaction.ts b/src/model/WalletTransaction.ts index 2fc0bff..1739aa5 100644 --- a/src/model/WalletTransaction.ts +++ b/src/model/WalletTransaction.ts @@ -7,4 +7,5 @@ export type WalletTransaction = { event: string; lockStatus: number; transactionHash: string; + transactionID?: string; }; diff --git a/src/router/index.ts b/src/router/index.ts index db7978c..fe48ef0 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -11,6 +11,12 @@ const router = createRouter({ path: "/", name: "home", component: HomeView, + props: true, + }, + { + path: "/:lockID", + name: "redirect buy", + component: HomeView, }, { path: "/seller", diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index e1ab5e0..4e4fbc2 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -10,6 +10,7 @@ import { addLock, releaseLock } from "@/blockchain/buyerMethods"; import { updateWalletStatus, checkUnreleasedLock } from "@/blockchain/wallet"; import { getNetworksLiquidity } from "@/blockchain/events"; import type { ValidDeposit } from "@/model/ValidDeposit"; +import { getUnreleasedLockById } from "@/blockchain/events"; import CustomAlert from "@/components/CustomAlert/CustomAlert.vue"; enum Step { @@ -30,6 +31,7 @@ const lockID = ref(""); const loadingRelease = ref(false); const showModal = ref(false); const showBuyAlert = ref(false); +const paramLockID = window.history.state?.lockID; const confirmBuyClick = async ( selectedDeposit: ValidDeposit, @@ -89,17 +91,30 @@ const checkForUnreleasedLocks = async (): Promise => { } }; -watch(walletAddress, async () => { - await checkForUnreleasedLocks(); -}); +if (paramLockID) { + const lockToRedirect = await getUnreleasedLockById(paramLockID as string); + if (lockToRedirect) { + lockID.value = lockToRedirect.lockID; + tokenAmount.value = lockToRedirect.pix.value; + pixTarget.value = Number(lockToRedirect.pix.pixKey); + flowStep.value = Step.Buy; + } else { + flowStep.value = Step.Search; + } +} else { + watch(walletAddress, async () => { + await checkForUnreleasedLocks(); + }); -watch(networkName, async () => { - if (walletAddress.value) await checkForUnreleasedLocks(); -}); + watch(networkName, async () => { + if (walletAddress.value) await checkForUnreleasedLocks(); + }); +} onMounted(async () => { await getNetworksLiquidity(); - if (walletAddress.value) await checkForUnreleasedLocks(); + if (walletAddress.value && !paramLockID) await checkForUnreleasedLocks(); + window.history.state.lockID = ""; });