Skip to content

Commit

Permalink
Frontend.XF: add currency image to Receive Page
Browse files Browse the repository at this point in the history
  • Loading branch information
knocte committed Jan 18, 2024
1 parent 2b61cf9 commit b843f1f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/GWallet.Frontend.XF/BalancesPage.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState,
let tapGestureRecognizer = TapGestureRecognizer()
tapGestureRecognizer.Tapped.Subscribe(fun _ ->
let receivePage () =
ReceivePage(balanceSet.Account, balanceState.UsdRate, self, balanceSet.Widgets)
ReceivePage(balanceSet.Account, readOnly, balanceState.UsdRate, self, balanceSet.Widgets)
:> Page
FrontendHelpers.SwitchToNewPage self receivePage true
) |> ignore
Expand Down
24 changes: 21 additions & 3 deletions src/GWallet.Frontend.XF/FrontendHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type BalanceState = {
UsdRate: MaybeCached<decimal>
}

type internal CurrencyImageSize =
| Small = 60
| Big = 120

module FrontendHelpers =

type IGlobalAppState =
Expand Down Expand Up @@ -411,11 +415,25 @@ module FrontendHelpers =
thisAssemblyName name
ImageSource.FromResource(fullyQualifiedResourceNameForLogo, thisAssembly)

let GetSizedImageSource name size =
let internal GetSizedImageSource name (size: int) =
let sizedName = SPrintF3 "%s_%ix%i" name size size
GetImageSource sizedName

let GetSizedColoredImageSource name color size =
let internal GetSizedColoredImageSource name color (size: CurrencyImageSize) =
let sizedColoredName = SPrintF2 "%s_%s" name color
GetSizedImageSource sizedColoredName size
GetSizedImageSource sizedColoredName (int size)

let internal CreateCurrencyImageSource (currency: Currency) (readOnly: bool) (size: CurrencyImageSize) =
let colour =
if readOnly then
"grey"
else
"red"
let currencyLowerCase = currency.ToString().ToLower()
GetSizedColoredImageSource currencyLowerCase colour size

let internal CreateCurrencyImage (currency: Currency) (readOnly: bool) (size: CurrencyImageSize) =
let imageSource = CreateCurrencyImageSource currency readOnly size
let currencyLogoImg = Image(Source = imageSource, IsVisible = true)
currencyLogoImg

17 changes: 6 additions & 11 deletions src/GWallet.Frontend.XF/LoadingPage.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ type LoadingPage(state: FrontendHelpers.IGlobalAppState, showLogoFirst: bool) as
let readOnlyAccounts = allAccounts.OfType<ReadOnlyAccount>() |> List.ofSeq
|> List.map (fun account -> account :> IAccount)

let CreateImage (currency: Currency) (readOnly: bool) =
let colour =
if readOnly then
"grey"
else
"red"
let currencyLowerCase = currency.ToString().ToLower()
let imageSource = FrontendHelpers.GetSizedColoredImageSource currencyLowerCase colour 60
let currencyLogoImg = Image(Source = imageSource, IsVisible = true)
currencyLogoImg
let GetAllCurrencyCases(): seq<Currency*bool> =
seq {
for currency in Currency.GetAll() do
Expand All @@ -51,7 +41,12 @@ type LoadingPage(state: FrontendHelpers.IGlobalAppState, showLogoFirst: bool) as
let GetAllImages(): seq<(Currency*bool)*Image> =
seq {
for currency,readOnly in GetAllCurrencyCases() do
yield (currency,readOnly),(CreateImage currency readOnly)
let currencyLogo =
FrontendHelpers.CreateCurrencyImage
currency
readOnly
CurrencyImageSize.Small
yield (currency, readOnly), currencyLogo
}
let PreLoadCurrencyImages(): Map<Currency*bool,Image> =
GetAllImages() |> Map.ofSeq
Expand Down
4 changes: 4 additions & 0 deletions src/GWallet.Frontend.XF/ReceivePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<Label x:Name="balanceLabel"
Text="..."
HorizontalOptions="Center" />
<Image
x:Name="currencyImage"
IsVisible="false"
/>
<Label x:Name="fiatBalanceLabel"
Text="..."
HorizontalOptions="Center" />
Expand Down
14 changes: 13 additions & 1 deletion src/GWallet.Frontend.XF/ReceivePage.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ open ZXing.Common
open GWallet.Backend

type ReceivePage(account: IAccount,
readOnly: bool,

// FIXME: should receive an Async<MaybeCached<decimal>> so that we get a fresh rate, just in case
usdRate: MaybeCached<decimal>,
Expand All @@ -29,11 +30,15 @@ type ReceivePage(account: IAccount,
let paymentCaption = "Send Payment"
let paymentCaptionInColdStorage = "Signoff Payment Offline"

let currencyImg =
mainLayout.FindByName<Image> "currencyImage"

do
self.Init()

[<Obsolete(DummyPageConstructorHelper.Warning)>]
new() = ReceivePage(ReadOnlyAccount(Currency.BTC, { Name = "dummy"; Content = fun _ -> "" }, fun _ -> ""),
false,
Fresh 0m,
DummyPageConstructorHelper.PageFuncToRaiseExceptionIfUsedAtRuntime(),
{ CryptoLabel = null; FiatLabel = null ; Frame = null })
Expand Down Expand Up @@ -79,6 +84,13 @@ type ReceivePage(account: IAccount,
paymentButton.IsEnabled <- true
transactionHistoryButton.IsEnabled <- false

currencyImg.Source <-
FrontendHelpers.CreateCurrencyImageSource
account.Currency
readOnly
CurrencyImageSize.Big
currencyImg.IsVisible <- true

// FIXME: remove this workaround below when https://github.com/xamarin/Xamarin.Forms/issues/8843 gets fixed
// TODO: file the UWP bug too
if Device.RuntimePlatform <> Device.macOS && Device.RuntimePlatform <> Device.UWP then () else
Expand All @@ -99,7 +111,7 @@ type ReceivePage(account: IAccount,

member self.OnSendPaymentClicked(_sender: Object, _args: EventArgs) =
let newReceivePageFunc = (fun _ ->
ReceivePage(account, usdRate, balancesPage, balanceWidgetsFromBalancePage) :> Page
ReceivePage(account, readOnly, usdRate, balancesPage, balanceWidgetsFromBalancePage) :> Page
)
let sendPage () =
let newPage = SendPage(account, self, newReceivePageFunc)
Expand Down

0 comments on commit b843f1f

Please sign in to comment.