Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Conversation

@valentinewallace
Copy link
Contributor

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.

@valentinewallace valentinewallace requested a review from tanx July 19, 2018 08:35
Copy link
Contributor

@tanx tanx left a 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

setAmount({ amount }) {
if (amount < 0) {
amount = 0;
}
Copy link
Contributor

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.

style={[amountStyles.input, style]}
charWidth={46}
style={[amountStyles.input, { textAlign: fiat ? 'left' : 'right' }, style]}
charWidth={40}
Copy link
Contributor

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.

<HorizontalExpandingTextInput
style={[amountStyles.input, style]}
charWidth={46}
style={[amountStyles.input, { textAlign: fiat ? 'left' : 'right' }, style]}
Copy link
Contributor

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.

@valentinewallace
Copy link
Contributor Author

@tanx should I also be adding this to the Create Channel page?

},
fiatUnit: {
color: color.blackDark,
},
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, when I take this styling out it looks like this:
deepinscreenshot_select-area_20180723135918

Copy link
Contributor

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.

const satoshis = fiatToSatoshis(fiatAmount, settings);
const amount = toAmount(satoshis, settings.unit);
invoice.setAmount({ amount });
};
Copy link
Contributor

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.

Copy link
Contributor Author

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}
Copy link
Contributor

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.

autoFocus={true}
value={store.invoice.amount}
onChangeText={amount => invoice.setAmount({ amount })}
onChangeText={amount => setAmount(amount, invoice, store.settings)}
Copy link
Contributor

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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

]}
>
$
</BalanceLabelNumeral>
Copy link
Contributor

@tanx tanx Jul 23, 2018

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.

]}
>
$
</BalanceLabelNumeral>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above...

onChangeText={amount => payment.setAmount({ amount })}
onChangeText={amount =>
setAmount(amount, payment, store.settings)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above...

const amount = toAmount(satoshis, settings.unit);
payment.setAmount({ amount });
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above...

expect(num, 'to equal', 145030);
});
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@tanx tanx left a 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.

  1. The toAmount and toSatoshis can 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.

  2. The create-channel view also supports fiat input now.

Take a look. Good the merge from my side.

@valentinewallace valentinewallace merged commit 04a4e7f into master Jul 26, 2018
@valentinewallace valentinewallace deleted the fiat-amount-input branch July 26, 2018 23:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants