mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-18 12:11:35 +00:00
Add contract oracle timestamp and exchange rate to summary
This commit is contained in:
parent
016fb0fb56
commit
456723973c
@ -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)
|
||||
|
@ -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(
|
||||
|
@ -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:
|
||||
|
@ -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<number>(isMaker ? 0 : 2);
|
||||
var userSummary = buttonValue == 0 ? makerSummary : takerSummary;
|
||||
|
||||
const contractTimestamp = new Date(platformSummary.contract_timestamp)
|
||||
|
||||
return (
|
||||
<Grid item xs={12} align="center">
|
||||
<Accordion defaultExpanded={true} elevation={0} sx={{width:322, position:'relative', right:8}}>
|
||||
@ -186,24 +189,40 @@ const TradeSummary = ({
|
||||
</div>
|
||||
{/* Platform Summary */}
|
||||
<div style={{display: buttonValue == 1 ? '':'none'}}>
|
||||
<List dense={true}>
|
||||
<List dense={true}>
|
||||
<ListItem>
|
||||
<ListItemIcon>
|
||||
<ListItemIcon>
|
||||
<PriceChangeIcon/>
|
||||
</ListItemIcon>
|
||||
<ListItemText
|
||||
primary={t("{{exchangeRate}} {{currencyCode}}/BTC",{exchangeRate:platformSummary.contract_exchange_rate.toPrecision(7),currencyCode:currencyCode})}
|
||||
secondary={t("Contract exchange rate")}/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemIcon>
|
||||
<ScheduleIcon/>
|
||||
</ListItemIcon>
|
||||
<ListItemText
|
||||
primary={contractTimestamp.toString()}
|
||||
secondary={t("Contract timestamp")}/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemIcon>
|
||||
<AccountBalanceIcon/>
|
||||
</ListItemIcon>
|
||||
<ListItemText
|
||||
</ListItemIcon>
|
||||
<ListItemText
|
||||
primary={t("{{revenueSats}} Sats",{revenueSats:platformSummary.trade_revenue_sats})}
|
||||
secondary={t("Platform trade revenue")}/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemIcon>
|
||||
<ListItemIcon>
|
||||
<RouteIcon/>
|
||||
</ListItemIcon>
|
||||
<ListItemText
|
||||
</ListItemIcon>
|
||||
<ListItemText
|
||||
primary={t("{{routingFeeSats}} MiliSats",{routingFeeSats:platformSummary.routing_fee_sats})}
|
||||
secondary={t("Platform covered routing fee")}/>
|
||||
</ListItem>
|
||||
</List>
|
||||
</List>
|
||||
</div>
|
||||
</AccordionDetails>
|
||||
</Accordion>
|
||||
|
Loading…
Reference in New Issue
Block a user