Merge pull request #11 from Reckless-Satoshi/add-payment-method-field

Add payment method field
This commit is contained in:
Reckless_Satoshi 2022-01-02 09:41:41 +00:00 committed by GitHub
commit 012a7add8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 38 deletions

View File

@ -50,7 +50,8 @@ class Order(models.Model):
type = models.PositiveSmallIntegerField(choices=Types.choices, null=False) type = models.PositiveSmallIntegerField(choices=Types.choices, null=False)
currency = models.PositiveSmallIntegerField(choices=Currencies.choices, null=False) currency = models.PositiveSmallIntegerField(choices=Currencies.choices, null=False)
amount = models.DecimalField(max_digits=9, decimal_places=4, validators=[MinValueValidator(0.00001)]) amount = models.DecimalField(max_digits=9, decimal_places=4, validators=[MinValueValidator(0.00001)])
premium = models.DecimalField(max_digits=3, decimal_places=2, default=0, null=True, validators=[MinValueValidator(-100), MaxValueValidator(1000)]) 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)]) satoshis = models.PositiveBigIntegerField(null=True, validators=[MinValueValidator(min_satoshis_trade), MaxValueValidator(max_satoshis_trade)])
# order participants # order participants

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','premium','satoshis','maker') fields = ('id','status','created_at','type','currency','amount','payment_method','premium','satoshis','maker')
class MakeOrderSerializer(serializers.ModelSerializer): class MakeOrderSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Order model = Order
fields = ('type','currency','amount','premium','satoshis') fields = ('type','currency','amount','payment_method','premium','satoshis')

View File

@ -18,6 +18,7 @@ class MakeOrder(APIView):
otype = serializer.data.get('type') otype = serializer.data.get('type')
currency = serializer.data.get('currency') currency = serializer.data.get('currency')
amount = serializer.data.get('amount') amount = serializer.data.get('amount')
payment_method = serializer.data.get('payment_method')
premium = serializer.data.get('premium') premium = serializer.data.get('premium')
satoshis = serializer.data.get('satoshis') satoshis = serializer.data.get('satoshis')
@ -30,6 +31,7 @@ class MakeOrder(APIView):
type=otype, type=otype,
currency=currency, currency=currency,
amount=amount, amount=amount,
payment_method=payment_method,
premium=premium, premium=premium,
satoshis=satoshis) satoshis=satoshis)
order.save() order.save()

View File

