From 35e7469a13ca10a8bc570b9b0f0d16e4dc584e5f Mon Sep 17 00:00:00 2001 From: Albert Folch Date: Fri, 13 Oct 2023 10:49:27 +0200 Subject: [PATCH 1/4] wip --- .../EscalateModal/steps/EscalateStepTwo.tsx | 6 +- src/lib/utils/dispute.ts | 18 ++++++ src/lib/utils/exchange.ts | 8 +-- src/lib/utils/getDateTimestamp.ts | 2 +- .../chat/components/ExchangeSidePreview.tsx | 55 +++++++++++-------- 5 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 src/lib/utils/dispute.ts diff --git a/src/components/modal/components/Chat/components/EscalateModal/steps/EscalateStepTwo.tsx b/src/components/modal/components/Chat/components/EscalateModal/steps/EscalateStepTwo.tsx index 8359162ef..8fa1b2815 100644 --- a/src/components/modal/components/Chat/components/EscalateModal/steps/EscalateStepTwo.tsx +++ b/src/components/modal/components/Chat/components/EscalateModal/steps/EscalateStepTwo.tsx @@ -511,9 +511,9 @@ function EscalateStepTwo({ values?.disputeId || "", [FormModel.formFields.buyerAddress.name]: values?.buyerAddress ? values?.buyerAddress : "", - [`Unsigned message: ${FormModel.formFields.message.name}`]: + [`Signed message: ${FormModel.formFields.message.name}`]: values?.message - ? `Unsigned message: ${values?.message}` + ? `Signed message: ${values?.message}` : "", [FormModel.formFields.signature.name]: values?.signature || "" @@ -524,7 +524,7 @@ function EscalateStepTwo({ diff --git a/src/lib/utils/dispute.ts b/src/lib/utils/dispute.ts new file mode 100644 index 000000000..30647e214 --- /dev/null +++ b/src/lib/utils/dispute.ts @@ -0,0 +1,18 @@ +import { subgraph } from "@bosonprotocol/react-kit"; + +import { getDateTimestamp } from "./getDateTimestamp"; + +export const getDisputeDates = ( + dispute: subgraph.DisputeFieldsFragment | undefined +) => { + const endOfResolutionPeriod = dispute?.timeout + ? getDateTimestamp(dispute?.timeout) + : undefined; + const finishedResolutionPeriod = endOfResolutionPeriod + ? Date.now() > endOfResolutionPeriod + : false; + return { + endOfResolutionPeriod, + finishedResolutionPeriod + }; +}; diff --git a/src/lib/utils/exchange.ts b/src/lib/utils/exchange.ts index 521d9c826..e33019b86 100644 --- a/src/lib/utils/exchange.ts +++ b/src/lib/utils/exchange.ts @@ -39,8 +39,8 @@ export const getHasExchangeDisputeResolutionElapsed = ( return false; } return ( - Number(exchange.redeemedDate) * 1000 + - Number(offer.disputePeriodDuration) * 1000 < + getDateTimestamp(exchange.redeemedDate) + + getDateTimestamp(offer.disputePeriodDuration) < Date.now() ); }; @@ -69,10 +69,10 @@ export const getExchangeTokenId = ( }; export const getExchangeDisputeDates = (exchange: Exchange) => { - const raisedDisputeAt = new Date(Number(exchange.disputedDate) * 1000); + const raisedDisputeAt = new Date(getDateTimestamp(exchange.disputedDate)); const lastDayToResolveDispute = new Date( raisedDisputeAt.getTime() + - Number(exchange.offer.resolutionPeriodDuration) * 1000 + getDateTimestamp(exchange.offer.resolutionPeriodDuration) ); const totalDaysToResolveDispute = dayjs(lastDayToResolveDispute).diff( raisedDisputeAt, diff --git a/src/lib/utils/getDateTimestamp.ts b/src/lib/utils/getDateTimestamp.ts index 3f2c2db65..4b934f4e2 100644 --- a/src/lib/utils/getDateTimestamp.ts +++ b/src/lib/utils/getDateTimestamp.ts @@ -1,4 +1,4 @@ -export const getDateTimestamp = (date: string) => { +export const getDateTimestamp = (date: string | undefined | null) => { const number = Number(date); return !isNaN(number) ? number * 1000 : 0; diff --git a/src/pages/chat/components/ExchangeSidePreview.tsx b/src/pages/chat/components/ExchangeSidePreview.tsx index 58178aa72..58a4ce437 100644 --- a/src/pages/chat/components/ExchangeSidePreview.tsx +++ b/src/pages/chat/components/ExchangeSidePreview.tsx @@ -7,6 +7,7 @@ import { buyerAndSellerAgreementIncluding, customisedExchangePolicy } from "lib/constants/policies"; +import { getDisputeDates } from "lib/utils/dispute"; import { getExchangePolicyName } from "lib/utils/policy/getExchangePolicyName"; import { ArrowSquareOut } from "phosphor-react"; import { @@ -437,7 +438,15 @@ export default function ExchangeSidePreview({ const isEscalated = !!dispute?.escalatedDate; const isRetracted = !!dispute?.retractedDate; const isFinalized = !!dispute?.finalizedDate; - + const { finishedResolutionPeriod } = getDisputeDates(dispute); + console.log({ + exchange, + dispute, + finishedResolutionPeriod, + isInDispute, + iAmTheBuyer, + isEscalated + }); const { totalDaysToResolveDispute, daysLeftToResolveDispute } = getExchangeDisputeDates(exchange); @@ -520,7 +529,7 @@ export default function ExchangeSidePreview({
- {isInDispute && iAmTheBuyer && !isEscalated && !isRetracted ? ( + {isInDispute && iAmTheBuyer && !isRetracted ? ( - + {!finishedResolutionPeriod && !isEscalated && ( + + )} ) : isInRedeemed && iAmTheBuyer ? ( From 5b07eed0136c706d3d1de7060b3bfbf865f4732e Mon Sep 17 00:00:00 2001 From: Albert Folch Date: Fri, 13 Oct 2023 13:16:32 +0200 Subject: [PATCH 2/4] refactor: remove logs --- src/pages/chat/components/ExchangeSidePreview.tsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/pages/chat/components/ExchangeSidePreview.tsx b/src/pages/chat/components/ExchangeSidePreview.tsx index 58a4ce437..4e2a296b6 100644 --- a/src/pages/chat/components/ExchangeSidePreview.tsx +++ b/src/pages/chat/components/ExchangeSidePreview.tsx @@ -439,14 +439,7 @@ export default function ExchangeSidePreview({ const isRetracted = !!dispute?.retractedDate; const isFinalized = !!dispute?.finalizedDate; const { finishedResolutionPeriod } = getDisputeDates(dispute); - console.log({ - exchange, - dispute, - finishedResolutionPeriod, - isInDispute, - iAmTheBuyer, - isEscalated - }); + const { totalDaysToResolveDispute, daysLeftToResolveDispute } = getExchangeDisputeDates(exchange); From 9f041ddf01a0ff26ec26990196ab75e6a12e227c Mon Sep 17 00:00:00 2001 From: Albert Folch Date: Fri, 13 Oct 2023 16:15:52 +0200 Subject: [PATCH 3/4] rollback condition --- src/pages/chat/components/ExchangeSidePreview.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/chat/components/ExchangeSidePreview.tsx b/src/pages/chat/components/ExchangeSidePreview.tsx index 4e2a296b6..0eeca3f38 100644 --- a/src/pages/chat/components/ExchangeSidePreview.tsx +++ b/src/pages/chat/components/ExchangeSidePreview.tsx @@ -522,7 +522,7 @@ export default function ExchangeSidePreview({
- {isInDispute && iAmTheBuyer && !isRetracted ? ( + {isInDispute && iAmTheBuyer && !isEscalated && !isRetracted ? (