diff --git a/api/logics.py b/api/logics.py index 2805807d..8e4a8644 100644 --- a/api/logics.py +++ b/api/logics.py @@ -982,6 +982,7 @@ class Logics: if order.has_range: order.amount = None order.last_satoshis = cls.satoshis_now(order) + order.last_satoshis_time = timezone.now() order.save() # send_message.delay(order.id,'order_published') # too spammy return @@ -1019,6 +1020,7 @@ class Logics: # If there was no maker_bond object yet, generates one order.last_satoshis = cls.satoshis_now(order) + order.last_satoshis_time = timezone.now() bond_satoshis = int(order.last_satoshis * order.bond_size/100) description = f"RoboSats - Publishing '{str(order)}' - Maker bond - This payment WILL FREEZE IN YOUR WALLET, check on the website if it was successful. It will automatically return unless you cheat or cancel unilaterally." @@ -1074,6 +1076,7 @@ class Logics: # THE TRADE AMOUNT IS FINAL WITH THE CONFIRMATION OF THE TAKER BOND! # (This is the last update to "last_satoshis", it becomes the escrow amount next) order.last_satoshis = cls.satoshis_now(order) + order.last_satoshis_time = timezone.now() order.taker_bond.status = LNPayment.Status.LOCKED order.taker_bond.save() @@ -1129,6 +1132,7 @@ class Logics: # If there was no taker_bond object yet, generates one order.last_satoshis = cls.satoshis_now(order) + order.last_satoshis_time = timezone.now() bond_satoshis = int(order.last_satoshis * order.bond_size/100) pos_text = "Buying" if cls.is_buyer(order, user) else "Selling" description = ( @@ -1574,7 +1578,7 @@ class Logics: Summarizes a finished order. Returns a dict with amounts, fees, costs, etc, for buyer and seller. ''' - if not order.status in [Order.Status.EXP, Order.Status.SUC, Order.Status.PAY, Order.Status.FAI]: + if not order.status in [Order.Status.SUC, Order.Status.PAY, Order.Status.FAI]: return False, {'bad_summary':'Order has not finished yet'} context = {} @@ -1609,6 +1613,9 @@ class Logics: context[f'{order_user}_summary']=summary platform_summary = {} + 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 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 8cb4beda..0e1aae41 100644 --- a/api/models.py +++ b/api/models.py @@ -392,6 +392,8 @@ class Order(models.Model): MaxValueValidator(MAX_TRADE * 2)], blank=True, ) # sats last time checked. Weird if 2* trade max... + # timestamp of last_satoshis + last_satoshis_time = models.DateTimeField(null=True, default=None, blank=True) # order participants maker = models.ForeignKey( diff --git a/api/views.py b/api/views.py index 248cadc9..da4d7d45 100644 --- a/api/views.py +++ b/api/views.py @@ -396,9 +396,10 @@ class OrderView(viewsets.ViewSet): data["bondless_taker"] = order.bondless_taker # Adds trade summary - valid, context = Logics.summarize_trade(order, request.user) - if valid: - data = {**data, **context} + if order.status in [Order.Status.SUC, Order.Status.PAY, Order.Status.FAI]: + valid, context = Logics.summarize_trade(order, request.user) + if valid: + data = {**data, **context} # If status is 'Expired' add expiry reason if order.status == Order.Status.EXP: diff --git a/frontend/src/components/TradeSummary.tsx b/frontend/src/components/TradeSummary.tsx index 69565977..515d39f7 100644 --- a/frontend/src/components/TradeSummary.tsx +++ b/frontend/src/components/TradeSummary.tsx @@ -22,6 +22,8 @@ import { saveAsJson } from "../utils/saveFile"; // Icons import FlagWithProps from "./FlagWithProps"; +import ScheduleIcon from '@mui/icons-material/Schedule'; +import PriceChangeIcon from '@mui/icons-material/PriceChange'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import DownloadIcon from '@mui/icons-material/Download'; import AccountBalanceIcon from '@mui/icons-material/AccountBalance'; @@ -60,7 +62,8 @@ const TradeSummary = ({ const { t } = useTranslation(); const [buttonValue, setButtonValue] = useState(isMaker ? 0 : 2); var userSummary = buttonValue == 0 ? makerSummary : takerSummary; - + const contractTimestamp = new Date(platformSummary.contract_timestamp) + return ( @@ -186,24 +189,40 @@ const TradeSummary = ({ {/* Platform Summary */}
- + - + + + + + + + + + + + + + - - + - + - - + - +