From 916a5fdf5a036770d2d6a794545df219e48634d4 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Mon, 18 Jul 2022 17:35:17 -0700 Subject: [PATCH] Add total time to contract completion to trade summary --- api/logics.py | 5 ++ api/models.py | 3 +- .../components/Icons/BasqueCountryFlag.tsx | 4 +- .../src/components/Icons/CataloniaFlag.tsx | 2 +- frontend/src/components/TradeSummary.tsx | 53 +++++++++++-------- frontend/static/locales/es.json | 4 ++ 6 files changed, 46 insertions(+), 25 deletions(-) diff --git a/api/logics.py b/api/logics.py index 8e4a8644..f011b3df 100644 --- a/api/logics.py +++ b/api/logics.py @@ -1353,6 +1353,8 @@ class Logics: order.payout.save() order.save() send_message.delay(order.id,'trade_successful') + order.contract_finalization_time = timezone.now() + order.save() return True # Pay onchain to address @@ -1367,6 +1369,8 @@ class Logics: order.status = Order.Status.SUC order.save() send_message.delay(order.id,'trade_successful') + order.contract_finalization_time = timezone.now() + order.save() return True return False @@ -1616,6 +1620,7 @@ class Logics: platform_summary['contract_exchange_rate'] = float(order.amount) / (float(order.last_satoshis) / 100000000) if order.last_satoshis_time != None: platform_summary['contract_timestamp'] = order.last_satoshis_time + platform_summary['contract_total_time'] = order.contract_finalization_time - order.last_satoshis_time if not order.is_swap: platform_summary['routing_fee_sats'] = order.payout.fee platform_summary['trade_revenue_sats'] = int(order.trade_escrow.num_satoshis - order.payout.num_satoshis - order.payout.fee) diff --git a/api/models.py b/api/models.py index 0e1aae41..986bfd58 100644 --- a/api/models.py +++ b/api/models.py @@ -394,7 +394,8 @@ class Order(models.Model): ) # sats last time checked. Weird if 2* trade max... # timestamp of last_satoshis last_satoshis_time = models.DateTimeField(null=True, default=None, blank=True) - + # time the fiat exchange is confirmed and Sats released to buyer + contract_finalization_time = models.DateTimeField(null=True, default=None, blank=True) # order participants maker = models.ForeignKey( User, diff --git a/frontend/src/components/Icons/BasqueCountryFlag.tsx b/frontend/src/components/Icons/BasqueCountryFlag.tsx index 2cb028e1..0f7073b0 100644 --- a/frontend/src/components/Icons/BasqueCountryFlag.tsx +++ b/frontend/src/components/Icons/BasqueCountryFlag.tsx @@ -5,8 +5,8 @@ export default function BasqueCountryFlag(props) { return ( - - + + ); } \ No newline at end of file diff --git a/frontend/src/components/Icons/CataloniaFlag.tsx b/frontend/src/components/Icons/CataloniaFlag.tsx index ef911d00..cf8dc334 100644 --- a/frontend/src/components/Icons/CataloniaFlag.tsx +++ b/frontend/src/components/Icons/CataloniaFlag.tsx @@ -5,7 +5,7 @@ export default function CataloniaFlag(props) { return ( - + ); } \ No newline at end of file diff --git a/frontend/src/components/TradeSummary.tsx b/frontend/src/components/TradeSummary.tsx index 515d39f7..0d092265 100644 --- a/frontend/src/components/TradeSummary.tsx +++ b/frontend/src/components/TradeSummary.tsx @@ -1,4 +1,5 @@ import React, { useState } from "react"; +import { format } from "date-fns"; import { useTranslation } from "react-i18next"; import { Avatar, @@ -59,10 +60,14 @@ const TradeSummary = ({ platformSummary, orderId, }: Props): JSX.Element => { - const { t } = useTranslation(); + const { t , i18n } = useTranslation(); const [buttonValue, setButtonValue] = useState(isMaker ? 0 : 2); var userSummary = buttonValue == 0 ? makerSummary : takerSummary; const contractTimestamp = new Date(platformSummary.contract_timestamp) + const total_time = platformSummary.contract_total_time + const hours = parseInt(total_time / 3600) + const mins = parseInt((total_time - hours * 3600) / 60) + const secs = parseInt(total_time - hours * 3600 - mins * 60) return ( @@ -156,7 +161,7 @@ const TradeSummary = ({ secondary={userSummary.is_buyer ? "BTC received" : "BTC sent"}/> @@ -169,7 +174,7 @@ const TradeSummary = ({ primary={t("{{swapFeeSats}} Sats ({{swapFeePercent}}%)" , {swapFeeSats:pn(userSummary.swap_fee_sats), swapFeePercent:userSummary.swap_fee_percent})} secondary={t("Onchain swap fee")}/> : null} @@ -190,38 +195,44 @@ const TradeSummary = ({ {/* Platform Summary */}
- - - - - - - - - - - - + + + + + + + + + + + + + + + +
diff --git a/frontend/static/locales/es.json b/frontend/static/locales/es.json index b085fa94..5f6eb00a 100644 --- a/frontend/static/locales/es.json +++ b/frontend/static/locales/es.json @@ -471,6 +471,10 @@ "Platform trade revenue":"Beneficio de la plataforma", "{{routingFeeSats}} MiliSats":"{{routingFeeSats}} MiliSats", "Platform covered routing fee":"Coste de enrutado cubierto", + "Timestamp":"Marca de hora", + "Completed in":"Completado en", + "Contract exchange rate":"Tasa de cambio del contrato", + "INFO DIALOG - InfoDiagog.js": "App information and clarifications and terms of use", "Close": "Cerrar",