-
Notifications
You must be signed in to change notification settings - Fork 168
Allow input amount in fiat if selected - payment + invoice #465
Conversation
tanx
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll also need a new helper function that calculates the satoshis from fiat. Right now we assume payment.amount is in a btc unit:
https://github.com/lightninglabs/lightning-app/pull/465/files#diff-c103796afd01e866f6af483b8930cf32R88
src/action/payment.js
Outdated
| setAmount({ amount }) { | ||
| if (amount < 0) { | ||
| amount = 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amount is set by the RN TextInput and is a string in the format 0.01.
src/component/field.js
Outdated
| style={[amountStyles.input, style]} | ||
| charWidth={46} | ||
| style={[amountStyles.input, { textAlign: fiat ? 'left' : 'right' }, style]} | ||
| charWidth={40} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heads up that the 46 pixels is required for the TextInput width to scale correctly.
src/component/field.js
Outdated
| <HorizontalExpandingTextInput | ||
| style={[amountStyles.input, style]} | ||
| charWidth={46} | ||
| style={[amountStyles.input, { textAlign: fiat ? 'left' : 'right' }, style]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't change the style in the first iteration. Important part is getting the logic right. We can revisit styling later.
78ab78f to
7a192cd
Compare
|
@tanx should I also be adding this to the |
src/view/invoice.js
Outdated
| }, | ||
| fiatUnit: { | ||
| color: color.blackDark, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also not needed for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. That was an outdated comment.
src/view/invoice.js
Outdated
| const satoshis = fiatToSatoshis(fiatAmount, settings); | ||
| const amount = toAmount(satoshis, settings.unit); | ||
| invoice.setAmount({ amount }); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since when do we put logic in react components? 🙃This logic is unit testable and needs to happen in the actions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol, true.
| </BalanceLabelNumeral> | ||
| <AmountInputField | ||
| autoFocus={true} | ||
| value={store.invoice.amount} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All our TextInputs are currently controlled react components. We need to add this again.
src/view/invoice.js
Outdated
| autoFocus={true} | ||
| value={store.invoice.amount} | ||
| onChangeText={amount => invoice.setAmount({ amount })} | ||
| onChangeText={amount => setAmount(amount, invoice, store.settings)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert back store.invoice.amount should reflect what actually rendered on screen. The actual satoshi value that is passed to the grpc api should be handled in a different variable.
| <BalanceLabelUnit style={styles.unit}>{store.unit}</BalanceLabelUnit> | ||
| <BalanceLabelUnit style={styles.unit}> | ||
| {store.unitLabel} | ||
| </BalanceLabelUnit> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/view/invoice.js
Outdated
| ]} | ||
| > | ||
| $ | ||
| </BalanceLabelNumeral> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens for Euro or GBP? Probably best to rename the current fiat display names to displayLong in config.js like for the btc units and add a short display for the currency symbols being displayed.
src/view/pay-bitcoin.js
Outdated
| ]} | ||
| > | ||
| $ | ||
| </BalanceLabelNumeral> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above...
src/view/pay-bitcoin.js
Outdated
| onChangeText={amount => payment.setAmount({ amount })} | ||
| onChangeText={amount => | ||
| setAmount(amount, payment, store.settings) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above...
src/view/pay-bitcoin.js
Outdated
| const amount = toAmount(satoshis, settings.unit); | ||
| payment.setAmount({ amount }); | ||
| }; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above...
test/unit/helper.spec.js
Outdated
| expect(num, 'to equal', 145030); | ||
| }); | ||
| }); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
7a192cd to
a827c2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@valentinewallace I did a pretty big refactoring, but the code is much cleaner now.
-
The
toAmountandtoSatoshiscan handle both fiat/btc values. This way I could replace all fiat specific helpers. Also, the changes to the actions/computed modules is much more minimally invasive like this. -
The create-channel view also supports fiat input now.
Take a look. Good the merge from my side.

Closes #461
The width of the input field is kinda weird still. I think we should switch to a monospace font for the amounts, which would help a lot for amounts like "11111" etc.