Upgrade fee computation for maker/takers

This commit is contained in:
Reckless_Satoshi 2022-03-03 07:40:56 -08:00
parent c4cf995dbf
commit b38f18d6d5
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
5 changed files with 42 additions and 14 deletions

View File

@ -11,6 +11,8 @@ import math
import ast
FEE = float(config("FEE"))
MAKER_FEE_SPLIT = float(config("MAKER_FEE_SPLIT"))
BOND_SIZE = float(config("BOND_SIZE"))
ESCROW_USERNAME = config("ESCROW_USERNAME")
PENALTY_TIMEOUT = int(config("PENALTY_TIMEOUT"))
@ -375,12 +377,35 @@ class Logics:
"""Computes buyer invoice amount. Uses order.last_satoshis,
that is the final trade amount set at Taker Bond time"""
if user == order.maker:
fee_fraction = FEE * MAKER_FEE_SPLIT
elif user == order.taker:
fee_fraction = FEE * (1 - MAKER_FEE_SPLIT)
fee_sats = order.last_satoshis * fee_fraction
if cls.is_buyer(order, user):
invoice_amount = int(order.last_satoshis *
(1 - FEE)) # Trading FEE is charged here.
invoice_amount = int(order.last_satoshis - fee_sats) # Trading fee to buyer is charged here.
return True, {"invoice_amount": invoice_amount}
@classmethod
def escrow_amount(cls, order, user):
"""Computes escrow invoice amount. Uses order.last_satoshis,
that is the final trade amount set at Taker Bond time"""
if user == order.maker:
fee_fraction = FEE * MAKER_FEE_SPLIT
elif user == order.taker:
fee_fraction = FEE * (1 - MAKER_FEE_SPLIT)
fee_sats = order.last_satoshis * fee_fraction
if cls.is_seller(order, user):
escrow_amount = int(order.last_satoshis + fee_sats) # Trading fee to seller is charged here.
return True, {"escrow_amount": escrow_amount}
@classmethod
def update_invoice(cls, order, user, invoice):
@ -852,8 +877,7 @@ class Logics:
}
# If there was no taker_bond object yet, generate one
escrow_satoshis = (order.last_satoshis
) # Amount was fixed when taker bond was locked
escrow_satoshis = cls.escrow_amount(order, user)[1]["escrow_amount"] # Amount was fixed when taker bond was locked, fee applied here
description = f"RoboSats - Escrow amount for '{str(order)}' - It WILL FREEZE IN YOUR WALLET. It will be released to the buyer once you confirm you received the fiat. It will automatically return if buyer does not confirm the payment."
# Gen hold Invoice

View File

@ -246,7 +246,8 @@ class OrderView(viewsets.ViewSet):
LNPayment.Status.LOCKED):
# Seller sees the amount he sends
if data["is_seller"]:
data["trade_satoshis"] = order.last_satoshis
data["trade_satoshis"] = Logics.escrow_amount(
order, request.user)[1]["escrow_amount"]
# Buyer sees the amount he receives
elif data["is_buyer"]:
data["trade_satoshis"] = Logics.payout_amount(
@ -334,7 +335,7 @@ class OrderView(viewsets.ViewSet):
if order.payout.status == LNPayment.Status.EXPIRE:
data["invoice_expired"] = True
# Add invoice amount once again if invoice was expired.
data["invoice_amount"] = int(order.last_satoshis * (1 - float(config('FEE'))))
data["invoice_amount"] = Logics.payout_amount(order,request.user)[1]["invoice_amount"]
return Response(data, status.HTTP_200_OK)

View File

@ -295,6 +295,7 @@ bottomBarDesktop =()=>{
<this.StatsDialog/>
<this.CommunityDialog/>
<this.dialogProfile/>
<this.exchangeSummaryDialog/>
<Grid container xs={12}>
<Grid item xs={1.9}>
@ -322,7 +323,7 @@ bottomBarDesktop =()=>{
<Grid item xs={1.9}>
<ListItem className="bottomItem">
<ListItemIcon size="small">
<InventoryIcon/>
<IconButton onClick={this.handleClickOpenExchangeSummary}><InventoryIcon/></IconButton>
</ListItemIcon>
<ListItemText
primaryTypographyProps={{fontSize: '14px'}}
@ -335,7 +336,7 @@ bottomBarDesktop =()=>{
<Grid item xs={1.9}>
<ListItem className="bottomItem">
<ListItemIcon size="small">
<SellIcon/>
<IconButton onClick={this.handleClickOpenExchangeSummary}><SellIcon/></IconButton>
</ListItemIcon>
<ListItemText
primaryTypographyProps={{fontSize: '14px'}}
@ -348,7 +349,7 @@ bottomBarDesktop =()=>{
<Grid item xs={1.9}>
<ListItem className="bottomItem">
<ListItemIcon size="small">
<SmartToyIcon/>
<IconButton onClick={this.handleClickOpenExchangeSummary}><SmartToyIcon/></IconButton>
</ListItemIcon>
<ListItemText
primaryTypographyProps={{fontSize: '14px'}}
@ -361,7 +362,7 @@ bottomBarDesktop =()=>{
<Grid item xs={1.9}>
<ListItem className="bottomItem">
<ListItemIcon size="small">
<PriceChangeIcon/>
<IconButton onClick={this.handleClickOpenExchangeSummary}><PriceChangeIcon/></IconButton>
</ListItemIcon>
<ListItemText
primaryTypographyProps={{fontSize: '14px'}}
@ -374,7 +375,7 @@ bottomBarDesktop =()=>{
<Grid item xs={1.5}>
<ListItem className="bottomItem">
<ListItemIcon size="small">
<PercentIcon/>
< IconButton onClick={this.handleClickOpenExchangeSummary}><PercentIcon/></IconButton>
</ListItemIcon>
<ListItemText
primaryTypographyProps={{fontSize: '14px'}}
@ -429,7 +430,7 @@ bottomBarDesktop =()=>{
this.setState({openExchangeSummary: false});
};
exchangeSummaryDialogPhone =() =>{
exchangeSummaryDialog =() =>{
return(
<Dialog
open={this.state.openExchangeSummary}
@ -511,7 +512,7 @@ bottomBarPhone =()=>{
<Paper elevation={6} style={{height:40}}>
<this.StatsDialog/>
<this.CommunityDialog/>
<this.exchangeSummaryDialogPhone/>
<this.exchangeSummaryDialog/>
<this.dialogProfile/>
<Grid container xs={12}>

View File

@ -920,6 +920,8 @@ handleRatingRobosatsChange=(e)=>{
style: {textAlign:"center"}
}}
multiline
minRows={4}
maxRows={8}
onChange={this.handleInputInvoiceChanged}
/>
</Grid>

File diff suppressed because one or more lines are too long