@ -23,6 +23,7 @@ export default class MakerPage extends Component {
defaultCurrency = 1; defaultCurrency = 1;
defaultCurrencyCode = 'USD'; defaultCurrencyCode = 'USD';
defaultAmount = 0 ; defaultAmount = 0 ;
defaultPaymentMethod = "Not specified";
defaultPremium = 0; defaultPremium = 0;
constructor(props) { constructor(props) {
@ -33,6 +34,7 @@ export default class MakerPage extends Component {
currency: this.defaultCurrency, currency: this.defaultCurrency,
currencyCode: this.defaultCurrencyCode, currencyCode: this.defaultCurrencyCode,
amount: this.defaultAmount, amount: this.defaultAmount,
payment_method: this.defaultPaymentMethod,
premium: 0, premium: 0,
satoshis: null, satoshis: null,
} }
@ -55,6 +57,11 @@ export default class MakerPage extends Component {
amount: e.target.value, amount: e.target.value,
}); });
} }
handlePaymentMethodChange=(e)=>{
this.setState({
payment_method: e.target.value,
});
}
handlePremiumChange=(e)=>{ handlePremiumChange=(e)=>{
this.setState({ this.setState({
premium: e.target.value, premium: e.target.value,
@ -89,6 +96,7 @@ export default class MakerPage extends Component {
type: this.state.type, type: this.state.type,
currency: this.state.currency, currency: this.state.currency,
amount: this.state.amount, amount: this.state.amount,
payment_method: this.state.payment_method,
premium: this.state.premium, premium: this.state.premium,
satoshis: this.state.satoshis, satoshis: this.state.satoshis,
}), }),
@ -108,11 +116,6 @@ export default class MakerPage extends Component {
</Grid> </Grid>
<Grid item xs={12} align="center"> <Grid item xs={12} align="center">
<FormControl component="fieldset"> <FormControl component="fieldset">
<FormHelperText>
<div align='center'>
Choose Buy or Sell Bitcoin
</div>
</FormHelperText>
<RadioGroup row defaultValue="0" onChange={this.handleTypeChange}> <RadioGroup row defaultValue="0" onChange={this.handleTypeChange}>
<FormControlLabel <FormControlLabel
value="0" value="0"
@ -127,15 +130,15 @@ export default class MakerPage extends Component {
labelPlacement="Top" labelPlacement="Top"
/> />
</RadioGroup> </RadioGroup>
<FormHelperText>
<div align='center'>
Choose Buy or Sell Bitcoin
</div>
</FormHelperText>
</FormControl> </FormControl>
</Grid> </Grid>
<Grid item xs={12} align="center"> <Grid item xs={12} align="center">
<FormControl > <FormControl >
<FormHelperText>
<div align='center'>
Select Payment Currency
</div>
</FormHelperText>
<Select <Select
require={true} require={true}
defaultValue={this.defaultCurrency} defaultValue={this.defaultCurrency}
@ -148,15 +151,15 @@ export default class MakerPage extends Component {
<MenuItem value={2}>EUR</MenuItem> <MenuItem value={2}>EUR</MenuItem>
<MenuItem value={3}>ETH</MenuItem> <MenuItem value={3}>ETH</MenuItem>
</Select> </Select>
<FormHelperText>
<div align='center'>
Select Payment Currency
</div>
</FormHelperText>
</FormControl> </FormControl>
</Grid> </Grid>
<Grid item xs={12} align="center"> <Grid item xs={12} align="center">
<FormControl > <FormControl >
<FormHelperText>
<div align='center'>
Amount of Fiat to Trade
</div>
</FormHelperText>
<TextField <TextField
type="number" type="number"
require={true} require={true}
@ -168,13 +171,30 @@ export default class MakerPage extends Component {
onChange={this.handleAmountChange} onChange={this.handleAmountChange}
/> />
</FormControl> </FormControl>
</Grid>
<Grid item xs={12} align="center">
<FormHelperText> <FormHelperText>
<div align='center'> <div align='center'>
Choose a pricing method Amount of Fiat to Trade
</div> </div>
</FormHelperText> </FormHelperText>
</Grid>
<Grid item xs={12} align="center">
<FormControl >
<TextField
type="text"
require={true}
inputProps={{
style: {textAlign:"center"}
}}
onChange={this.handlePaymentMethodChange}
/>
<FormHelperText>
<div align='center'>
Enter the Payment Method(s)
</div>
</FormHelperText>
</FormControl>
</Grid>
<Grid item xs={12} align="center">
<FormControl component="fieldset"> <FormControl component="fieldset">
<RadioGroup row defaultValue="relative"> <RadioGroup row defaultValue="relative">
<FormControlLabel <FormControlLabel
@ -193,36 +213,38 @@ export default class MakerPage extends Component {
onShow="false" onShow="false"
/> />
</RadioGroup> </RadioGroup>
<FormHelperText >
<div align='center'>
Choose a Pricing Method
</div>
</FormHelperText>
</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.isExplicit
? <Grid item xs={12} align="center"> ? <Grid item xs={12} align="center">
<FormControl > <FormControl >
<FormHelperText>
<div align='center'>
Explicit Amount in Satoshis
</div>
</FormHelperText>
<TextField <TextField
type="number" type="number"
require={true} require={true}
inputProps={{ inputProps={{
// TODO read these from .env file
min:10000 , min:10000 ,
max:500000 ,
style: {textAlign:"center"} style: {textAlign:"center"}
}} }}
onChange={this.handleSatoshisChange} onChange={this.handleSatoshisChange}
defaultValue={this.defaultSatoshis} defaultValue={this.defaultSatoshis}
/> />
<FormHelperText>
<div align='center'>
Explicit Amount in Satoshis
</div>
</FormHelperText>
</FormControl> </FormControl>
</Grid> </Grid>
: <Grid item xs={12} align="center"> : <Grid item xs={12} align="center">
<FormControl > <FormControl >
<FormHelperText>
<div align='center'>
Premium Relative to Market Price (%)
</div>
</FormHelperText>
<TextField <TextField
type="number" type="number"
require={true} require={true}
@ -232,11 +254,18 @@ export default class MakerPage extends Component {
}} }}
onChange={this.handlePremiumChange} onChange={this.handlePremiumChange}
/> />
<FormHelperText>
<div align='center'>
Premium Relative to Market Price (%)
</div>
</FormHelperText>
</FormControl> </FormControl>
</Grid> </Grid>
} }
<Grid item xs={12} align="center"> <Grid item xs={12} align="center">
<Button color="primary" variant="contained" onClick={this.handleCreateOfferButtonPressed}>
Create Order
</Button>
<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}
@ -247,9 +276,6 @@ export default class MakerPage extends Component {
} }
</div> </div>
</Typography> </Typography>
<Button color="primary" variant="contained" onClick={this.handleCreateOfferButtonPressed}>
Create Order
</Button>
</Grid> </Grid>
<Grid item xs={12} align="center"> <Grid item xs={12} align="center">
<Button color="secondary" variant="contained" to="/" component={Link}> <Button color="secondary" variant="contained" to="/" component={Link}>

File diff suppressed because one or more lines are too long