Skip to content

Commit eb34099

Browse files
author
Steve Sanders
authored
put "available" in send confirmation from field (keybase#14974)
* add available to stellar balance description in service * add balanceAvailable for send confirm * put amountAvailable in built payment from service * merge error * stories
1 parent 155935f commit eb34099

9 files changed

Lines changed: 38 additions & 24 deletions

File tree

‎go/protocol/stellar1/local.go‎

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

‎go/stellar/build.go‎

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -211,37 +211,40 @@ func BuildPaymentLocal(mctx libkb.MetaContext, arg stellar1.BuildPaymentLocalArg
211211
if err != nil {
212212
log("error getting available balance: %v", err)
213213
} else {
214+
availableToSendFormatted := availableToSendXLM + " XLM"
215+
availableToSendXLMFmt, err := FormatAmount(
216+
availableToSendXLM, false, FmtTruncate)
217+
if err == nil {
218+
availableToSendFormatted = availableToSendXLMFmt + " XLM"
219+
}
220+
if arg.Currency != nil && amountX.rate != nil {
221+
// If the user entered an amount in outside currency and an exchange
222+
// rate is available, attempt to show them available balance in that currency.
223+
availableToSendOutside, err := stellarnet.ConvertXLMToOutside(availableToSendXLM, amountX.rate.Rate)
224+
if err != nil {
225+
log("error converting available-to-send", err)
226+
} else {
227+
formattedATS, err := FormatCurrencyWithCodeSuffix(mctx,
228+
availableToSendOutside, amountX.rate.Currency, FmtTruncate)
229+
if err != nil {
230+
log("error formatting available-to-send", err)
231+
} else {
232+
availableToSendFormatted = formattedATS
233+
}
234+
}
235+
}
214236
cmp, err := stellarnet.CompareStellarAmounts(availableToSendXLM, amountX.amountOfAsset)
215237
switch {
216238
case err != nil:
217239
log("error comparing amounts (%v) (%v): %v", availableToSendXLM, amountX.amountOfAsset, err)
218240
case cmp == -1:
219241
log("Send amount is more than available to send %v > %v", amountX.amountOfAsset, availableToSendXLM)
220242
readyChecklist.amount = false // block sending
221-
res.AmountErrMsg = fmt.Sprintf("Your available to send is *%s XLM*.", availableToSendXLM)
222-
availableToSendXLMFmt, err := FormatAmount(
223-
availableToSendXLM, false, FmtTruncate)
224-
if err == nil {
225-
res.AmountErrMsg = fmt.Sprintf("Your available to send is *%s XLM*.", availableToSendXLMFmt)
226-
}
227-
if arg.Currency != nil && amountX.rate != nil {
228-
// If the user entered an amount in outside currency and an exchange
229-
// rate is available, attempt to show them available balance in that currency.
230-
availableToSendOutside, err := stellarnet.ConvertXLMToOutside(availableToSendXLM, amountX.rate.Rate)
231-
if err != nil {
232-
log("error converting available-to-send", err)
233-
} else {
234-
formattedATS, err := FormatCurrencyWithCodeSuffix(mctx,
235-
availableToSendOutside, amountX.rate.Currency, FmtTruncate)
236-
if err != nil {
237-
log("error formatting available-to-send", err)
238-
} else {
239-
res.AmountErrMsg = fmt.Sprintf("Your available to send is *%s*.", formattedATS)
240-
}
241-
}
242-
}
243+
res.AmountErrMsg = fmt.Sprintf("Your available to send is *%s*.", availableToSendFormatted)
244+
243245
default:
244246
// Welcome back. How was your stay at the error handling hotel?
247+
res.AmountAvailable = availableToSendFormatted + " available"
245248
}
246249
}
247250
}

‎protocol/avdl/stellar1/local.avdl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ protocol local {
312312
string displayAmountFiat; // "$1.23 USD"
313313
@lint("ignore")
314314
boolean sendingIntentionXLM; // true if currency is nil
315+
string amountAvailable; // "3280.435 XLM available"
315316

316317
array<SendBannerLocal> banners;
317318
}

‎protocol/json/stellar1/local.json‎

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

‎shared/actions/__tests__/wallets.test.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const startReduxSaga = Testing.makeStartReduxSaga(walletsSaga, initialStore, sta
3535
const getRoute = getState => getRoutePath(getState().routeTree.routeState, [Tabs.walletsTab])
3636

3737
const buildPaymentRes: RPCStellarTypes.BuildPaymentResLocal = {
38+
amountAvailable: '',
3839
amountErrMsg: '',
3940
banners: null,
4041
displayAmountFiat: '$5.00 USD',

‎shared/constants/types/rpc-stellar-gen.js.flow‎

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

‎shared/constants/types/wallets.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export type _Building = {
9090
}
9191

9292
export type _BuiltPayment = {
93+
amountAvailable: string,
9394
amountErrMsg: string,
9495
banners: ?Array<StellarRPCTypes.SendBannerLocal>,
9596
from: AccountID,

‎shared/constants/wallets.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const makeBuilding: I.RecordFactory<Types._Building> = I.Record({
5050
})
5151

5252
const makeBuiltPayment: I.RecordFactory<Types._BuiltPayment> = I.Record({
53+
amountAvailable: '',
5354
amountErrMsg: '',
5455
banners: null,
5556
displayAmountFiat: '',
@@ -116,6 +117,7 @@ const makeState: I.RecordFactory<Types._State> = I.Record({
116117

117118
const buildPaymentResultToBuiltPayment = (b: RPCTypes.BuildPaymentResLocal) =>
118119
makeBuiltPayment({
120+
amountAvailable: b.amountAvailable,
119121
amountErrMsg: b.amountErrMsg,
120122
banners: b.banners,
121123
displayAmountFiat: b.displayAmountFiat,

‎shared/wallets/confirm-form/participants/container.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const mapStateToProps = state => {
2929
}
3030

3131
return {
32-
fromAccountAssets: fromAccount.balanceDescription,
32+
fromAccountAssets: built.amountAvailable,
3333
fromAccountIsDefault: fromAccount.isDefault,
3434
fromAccountName: fromAccount.name,
3535
recipientAccountAssets,

0 commit comments

Comments
 (0)