Skip to content

Commit

Permalink
Merge pull request #914 from kaloudis/fiat-conversion-commas
Browse files Browse the repository at this point in the history
Fiat conversion: handle commas
  • Loading branch information
kaloudis authored Mar 30, 2022
2 parents 8d4db2c + 16063a1 commit 33e24a2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
3 changes: 2 additions & 1 deletion views/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ export default class Receive extends React.Component<
break;
case 'fiat':
satAmount = Number(
(Number(value) / Number(rate)) * Number(satoshisPerBTC)
(Number(value.replace(/,/g, '.')) / Number(rate)) *
Number(satoshisPerBTC)
).toFixed(0);
break;
}
Expand Down
54 changes: 32 additions & 22 deletions views/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,19 @@ export default class Send extends React.Component<SendProps, SendState> {
super(props);
const { navigation } = props;
const destination = navigation.getParam('destination', null);
const amount = navigation.getParam('amount', '');
const amount = navigation.getParam('amount', null);
const transactionType = navigation.getParam('transactionType', null);
const isValid = navigation.getParam('isValid', null);
const isValid = navigation.getParam('isValid', false);

if (transactionType === 'Lightning') {
this.props.InvoicesStore.getPayReq(destination);
}

this.state = {
isValid: isValid || false,
transactionType,
destination: destination || '',
amount,
amount: amount || '',
fee: '2',
utxos: [],
utxoBalance: 0,
Expand All @@ -117,6 +121,29 @@ export default class Send extends React.Component<SendProps, SendState> {
}
}

UNSAFE_componentWillReceiveProps(nextProps: any) {
const { navigation } = nextProps;
const destination = navigation.getParam('destination', null);
const amount = navigation.getParam('amount', null);
const transactionType = navigation.getParam('transactionType', null);

if (transactionType === 'Lightning') {
this.props.InvoicesStore.getPayReq(destination);
}

this.setState({
transactionType,
destination,
isValid: true
});

if (amount) {
this.setState({
amount
});
}
}

async componentDidMount() {
if (this.state.destination) {
this.validateAddress(this.state.destination);
Expand Down Expand Up @@ -169,24 +196,6 @@ export default class Send extends React.Component<SendProps, SendState> {
this.setState(newState);
};

UNSAFE_componentWillReceiveProps(nextProps: any) {
const { navigation } = nextProps;
const destination = navigation.getParam('destination', null);
const amount = navigation.getParam('amount', null);
const transactionType = navigation.getParam('transactionType', null);

if (transactionType === 'Lightning') {
this.props.InvoicesStore.getPayReq(destination);
}

this.setState({
transactionType,
destination,
amount,
isValid: true
});
}

validateAddress = (text: string) => {
const { navigation } = this.props;
handleAnything(text)
Expand Down Expand Up @@ -321,7 +330,8 @@ export default class Send extends React.Component<SendProps, SendState> {
break;
case 'fiat':
satAmount = Number(
(Number(amount) / Number(rate)) * Number(satoshisPerBTC)
(Number(amount.replace(/,/g, '.')) / Number(rate)) *
Number(satoshisPerBTC)
).toFixed(0);
break;
}
Expand Down

0 comments on commit 33e24a2

Please sign in to comment.