mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-31 02:21: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:
|
if order.has_range:
|
||||||
order.amount = None
|
order.amount = None
|
||||||
order.last_satoshis = cls.satoshis_now(order)
|
order.last_satoshis = cls.satoshis_now(order)
|
||||||
|
order.last_satoshis_time = timezone.now()
|
||||||
order.save()
|
order.save()
|
||||||
# send_message.delay(order.id,'order_published') # too spammy
|
# send_message.delay(order.id,'order_published') # too spammy
|
||||||
return
|
return
|
||||||
@ -1019,6 +1020,7 @@ class Logics:
|
|||||||
|
|
||||||
# If there was no maker_bond object yet, generates one
|
# If there was no maker_bond object yet, generates one
|
||||||
order.last_satoshis = cls.satoshis_now(order)
|
order.last_satoshis = cls.satoshis_now(order)
|
||||||
|
order.last_satoshis_time = timezone.now()
|
||||||
bond_satoshis = int(order.last_satoshis * order.bond_size/100)
|
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."
|
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!
|
# 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)
|
# (This is the last update to "last_satoshis", it becomes the escrow amount next)
|
||||||
order.last_satoshis = cls.satoshis_now(order)
|
order.last_satoshis = cls.satoshis_now(order)
|
||||||
|
order.last_satoshis_time = timezone.now()
|
||||||
order.taker_bond.status = LNPayment.Status.LOCKED
|
order.taker_bond.status = LNPayment.Status.LOCKED
|
||||||
order.taker_bond.save()
|
order.taker_bond.save()
|
||||||
|
|
||||||
@ -1129,6 +1132,7 @@ class Logics:
|
|||||||
|
|
||||||
# If there was no taker_bond object yet, generates one
|
# If there was no taker_bond object yet, generates one
|
||||||
order.last_satoshis = cls.satoshis_now(order)
|
order.last_satoshis = cls.satoshis_now(order)
|
||||||
|
order.last_satoshis_time = timezone.now()
|
||||||
bond_satoshis = int(order.last_satoshis * order.bond_size/100)
|
bond_satoshis = int(order.last_satoshis * order.bond_size/100)
|
||||||
pos_text = "Buying" if cls.is_buyer(order, user) else "Selling"
|
pos_text = "Buying" if cls.is_buyer(order, user) else "Selling"
|
||||||
description = (
|
description = (
|
||||||
@ -1574,7 +1578,7 @@ class Logics:
|
|||||||
Summarizes a finished order. Returns a dict with
|
Summarizes a finished order. Returns a dict with
|
||||||
amounts, fees, costs, etc, for buyer and seller.
|
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'}
|
return False, {'bad_summary':'Order has not finished yet'}
|
||||||
|
|
||||||
context = {}
|
context = {}
|
||||||
@ -1609,6 +1613,9 @@ class Logics:
|
|||||||
context[f'{order_user}_summary']=summary
|
context[f'{order_user}_summary']=summary
|
||||||
|
|
||||||
platform_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:
|
if not order.is_swap:
|
||||||
platform_summary['routing_fee_sats'] = order.payout.fee
|
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)
|
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)],
|
MaxValueValidator(MAX_TRADE * 2)],
|
||||||
blank=True,
|
blank=True,
|
||||||
) # sats last time checked. Weird if 2* trade max...
|
) # 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
|
# order participants
|
||||||
maker = models.ForeignKey(
|
maker = models.ForeignKey(
|
||||||
|
@ -396,9 +396,10 @@ class OrderView(viewsets.ViewSet):
|
|||||||
data["bondless_taker"] = order.bondless_taker
|
data["bondless_taker"] = order.bondless_taker
|
||||||
|
|
||||||
# Adds trade summary
|
# Adds trade summary
|
||||||
valid, context = Logics.summarize_trade(order, request.user)
|
if order.status in [Order.Status.SUC, Order.Status.PAY, Order.Status.FAI]:
|
||||||
if valid:
|
valid, context = Logics.summarize_trade(order, request.user)
|
||||||
data = {**data, **context}
|
if valid:
|
||||||
|
data = {**data, **context}
|
||||||
|
|
||||||
# If status is 'Expired' add expiry reason
|
# If status is 'Expired' add expiry reason
|
||||||
if order.status == Order.Status.EXP:
|
if order.status == Order.Status.EXP:
|
||||||
|
@ -22,6 +22,8 @@ import { saveAsJson } from "../utils/saveFile";
|
|||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
import FlagWithProps from "./FlagWithProps";
|
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 ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
||||||
import DownloadIcon from '@mui/icons-material/Download';
|
import DownloadIcon from '@mui/icons-material/Download';
|
||||||
import AccountBalanceIcon from '@mui/icons-material/AccountBalance';
|
import AccountBalanceIcon from '@mui/icons-material/AccountBalance';
|
||||||
@ -60,7 +62,8 @@ const TradeSummary = ({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [buttonValue, setButtonValue] = useState<number>(isMaker ? 0 : 2);
|
const [buttonValue, setButtonValue] = useState<number>(isMaker ? 0 : 2);
|
||||||
var userSummary = buttonValue == 0 ? makerSummary : takerSummary;
|
var userSummary = buttonValue == 0 ? makerSummary : takerSummary;
|
||||||
|
const contractTimestamp = new Date(platformSummary.contract_timestamp)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid item xs={12} align="center">
|
<Grid item xs={12} align="center">
|
||||||
<Accordion defaultExpanded={true} elevation={0} sx={{width:322, position:'relative', right:8}}>
|
<Accordion defaultExpanded={true} elevation={0} sx={{width:322, position:'relative', right:8}}>
|
||||||
@ -186,24 +189,40 @@ const TradeSummary = ({
|
|||||||
</div>
|
</div>
|
||||||
{/* Platform Summary */}
|
{/* Platform Summary */}
|
||||||
<div style={{display: buttonValue == 1 ? '':'none'}}>
|
<div style={{display: buttonValue == 1 ? '':'none'}}>
|
||||||
<List dense={true}>
|
<List dense={true}>
|
||||||
<ListItem>
|
<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/>
|
<AccountBalanceIcon/>
|
||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
<ListItemText
|
<ListItemText
|
||||||
primary={t("{{revenueSats}} Sats",{revenueSats:platformSummary.trade_revenue_sats})}
|
primary={t("{{revenueSats}} Sats",{revenueSats:platformSummary.trade_revenue_sats})}
|
||||||
secondary={t("Platform trade revenue")}/>
|
secondary={t("Platform trade revenue")}/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
<ListItem>
|
<ListItem>
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
<RouteIcon/>
|
<RouteIcon/>
|
||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
<ListItemText
|
<ListItemText
|
||||||
primary={t("{{routingFeeSats}} MiliSats",{routingFeeSats:platformSummary.routing_fee_sats})}
|
primary={t("{{routingFeeSats}} MiliSats",{routingFeeSats:platformSummary.routing_fee_sats})}
|
||||||
secondary={t("Platform covered routing fee")}/>
|
secondary={t("Platform covered routing fee")}/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</List>
|
</List>
|
||||||
</div>
|
</div>
|
||||||
</AccordionDetails>
|
</AccordionDetails>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
Loading…
Reference in New Issue
Block a user