Skip to content

Commit e9b862b

Browse files
committed
Frontend.XF/{ReceivePage,FEHelpers}: add bits/sats
With this new TapGestureRecognizer, we allow the user to tap on the BTC amount and switch to bits and sats (and back to BTC if she taps a 3rd time).
1 parent 46d5ef7 commit e9b862b

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

src/GWallet.Frontend.XF/FrontendHelpers.fs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ type internal CurrencyImageSize =
3838

3939
module FrontendHelpers =
4040

41+
type CryptoSubUnit =
42+
| No
43+
| Specific of multiplier:int * caption:string
44+
45+
let Sats =
46+
CryptoSubUnit.Specific(100_000_000, "sats")
47+
let Bits =
48+
CryptoSubUnit.Specific(1_000_000, "bits")
49+
4150
type IGlobalAppState =
4251
[<CLIEvent>]
4352
abstract member Resumed: IEvent<unit> with get
@@ -109,6 +118,7 @@ module FrontendHelpers =
109118

110119
let UpdateBalance (balance: MaybeCached<decimal>) currency usdRate
111120
(maybeFrame: Option<Frame>) (balanceLabel: Label) (fiatBalanceLabel: Label)
121+
(cryptoSubUnit: CryptoSubUnit)
112122
: MaybeCached<decimal> =
113123
let maybeBalanceAmount =
114124
match balance with
@@ -129,8 +139,18 @@ module FrontendHelpers =
129139
| None ->
130140
SPrintF1 "%A (?)" currency, NotFresh(NotAvailable), SPrintF1 "(?) %s" defaultFiatCurrency
131141
| Some balanceAmount ->
132-
let cryptoAmount = Formatting.DecimalAmountRounding CurrencyType.Crypto balanceAmount
133-
let cryptoAmountStr = SPrintF2 "%A %s" currency cryptoAmount
142+
let adjustedBalance =
143+
match cryptoSubUnit with
144+
| No -> balanceAmount
145+
| Specific (multiplier, _caption) ->
146+
balanceAmount * decimal multiplier
147+
let cryptoAmount = Formatting.DecimalAmountRounding CurrencyType.Crypto adjustedBalance
148+
let cryptoAmountStr =
149+
match cryptoSubUnit with
150+
| No ->
151+
SPrintF2 "%A %s" currency cryptoAmount
152+
| Specific (_multiplier, caption) ->
153+
SPrintF2 "%s %A" cryptoAmount caption
134154
let fiatAmount,fiatAmountStr = BalanceInUsdString balanceAmount usdRate
135155
cryptoAmountStr,fiatAmount,fiatAmountStr
136156
MainThread.BeginInvokeOnMainThread(fun _ ->
@@ -159,6 +179,7 @@ module FrontendHelpers =
159179
(Some balanceSet.Widgets.Frame)
160180
balanceSet.Widgets.CryptoLabel
161181
balanceSet.Widgets.FiatLabel
182+
CryptoSubUnit.No
162183
return {
163184
BalanceSet = balanceSet
164185
FiatAmount = fiatAmount
@@ -187,6 +208,7 @@ module FrontendHelpers =
187208
(Some balanceSet.Widgets.Frame)
188209
balanceSet.Widgets.CryptoLabel
189210
balanceSet.Widgets.FiatLabel
211+
CryptoSubUnit.No
190212
return {
191213
BalanceSet = balanceSet
192214
FiatAmount = fiatAmount

src/GWallet.Frontend.XF/ReceivePage.xaml.fs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ type ReceivePage(account: IAccount,
3333
let currencyImg =
3434
mainLayout.FindByName<Image> "currencyImage"
3535

36+
let balanceLabel = mainLayout.FindByName<Label> "balanceLabel"
37+
let fiatBalanceLabel = mainLayout.FindByName<Label> "fiatBalanceLabel"
38+
39+
let tapCryptoLabel accountBalance =
40+
let cryptoSubUnit =
41+
if balanceLabel.Text.StartsWith "BTC" then
42+
FrontendHelpers.Bits
43+
elif balanceLabel.Text.EndsWith "bits" then
44+
FrontendHelpers.Sats
45+
else
46+
FrontendHelpers.CryptoSubUnit.No
47+
FrontendHelpers.UpdateBalance
48+
(NotFresh accountBalance)
49+
account.Currency
50+
usdRate
51+
None
52+
balanceLabel
53+
fiatBalanceLabel
54+
cryptoSubUnit
55+
|> ignore
56+
3657
do
3758
self.Init()
3859

@@ -44,12 +65,17 @@ type ReceivePage(account: IAccount,
4465
{ CryptoLabel = null; FiatLabel = null ; Frame = null })
4566

4667
member __.Init() =
47-
let balanceLabel = mainLayout.FindByName<Label>("balanceLabel")
48-
let fiatBalanceLabel = mainLayout.FindByName<Label>("fiatBalanceLabel")
4968

5069
let accountBalance =
5170
Caching.Instance.RetrieveLastCompoundBalance account.PublicAddress account.Currency
52-
FrontendHelpers.UpdateBalance (NotFresh accountBalance) account.Currency usdRate None balanceLabel fiatBalanceLabel
71+
FrontendHelpers.UpdateBalance
72+
(NotFresh accountBalance)
73+
account.Currency
74+
usdRate
75+
None
76+
balanceLabel
77+
fiatBalanceLabel
78+
FrontendHelpers.CryptoSubUnit.No
5379
|> ignore
5480

5581
// this below is for the case when a new ReceivePage() instance is suddenly created after sending a transaction
@@ -60,11 +86,19 @@ type ReceivePage(account: IAccount,
6086
(Some balanceWidgetsFromBalancePage.Frame)
6187
balanceWidgetsFromBalancePage.CryptoLabel
6288
balanceWidgetsFromBalancePage.FiatLabel
89+
FrontendHelpers.CryptoSubUnit.No
6390
|> ignore
6491

6592
balanceLabel.FontSize <- FrontendHelpers.BigFontSize
6693
fiatBalanceLabel.FontSize <- FrontendHelpers.MediumFontSize
6794

95+
if account.Currency = Currency.BTC then
96+
let cryptoTapGestureRecognizer = TapGestureRecognizer()
97+
cryptoTapGestureRecognizer.Tapped.Subscribe(
98+
fun _ -> tapCryptoLabel accountBalance
99+
) |> ignore
100+
balanceLabel.GestureRecognizers.Add cryptoTapGestureRecognizer
101+
68102
let qrCode = mainLayout.FindByName<ZXingBarcodeImageView> "qrCode"
69103
if isNull qrCode then
70104
failwith "Couldn't find QR code"

0 commit comments

Comments
 (0)