Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up config.js and PaymentController so it actually works #54

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/components/PaymentController.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';

import { newInvoice, awaitStatus, getPrice } from '../api';
import { invoiceRecipient, invoiceCurrency } from '../config';

import EnterAmount from './EnterAmount';
import FiatAmount from './FiatAmount';
Expand Down Expand Up @@ -30,7 +31,7 @@ class PaymentController extends Component {

constructor(props) {
super(props);
this.state = { fiatAmount: '', exchangeRate: '', bitcoinAmount: '', invoice: '', qrCodeType: 'both', paymentStatus: paymentEnum.REQUESTING_AMOUNT };
this.state = { fiatAmount: '', fiatCurrency: invoiceCurrency, exchangeRate: '', bitcoinAmount: '', recipientDesc: invoiceRecipient, invoice: '', qrCodeType: 'both', paymentStatus: paymentEnum.REQUESTING_AMOUNT };
// this.handleAmountChange = this.handleAmountChange.bind(this);
this.handleAmountConfirm = this.handleAmountConfirm.bind(this);
this.handleNewAmount = this.handleNewAmount.bind(this);
Expand Down Expand Up @@ -67,7 +68,7 @@ class PaymentController extends Component {

async findExchangeRate() {
const price = await getPrice();
const exchangeRate = price.THB;
const exchangeRate = price[this.state.fiatCurrency];

this.setState((prevState) => {
return {
Expand All @@ -79,7 +80,7 @@ class PaymentController extends Component {
}

async generateInvoice() {
const description = `Payment of ${this.state.fiatAmount} THB to LNCM`;
const description = `Payment of ${this.state.fiatAmount} ${this.state.fiatCurrency} to ${this.state.recipientDesc}`;
const invoice = await newInvoice(this.state.bitcoinAmount * 1e8, description);
this.setInvoice(invoice);
}
Expand Down Expand Up @@ -121,7 +122,7 @@ class PaymentController extends Component {
case paymentEnum.REQUESTING_AMOUNT:
return (
<div>
<EnterAmount fiatAmount={this.state.fiatAmount} fiatCurrency="THB" onAmountConfirm={this.handleAmountConfirm} onBitcoinQRCodeChange={this.handleBitcoinQRCodeChange} onLightningQRCodeChange={this.handleLightningQRCodeChange} />
<EnterAmount fiatAmount={this.state.fiatAmount} fiatCurrency={this.state.fiatCurrency} onAmountConfirm={this.handleAmountConfirm} onBitcoinQRCodeChange={this.handleBitcoinQRCodeChange} onLightningQRCodeChange={this.handleLightningQRCodeChange} />
</div>
);
case paymentEnum.FINDING_EXCHANGE_RATE:
Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const baseUrl = '/api';
export const donationDesc = 'LNCM Donation';
export const invoiceDesc = 'LN Payment';
export const invoiceRecipient = 'LNCM';
export const invoiceCurrency = 'THB';

// if editableQrCodeType is set to 'true'
// then the merchant or customer can select the type of QR code they want.
Expand Down