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") 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)]) 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)]) 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 # 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 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 OrderSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Order 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 MakeOrderSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Order 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) { constructor(props) {
super(props); super(props);
this.state={ this.state={
isExplicit: false, explicit: false,
type: 0, type: 0,
currency: this.defaultCurrency, currency: this.defaultCurrency,
currencyCode: this.defaultCurrencyCode, currencyCode: this.defaultCurrencyCode,
@ -74,14 +74,14 @@ export default class MakerPage extends Component {
} }
handleClickRelative=(e)=>{ handleClickRelative=(e)=>{
this.setState({ this.setState({
isExplicit: false, explicit: false,
satoshis: null, satoshis: null,
premium: 0, premium: 0,
}); });
} }
handleClickExplicit=(e)=>{ handleClickExplicit=(e)=>{
this.setState({ this.setState({
isExplicit: true, explicit: true,
satoshis: 10000, satoshis: 10000,
premium: null, premium: null,
}); });
@ -97,6 +97,7 @@ export default class MakerPage extends Component {
currency: this.state.currency, currency: this.state.currency,
amount: this.state.amount, amount: this.state.amount,
payment_method: this.state.payment_method, payment_method: this.state.payment_method,
explicit: this.state.explicit,
premium: this.state.premium, premium: this.state.premium,
satoshis: this.state.satoshis, satoshis: this.state.satoshis,
}), }),
@ -221,7 +222,7 @@ export default class MakerPage extends Component {
</FormControl> </FormControl>
</Grid> </Grid>
{/* conditional shows either Premium % field or Satoshis field based on pricing method */} {/* conditional shows either Premium % field or Satoshis field based on pricing method */}
{ this.state.isExplicit { this.state.explicit
? <Grid item xs={12} align="center"> ? <Grid item xs={12} align="center">
<FormControl > <FormControl >
<TextField <TextField
@ -269,7 +270,7 @@ export default class MakerPage extends Component {
<Typography component="subtitle2" variant="subtitle2"> <Typography component="subtitle2" variant="subtitle2">
<div align='center'> <div align='center'>
Create a BTC {this.state.type==0 ? "buy":"sell"} order for {this.state.amount} {this.state.currencyCode} 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 market price" :
(this.state.premium > 0 ? " at a " + this.state.premium + "% premium":" at a " + -this.state.premium + "% discount") (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, is_participant: false,
amount: 1, amount: 1,
paymentMethod:"", paymentMethod:"",
explicit: false,
premium: 0, premium: 0,
satoshis: null, satoshis: null,
makerId: "", makerId: "",
@ -19,10 +20,11 @@ export default class OrderPage extends Component {
// takerNick:"", // takerNick:"",
}; };
this.orderId = this.props.match.params.orderId; this.orderId = this.props.match.params.orderId;
this.getOrderDetails();
} }
get_order_details() { getOrderDetails() {
fetch('api/order' + '?order_id' + this.orderId) fetch('/api/order' + '?order_id=' + this.orderId)
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
this.setState({ this.setState({
@ -31,9 +33,10 @@ export default class OrderPage extends Component {
currency: data.currency, currency: data.currency,
amount: data.amount, amount: data.amount,
paymentMethod: data.payment_method, paymentMethod: data.payment_method,
premium: data.premium, explicit: data.explicit,
makerId: maker, //premium: data.premium,
// satoshis: satoshis, // satoshis: satoshis,
// makerId: maker,
// isParticipant: is_participant, // isParticipant: is_participant,
// makerNick: maker_nick, // makerNick: maker_nick,
// takerId: taker, // takerId: taker,
@ -52,8 +55,9 @@ export default class OrderPage extends Component {
<p>Currency: {this.state.currencyCode}</p> <p>Currency: {this.state.currencyCode}</p>
<p>Amount: {this.state.amount}</p> <p>Amount: {this.state.amount}</p>
<p>Payment method: {this.state.paymentMethod}</p> <p>Payment method: {this.state.paymentMethod}</p>
<p>Premium: {this.state.premium}</p> <p>Pricing method is explicit: {this.state.explicit.toString()}</p>
<p>Maker: {this.makerId}</p> {/* <p>Premium: {this.state.premium}</p>
<p>Maker: {this.makerId}</p> */}
</div> </div>
); );
} }

File diff suppressed because one or more lines are too long