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)
currency = models.PositiveSmallIntegerField(choices=Currencies.choices, null=False)
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)])
# order participants

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','premium','satoshis','maker')
fields = ('id','status','created_at','type','currency','amount','payment_method','premium','satoshis','maker')
class MakeOrderSerializer(serializers.ModelSerializer):
class Meta:
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')
currency = serializer.data.get('currency')
amount = serializer.data.get('amount')
payment_method = serializer.data.get('payment_method')
premium = serializer.data.get('premium')
satoshis = serializer.data.get('satoshis')
@ -30,6 +31,7 @@ class MakeOrder(APIView):
type=otype,
currency=currency,
amount=amount,
payment_method=payment_method,
premium=premium,
satoshis=satoshis)
order.save()

View File

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

File diff suppressed because one or more lines are too long