-
Notifications
You must be signed in to change notification settings - Fork 91
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
Lightning fiat #2574
Lightning fiat #2574
Conversation
907a464
to
8481603
Compare
Requested reviews from both @benma and @thisconnect for backend/frontend 😇 🙏 thanks a lot |
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.
tested a bit, looks very nice. added some comments.
@@ -217,7 +216,7 @@ export function AccountsSummary({ accounts, devices }: TProps) { | |||
totalBalancePerCoin={ balancePerCoin ? balancePerCoin[keystore.rootFingerprint] : undefined} | |||
totalBalance={ accountsTotalBalance ? accountsTotalBalance[keystore.rootFingerprint] : undefined} | |||
balances={balances} | |||
lightningNodeState={(lightningConfig.accounts.length && lightningConfig.accounts[0].rootFingerprint === keystore.rootFingerprint) ? nodeState : undefined} | |||
lightningBalance={(lightningConfig.accounts.length && lightningConfig.accounts[0].rootFingerprint === keystore.rootFingerprint) ? lightningBalance : undefined} |
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.
This component doesn't really need lightningConfig
and lightningBalance
as those are only used in SummaryBalance component, wdyt about moving as much s possible into SummaryBalance?
you'll probably have to pass keystore.rootFingerprint
as well somehow for the condition.
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.
yeah, I moved the LN logic inside the component and refactored a bit to only pass it the keystore struct, instead of various fields belonging to it.
func (lightning *Lightning) GetBalance(_ *http.Request) interface{} { | ||
balance, err := lightning.Balance() | ||
if err != nil { | ||
return responseDto{Success: false, ErrorMessage: err.Error()} |
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 does Dto
mean? man i really dislike abbreviations lol
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.
It's Data Transfer Object. It's quite used as an abbreviation, afaik.
backend/lightning/lightning.go
Outdated
@@ -154,13 +167,51 @@ func (lightning *Lightning) Deactivate() error { | |||
return nil | |||
} | |||
|
|||
// AssertActive returns an error if the lightning service not has been activated. | |||
func (lightning *Lightning) AssertActive() error { |
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.
assert is the wrong word, as assert in all contexts I know (in Python, C, ...), it crashes/panics/exists.
CheckActive
or ValidateActive
would be better.
backend/lightning/lightning.go
Outdated
} | ||
|
||
// Balance returns the balance of the lightning account, together with its conversions to fiat. | ||
func (lightning *Lightning) Balance() (interface{}, error) { |
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.
don't return interface{}
but a concrete type
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.
this function should really return *accounts.Balance
, like btc/account.go and eth/account.go, and the handler should convert to AccountBalance
.
Reason: AccountBalance is frontend focused, and it's the handler's job to convert input/output from/to the frontend.
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.
Agree 👍 done.
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.
Only now I see that the handlers are methods on the same struct :O but the split was still good, as we will hopefully refactor this later and make a clean split 😄
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.
Yeah, we should definitely refactor the lightning handlers to belong to the handlers package, as done in the other places, but didn't want to do it now 😬 So that we can also use handlers.formatAmountAsJSON()
backend/lightning/lightning.go
Outdated
// Balance returns the balance of the lightning account, together with its conversions to fiat. | ||
func (lightning *Lightning) Balance() (interface{}, error) { | ||
if err := lightning.AssertActive(); err != nil { | ||
return coin.FormattedAmount{}, err |
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.
return nil, err
backend/lightning/lightning.go
Outdated
|
||
nodeInfo, err := lightning.sdkService.NodeInfo() | ||
if err != nil { | ||
return coin.FormattedAmount{}, err |
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.
return nil, err
backend/lightning/lightning.go
Outdated
return coin.FormattedAmount{}, err | ||
} | ||
|
||
amount := coin.NewAmount(big.NewInt(int64(nodeInfo.ChannelsBalanceMsat / 1000))) |
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 is coin.NewAmountFromInt64()
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.
Nice! thanks
backend/accounts/account.go
Outdated
@@ -32,6 +32,14 @@ type AddressList struct { | |||
Addresses []Address | |||
} | |||
|
|||
// AccountBalance includes the total and incoming balance of an account. | |||
type AccountBalance struct { |
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 is already a Balance
struct (in balance.go). making this ultra confusing.
Maybe move this to balance.go too and name it FormattedAccountBalance
.
FormattedAmount is needed inside the lightning package. Moving it into the `coin` package allow us to import it there too. Same for AccountBalance, which is explicitly declared inside `accounts`.
Adds a new backend endpoint that allows to fetch the node balance and the relative fiat conversions.
8481603
to
40976c9
Compare
Rebased and addressed comments. @benma @thisconnect PTAL 🙏 |
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.
Thanks, utACK
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.
tested LGTM 👍
This is a first PR to start adding Fiat conversion support for lightning.
Fiat conversions for LN send/receive will be addressed in a separate PR.