Skip to content

Commit 4832aa5

Browse files
authored
Include DisplayAmountFiat for sep7 validated result (keybase#18061)
* Include DisplayAmountFiat for sep7 validated result * WIP * Include available to send with sep7 validated uri * Fix err check * Fix native available amount * Clarify comment * Add XLM suffix to AvailableToSendNative
1 parent eebdff4 commit 4832aa5

5 files changed

Lines changed: 96 additions & 25 deletions

File tree

‎go/protocol/stellar1/local.go‎

Lines changed: 30 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎go/stellar/stellarsvc/service.go‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,54 @@ func (s *Server) validateStellarURI(mctx libkb.MetaContext, uri string, getter s
647647
MemoType: validated.MemoType,
648648
}
649649

650+
if validated.Amount != "" && validated.AssetCode == "" {
651+
// show how much validate.Amount XLM is in the user's display currency
652+
accountID, err := stellar.GetOwnPrimaryAccountID(mctx)
653+
if err != nil {
654+
return nil, nil, err
655+
}
656+
displayCurrency, err := stellar.GetAccountDisplayCurrency(mctx, accountID)
657+
if err != nil {
658+
return nil, nil, err
659+
}
660+
rate, err := s.remoter.ExchangeRate(mctx.Ctx(), displayCurrency)
661+
if err != nil {
662+
return nil, nil, err
663+
}
664+
outsideAmount, err := stellarnet.ConvertXLMToOutside(validated.Amount, rate.Rate)
665+
if err != nil {
666+
return nil, nil, err
667+
}
668+
fmtWorth, err := stellar.FormatCurrencyWithCodeSuffix(mctx, outsideAmount, rate.Currency, stellarnet.Round)
669+
if err != nil {
670+
return nil, nil, err
671+
}
672+
local.DisplayAmountFiat = fmtWorth
673+
674+
details, err := s.remoter.Details(mctx.Ctx(), accountID)
675+
if err != nil {
676+
return nil, nil, err
677+
}
678+
availableXLM := details.Available
679+
if availableXLM == "" {
680+
availableXLM = "0"
681+
}
682+
fmtAvailableAmountXLM, err := stellar.FormatAmount(mctx, availableXLM, false, stellarnet.Round)
683+
if err != nil {
684+
return nil, nil, err
685+
}
686+
availableAmount, err := stellarnet.ConvertXLMToOutside(availableXLM, rate.Rate)
687+
if err != nil {
688+
return nil, nil, err
689+
}
690+
fmtAvailableWorth, err := stellar.FormatCurrencyWithCodeSuffix(mctx, availableAmount, rate.Currency, stellarnet.Round)
691+
if err != nil {
692+
return nil, nil, err
693+
}
694+
local.AvailableToSendNative = fmtAvailableAmountXLM + " XLM"
695+
local.AvailableToSendFiat = fmtAvailableWorth
696+
}
697+
650698
if validated.TxEnv != nil {
651699
tx := validated.TxEnv.Tx
652700
if tx.SourceAccount.Address() != "" && tx.SourceAccount.Address() != zeroSourceAccount {

‎protocol/avdl/stellar1/local.avdl‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,11 @@ protocol local {
709709
string assetIssuer; // required if assetCode exists
710710
string memo; // optional
711711
string memoType; // required if memo exists
712+
713+
// keybase-specific pay fields
714+
string displayAmountFiat; // "$1.23 USD" (the worth of amount in user's display currency if asset being sent is XLM)
715+
string availableToSendNative;
716+
string availableToSendFiat;
712717
}
713718

714719
ValidateStellarURIResultLocal validateStellarURILocal(int sessionID, string inputURI);

‎protocol/json/stellar1/local.json‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎shared/constants/types/rpc-stellar-gen.tsx‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)