-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:goldcaddy77/reblocks into feat/qr…
…code-component
- Loading branch information
Showing
3 changed files
with
158 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as React from 'react'; | ||
|
||
import { ACCOUNT_ID, Currency, getCurrentXRBPrice } from '../../lib/'; | ||
|
||
import { PaymentResponse, ReblocksPayment } from './ReblocksPayment'; | ||
|
||
export interface Props { | ||
onSuccess: (data: PaymentResponse) => void; | ||
} | ||
|
||
export interface State { | ||
currentXRBPrice?: number; | ||
xrbPerBeer?: number; | ||
} | ||
|
||
export class BeerForm extends React.Component<Props, State> { | ||
BEER_PRICE = 7.0; | ||
|
||
constructor(props: Props) { | ||
super(props); | ||
this.state = { currentXRBPrice: undefined, xrbPerBeer: undefined }; | ||
} | ||
|
||
componentDidMount() { | ||
this.loadData('USD'); | ||
} | ||
|
||
loadData = (currency?: Currency) => { | ||
getCurrentXRBPrice(currency as Currency) | ||
.then(response => { | ||
console.log('parsed json', response); | ||
console.log('xrb per beer', this.BEER_PRICE / parseFloat(response.price_local)); | ||
this.setState({ | ||
currentXRBPrice: parseFloat(response.price_local), | ||
xrbPerBeer: this.BEER_PRICE / parseFloat(response.price_local) | ||
}); | ||
}) | ||
.catch(ex => { | ||
console.log('parsing failed', ex); | ||
}); | ||
}; | ||
|
||
formatUSD = (value?: number): string => { | ||
if (!value) { | ||
return ''; | ||
} | ||
return `$${value.toFixed(2)}`; | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<p> | ||
Current cost of a delicious IPA in Boston: {this.formatUSD(this.BEER_PRICE)} | ||
<br /> | ||
{this.state.currentXRBPrice && ( | ||
<span>Current cost of XRB in USD: {this.formatUSD(this.state.currentXRBPrice)}</span> | ||
)} | ||
<br /> | ||
{this.state.xrbPerBeer && <span>XRBs in a beer: {this.state.xrbPerBeer}</span>} | ||
</p> | ||
<p style={{ display: this.state.xrbPerBeer }}> | ||
<ReblocksPayment | ||
accountId={ACCOUNT_ID} | ||
amount={(this.state.xrbPerBeer || 0) * 1000000} | ||
onPaymentSuccess={this.props.onSuccess} | ||
/> | ||
</p> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import * as React from 'react'; | ||
// tslint:disable-next-line:no-duplicate-imports | ||
import { ChangeEvent } from 'react'; | ||
|
||
import { ACCOUNT_ID } from '../../lib/'; | ||
|
||
import { PaymentResponse, ReblocksPayment } from './ReblocksPayment'; | ||
|
||
export interface State { | ||
accountId: string; | ||
amount: number; | ||
} | ||
|
||
export interface Props { | ||
onSuccess: (data: PaymentResponse) => void; | ||
} | ||
|
||
export class PaymentForm extends React.Component<Props, State> { | ||
constructor(props: Props) { | ||
super(props); | ||
this.state = { accountId: ACCOUNT_ID, amount: 10000 }; | ||
} | ||
|
||
onChangeAccountId = (event: ChangeEvent<HTMLInputElement>) => { | ||
console.log(event.currentTarget.value); | ||
this.setState({ accountId: event.currentTarget.value }); | ||
}; | ||
|
||
onChangeAmount = (event: ChangeEvent<HTMLInputElement>) => { | ||
console.log(event.currentTarget.value); | ||
this.setState({ amount: parseFloat(event.currentTarget.value) }); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<form> | ||
<p> | ||
Filling in the form below will dynamically change the payment button with the new account | ||
and amount specified | ||
</p> | ||
<fieldset> | ||
<label>Account ID</label> | ||
<input | ||
type="text" | ||
value={this.state.accountId} | ||
placeholder="Account ID" | ||
onChange={this.onChangeAccountId} | ||
/> | ||
<label>Amount (in rai, 1,000,000 rai = 1 XRB)</label> | ||
|
||
<input | ||
type="number" | ||
value={this.state.amount} | ||
placeholder="Amount of rai" | ||
onChange={this.onChangeAmount} | ||
/> | ||
<ReblocksPayment | ||
accountId={this.state.accountId} | ||
amount={this.state.amount} | ||
onPaymentSuccess={this.props.onSuccess} | ||
/> | ||
</fieldset> | ||
</form> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters