Fix order detail page view. Add explicit to model as pricing method boolean explicit/relative

This commit is contained in:
Reckless_Satoshi 2022-01-02 05:24:35 -08:00
parent 298efc394b
commit c4b625a993
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
5 changed files with 21 additions and 15 deletions

View File

@ -53,6 +53,7 @@ class Order(models.Model):
payment_method = models.CharField(max_length=30, null=False, default="Not specified")
premium = models.DecimalField(max_digits=5, decimal_places=2, default=0, null=True, validators=[MinValueValidator(-100), MaxValueValidator(999)])
satoshis = models.PositiveBigIntegerField(null=True, validators=[MinValueValidator(min_satoshis_trade), MaxValueValidator(max_satoshis_trade)])
explicit = models.BooleanField(default=False, null=False) # pricing method. A explicit amount of sats, or a relative premium above/below market.
# order participants
maker = models.ForeignKey(User, related_name='maker', on_delete=models.SET_NULL, null=True, default=None) # unique = True, a maker can only make one order

View File

@ -4,9 +4,9 @@ from .models import Order
class OrderSerializer(serializers.ModelSerializer):
class Meta:
model = Order
fields = ('id','status','created_at','type','currency','amount','payment_method','premium','satoshis','maker','taker')
fields = ('id','status','created_at','type','currency','amount','payment_method','explicit','premium','satoshis','maker','taker')
class MakeOrderSerializer(serializers.ModelSerializer):
class Meta:
model = Order
fields = ('type','currency','amount','payment_method','premium','satoshis')
fields = ('type','currency','amount','payment_method','explicit','premium','satoshis')

View File

@ -29,7 +29,7 @@ export default class MakerPage extends Component {
constructor(props) {
super(props);
this.state={
isExplicit: false,
explicit: false,
type: 0,
currency: this.defaultCurrency,
currencyCode: this.defaultCurrencyCode,
@ -74,14 +74,14 @@ export default class MakerPage extends Component {
}
handleClickRelative=(e)=>{
this.setState({
isExplicit: false,
explicit: false,
satoshis: null,
premium: 0,
});
}
handleClickExplicit=(e)=>{
this.setState({
isExplicit: true,
explicit: true,
satoshis: 10000,
premium: null,
});
@ -97,6 +97,7 @@ export default class MakerPage extends Component {
currency: this.state.currency,
amount: this.state.amount,
payment_method: this.state.payment_method,
explicit: this.state.explicit,
premium: this.state.premium,
satoshis: this.state.satoshis,
}),
@ -221,7 +222,7 @@ export default class MakerPage extends Component {
</FormControl>
</Grid>
{/* conditional shows either Premium % field or Satoshis field based on pricing method */}
{ this.state.isExplicit
{ this.state.explicit
? <Grid item xs={12} align="center">
<FormControl >
<TextField
@ -269,7 +270,7 @@ export default class MakerPage extends Component {
<Typography component="subtitle2" variant="subtitle2">
<div align='center'>
Create a BTC {this.state.type==0 ? "buy":"sell"} order for {this.state.amount} {this.state.currencyCode}
{this.state.isExplicit ? " of " + this.state.satoshis + " Satoshis" :
{this.state.explicit ? " of " + this.state.satoshis + " Satoshis" :
(this.state.premium == 0 ? " at market price" :
(this.state.premium > 0 ? " at a " + this.state.premium + "% premium":" at a " + -this.state.premium + "% discount")
)

View File

@ -11,6 +11,7 @@ export default class OrderPage extends Component {
is_participant: false,
amount: 1,
paymentMethod:"",
explicit: false,
premium: 0,
satoshis: null,
makerId: "",
@ -19,10 +20,11 @@ export default class OrderPage extends Component {
// takerNick:"",
};
this.orderId = this.props.match.params.orderId;
this.getOrderDetails();
}
get_order_details() {
fetch('api/order' + '?order_id' + this.orderId)
getOrderDetails() {
fetch('/api/order' + '?order_id=' + this.orderId)
.then((response) => response.json())
.then((data) => {
this.setState({
@ -31,9 +33,10 @@ export default class OrderPage extends Component {
currency: data.currency,
amount: data.amount,
paymentMethod: data.payment_method,
premium: data.premium,
makerId: maker,
explicit: data.explicit,
//premium: data.premium,
// satoshis: satoshis,
// makerId: maker,
// isParticipant: is_participant,
// makerNick: maker_nick,
// takerId: taker,
@ -52,8 +55,9 @@ export default class OrderPage extends Component {
<p>Currency: {this.state.currencyCode}</p>
<p>Amount: {this.state.amount}</p>
<p>Payment method: {this.state.paymentMethod}</p>
<p>Premium: {this.state.premium}</p>
<p>Maker: {this.makerId}</p>
<p>Pricing method is explicit: {this.state.explicit.toString()}</p>
{/* <p>Premium: {this.state.premium}</p>
<p>Maker: {this.makerId}</p> */}
</div>
);
}

File diff suppressed because one or more lines are too long