From 70027b17a8d0cbe9b7fd9b0863e147eb3d09eccd Mon Sep 17 00:00:00 2001 From: Mikhail Smirnov <58223117+mismirnov@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:50:06 +0300 Subject: [PATCH] Fix/testnet quotes (#90) * Testnet quotes disabled * TestNet warning added * Disabled currency purchase on iOS * App version 1.26.0 --- atomex.Android/Properties/AndroidManifest.xml | 4 +- atomex.iOS/Info.plist | 4 +- atomex.iOS/atomex.iOS.csproj | 9 ++-- atomex/Resources/AppResources.Designer.cs | 6 +++ atomex/Resources/AppResources.fr.Designer.cs | 6 +++ atomex/Resources/AppResources.fr.resx | 3 ++ atomex/Resources/AppResources.resx | 3 ++ atomex/Resources/AppResources.ru.Designer.cs | 6 +++ atomex/Resources/AppResources.ru.resx | 3 ++ atomex/Resources/AppResources.tr.Designer.cs | 6 +++ atomex/Resources/AppResources.tr.resx | 3 ++ .../CurrencyViewModels/CurrencyViewModel.cs | 15 +++++- .../CurrencyViewModels/TezosTokenViewModel.cs | 11 +++- .../OperationRequestViewModel.cs | 2 +- atomex/ViewModels/DelegateViewModel.cs | 10 +++- atomex/ViewModels/MainViewModel.cs | 30 ++++++++++- .../SendViewModels/Erc20SendViewModel.cs | 5 +- .../SendViewModels/Fa12SendViewModel.cs | 4 ++ .../SendViewModels/Fa2SendViewModel.cs | 4 ++ .../SendViewModels/SendViewModel.cs | 9 ++++ .../TezosTokensSendViewModel.cs | 9 ++++ atomex/Views/MainPage.xaml.cs | 12 +++-- atomex/Views/Popup/TestNetWalletPopup.xaml | 54 +++++++++++++++++++ atomex/Views/Popup/TestNetWalletPopup.xaml.cs | 14 +++++ atomex/atomex.csproj | 4 ++ 25 files changed, 216 insertions(+), 20 deletions(-) create mode 100644 atomex/Views/Popup/TestNetWalletPopup.xaml create mode 100644 atomex/Views/Popup/TestNetWalletPopup.xaml.cs diff --git a/atomex.Android/Properties/AndroidManifest.xml b/atomex.Android/Properties/AndroidManifest.xml index 8bdb8713..dddb215d 100644 --- a/atomex.Android/Properties/AndroidManifest.xml +++ b/atomex.Android/Properties/AndroidManifest.xml @@ -1,6 +1,6 @@  - - + + diff --git a/atomex.iOS/Info.plist b/atomex.iOS/Info.plist index 37a1536c..618c6ee1 100644 --- a/atomex.iOS/Info.plist +++ b/atomex.iOS/Info.plist @@ -24,7 +24,7 @@ CFBundleIdentifier com.atomex.ios CFBundleVersion - 1.25.0 + 1.26.0 UILaunchStoryboardName AtomexLaunchScreen CFBundleName @@ -89,7 +89,7 @@ UIStatusBarStyle UIStatusBarStyleLightContent CFBundleShortVersionString - 1.25 + 1.26 CFBundleLocalizations en diff --git a/atomex.iOS/atomex.iOS.csproj b/atomex.iOS/atomex.iOS.csproj index e1f4e1b3..fb087099 100644 --- a/atomex.iOS/atomex.iOS.csproj +++ b/atomex.iOS/atomex.iOS.csproj @@ -27,9 +27,9 @@ x86_64 None true - Apple Development: Igor Matcak (572BY3ZBQR) + iPhone Distribution NSUrlSessionHandler - VS: com.atomex.ios Development + Atomex Distribution --interpreter 8.0 --interpreter @@ -43,9 +43,10 @@ 4 None x86_64 - Apple Distribution: ATOMEX OU (BJT6S7XYJV) + iPhone Distribution --interpreter 8.0 + Atomex Distribution true @@ -73,7 +74,7 @@ prompt 4 ARM64 - iPhone Distribution + Apple Distribution: ATOMEX OU (BJT6S7XYJV) --interpreter Entitlements.plist true diff --git a/atomex/Resources/AppResources.Designer.cs b/atomex/Resources/AppResources.Designer.cs index 1a44452d..f7e45c76 100644 --- a/atomex/Resources/AppResources.Designer.cs +++ b/atomex/Resources/AppResources.Designer.cs @@ -2618,5 +2618,11 @@ internal static string ReturnToAtomex { return ResourceManager.GetString("ReturnToAtomex", resourceCulture); } } + + internal static string TestNetWalletWarning { + get { + return ResourceManager.GetString("TestNetWalletWarning", resourceCulture); + } + } } } diff --git a/atomex/Resources/AppResources.fr.Designer.cs b/atomex/Resources/AppResources.fr.Designer.cs index 0bd4bf39..827e6555 100644 --- a/atomex/Resources/AppResources.fr.Designer.cs +++ b/atomex/Resources/AppResources.fr.Designer.cs @@ -2618,5 +2618,11 @@ internal static string CameraPermission { return ResourceManager.GetString("CameraPermission", resourceCulture); } } + + internal static string TestNetWalletWarning { + get { + return ResourceManager.GetString("TestNetWalletWarning", resourceCulture); + } + } } } diff --git a/atomex/Resources/AppResources.fr.resx b/atomex/Resources/AppResources.fr.resx index cddb155b..64d7c748 100644 --- a/atomex/Resources/AppResources.fr.resx +++ b/atomex/Resources/AppResources.fr.resx @@ -1357,4 +1357,7 @@ NOTE: Do not sign out or close the application until the swap is completed, othe Camera permission + + You are using a test wallet (TestNet), the coins on which have no real monetary value! Be careful and beware of scammers! + diff --git a/atomex/Resources/AppResources.resx b/atomex/Resources/AppResources.resx index b267b7db..2bd0cd67 100644 --- a/atomex/Resources/AppResources.resx +++ b/atomex/Resources/AppResources.resx @@ -1360,4 +1360,7 @@ NOTE: Do not sign out or close the application until the swap is completed, othe Return back to Atomex + + You are using a test wallet (TestNet), the coins on which have no real monetary value! Be careful and beware of scammers! + diff --git a/atomex/Resources/AppResources.ru.Designer.cs b/atomex/Resources/AppResources.ru.Designer.cs index 19de99c1..ee3a45e1 100644 --- a/atomex/Resources/AppResources.ru.Designer.cs +++ b/atomex/Resources/AppResources.ru.Designer.cs @@ -2618,5 +2618,11 @@ internal static string CameraPermission { return ResourceManager.GetString("CameraPermission", resourceCulture); } } + + internal static string TestNetWalletWarning { + get { + return ResourceManager.GetString("TestNetWalletWarning", resourceCulture); + } + } } } diff --git a/atomex/Resources/AppResources.ru.resx b/atomex/Resources/AppResources.ru.resx index 8636d1f8..b599912d 100644 --- a/atomex/Resources/AppResources.ru.resx +++ b/atomex/Resources/AppResources.ru.resx @@ -1357,4 +1357,7 @@ Доступ к камере + + Вы используете тестовый кошелек (TestNet), монеты на котором не имеют реальной денежной стоимости! Будьте осторожны и остерегайтесь мошенников! + diff --git a/atomex/Resources/AppResources.tr.Designer.cs b/atomex/Resources/AppResources.tr.Designer.cs index 7af68b8e..87a362dd 100644 --- a/atomex/Resources/AppResources.tr.Designer.cs +++ b/atomex/Resources/AppResources.tr.Designer.cs @@ -2618,5 +2618,11 @@ internal static string CameraPermission { return ResourceManager.GetString("CameraPermission", resourceCulture); } } + + internal static string TestNetWalletWarning { + get { + return ResourceManager.GetString("TestNetWalletWarning", resourceCulture); + } + } } } diff --git a/atomex/Resources/AppResources.tr.resx b/atomex/Resources/AppResources.tr.resx index 4e140fd5..6850a63b 100644 --- a/atomex/Resources/AppResources.tr.resx +++ b/atomex/Resources/AppResources.tr.resx @@ -1357,4 +1357,7 @@ NOTE: Do not sign out or close the application until the swap is completed, othe Camera permission + + You are using a test wallet (TestNet), the coins on which have no real monetary value! Be careful and beware of scammers! + diff --git a/atomex/ViewModels/CurrencyViewModels/CurrencyViewModel.cs b/atomex/ViewModels/CurrencyViewModels/CurrencyViewModel.cs index eb635029..86342eae 100644 --- a/atomex/ViewModels/CurrencyViewModels/CurrencyViewModel.cs +++ b/atomex/ViewModels/CurrencyViewModels/CurrencyViewModel.cs @@ -47,7 +47,8 @@ public class CurrencyViewModel : BaseViewModel, IDisposable public bool HasCollectibles => CurrencyCode == TezosConfig.Xtz; public bool HasTokens => CurrencyCode == TezosConfig.Xtz; public bool HasDapps => CurrencyCode == TezosConfig.Xtz; - public bool CanBuy => BuyViewModel.Currencies.Contains(Currency?.Name); + public bool CanBuy => BuyViewModel.Currencies.Contains(Currency?.Name) && + Device.RuntimePlatform != Device.iOS; public bool IsOpenCurrency { get; set; } @@ -160,6 +161,12 @@ public void SubscribeToServices() public void SubscribeToRatesProvider(IQuotesProvider quotesProvider) { + if (quotesProvider == null) + return; + + if (App.Account?.Network == Network.TestNet) + return; + QuotesProvider = quotesProvider; QuotesProvider.QuotesUpdated += OnQuotesUpdatedEventHandler; } @@ -233,7 +240,11 @@ private void OnQuotesUpdatedEventHandler(object sender, EventArgs args) private void UpdateQuotesInBaseCurrency(IQuotesProvider quotesProvider) { - if (quotesProvider == null) return; + if (quotesProvider == null) + return; + + if (App.Account?.Network == Network.TestNet) + return; try { diff --git a/atomex/ViewModels/CurrencyViewModels/TezosTokenViewModel.cs b/atomex/ViewModels/CurrencyViewModels/TezosTokenViewModel.cs index 1e10a2c5..9ada9810 100644 --- a/atomex/ViewModels/CurrencyViewModels/TezosTokenViewModel.cs +++ b/atomex/ViewModels/CurrencyViewModels/TezosTokenViewModel.cs @@ -14,6 +14,7 @@ using Atomex; using Atomex.Blockchain.Tezos; using Atomex.Common; +using Atomex.Core; using Atomex.MarketData.Abstract; using atomex.Models; using Atomex.TezosTokens; @@ -469,7 +470,12 @@ public void SubscribeToUpdates() { _app.Account.BalanceUpdated += OnBalanceUpdatedEventHandler; - if (TokenBalance.IsNft) return; + if (_account.Wallet.Network == Network.TestNet) + return; + + if (TokenBalance.IsNft) + return; + _app.QuotesProvider.QuotesUpdated += OnQuotesUpdatedEventHandler; } @@ -477,6 +483,9 @@ private void OnQuotesUpdatedEventHandler(object sender, EventArgs args) { if (sender is not IQuotesProvider quotesProvider) return; + + if (_app.Account?.Network == Network.TestNet) + return; UpdateQuotesInBaseCurrency(quotesProvider); } diff --git a/atomex/ViewModels/DappsViewModels/OperationRequestViewModel.cs b/atomex/ViewModels/DappsViewModels/OperationRequestViewModel.cs index be187966..bc75cab5 100644 --- a/atomex/ViewModels/DappsViewModels/OperationRequestViewModel.cs +++ b/atomex/ViewModels/DappsViewModels/OperationRequestViewModel.cs @@ -231,7 +231,7 @@ public DelegationContentViewModel() Launcher.OpenAsync(new Uri(uri.ToString())); }); - protected override void OnQuotesUpdatedEventHandler(object? sender, EventArgs args) + protected override void OnQuotesUpdatedEventHandler(object sender, EventArgs args) { if (sender is not IQuotesProvider quotesProvider) return; diff --git a/atomex/ViewModels/DelegateViewModel.cs b/atomex/ViewModels/DelegateViewModel.cs index 5f9fb415..cd0a06e5 100644 --- a/atomex/ViewModels/DelegateViewModel.cs +++ b/atomex/ViewModels/DelegateViewModel.cs @@ -16,6 +16,7 @@ using Atomex.Blockchain.Tezos; using Atomex.Blockchain.Tezos.Internal; using Atomex.Common; +using Atomex.Core; using Atomex.MarketData.Abstract; using Atomex.Wallet; using Atomex.Wallet.Tezos; @@ -649,7 +650,11 @@ private async Task> GetDelegate( private void SubscribeToServices() { - if (!_app.HasQuotesProvider) return; + if (!_app.HasQuotesProvider) + return; + + if (_app.Account?.Network == Network.TestNet) + return; _app.QuotesProvider.QuotesUpdated += OnQuotesUpdatedEventHandler; _app.QuotesProvider.AvailabilityChanged += OnQuotesProviderAvailabilityChangedEventHandler; @@ -659,6 +664,9 @@ private void OnQuotesUpdatedEventHandler(object sender, EventArgs args) { if (sender is not IQuotesProvider quotesProvider) return; + + if (_app.Account?.Network == Network.TestNet) + return; try { diff --git a/atomex/ViewModels/MainViewModel.cs b/atomex/ViewModels/MainViewModel.cs index 8e18451d..9c6d48af 100644 --- a/atomex/ViewModels/MainViewModel.cs +++ b/atomex/ViewModels/MainViewModel.cs @@ -11,10 +11,13 @@ using System; using System.Linq; using System.Threading.Tasks; +using System.Windows.Input; using atomex.Common; +using Atomex.Core; using atomex.ViewModels.ConversionViewModels; using atomex.ViewModels.CurrencyViewModels; using atomex.ViewModels.DappsViewModels; +using atomex.Views.Popup; using ReactiveUI; using ReactiveUI.Fody.Helpers; using Xamarin.Essentials; @@ -26,14 +29,16 @@ namespace atomex.ViewModels public class MainViewModel : BaseViewModel { public IAtomexApp AtomexApp { get; } + [Reactive] private INavigationService NavigationService { get; set; } public SettingsViewModel SettingsViewModel { get; } public ConversionViewModel ConversionViewModel { get; } public PortfolioViewModel PortfolioViewModel { get; } public BuyViewModel BuyViewModel { get; } [Reactive] public ConnectDappViewModel ConnectDappViewModel { get; set; } + public bool IsTestNet { get; set; } public EventHandler Locked; - + public MainViewModel( IAtomexApp app, IAccount account) @@ -70,6 +75,7 @@ public MainViewModel( BuyViewModel = new BuyViewModel(AtomexApp); SettingsViewModel = new SettingsViewModel(AtomexApp, this); PortfolioViewModel.CurrenciesLoaded += OnCurrenciesLoadedEventHandler; + IsTestNet = account?.Wallet.Network == Network.TestNet; _ = TokenDeviceService.SendTokenToServerAsync(App.DeviceToken, App.FileSystem, AtomexApp); @@ -83,6 +89,23 @@ public MainViewModel( await ConnectDappViewModel.OnDeepLinkResult(deepLink); await SecureStorage.SetAsync("DappDeepLink", string.Empty); }); + + this.WhenAnyValue(vm => vm.NavigationService) + .WhereNotNull() + .SubscribeInMainThread(_ => + { + if (!IsTestNet) return; + NavigationService.ShowPopup(new TestNetWalletPopup(this)); + }); + } + + public void SetNavigationService(INavigationService service) + { + NavigationService = service ?? throw new ArgumentNullException(nameof(service)); + PortfolioViewModel.SetNavigationService(service); + SettingsViewModel.SetNavigationService(service); + BuyViewModel.SetNavigationService(service); + ConversionViewModel.SetNavigationService(service); } private void OnCurrenciesLoadedEventHandler(object sender, EventArgs args) @@ -179,5 +202,10 @@ private void OnAtomexClientServiceStatusChangedEventHandler(object sender, Servi atomexClient.SubscribeToMarketData(SubscriptionType.DepthTwenty); } } + + private ICommand _closePopupCommand; + + public ICommand ClosePopupCommand => _closePopupCommand ??= + ReactiveCommand.Create(() => NavigationService?.ClosePopup()); } } diff --git a/atomex/ViewModels/SendViewModels/Erc20SendViewModel.cs b/atomex/ViewModels/SendViewModels/Erc20SendViewModel.cs index b74262c4..1b1799a4 100644 --- a/atomex/ViewModels/SendViewModels/Erc20SendViewModel.cs +++ b/atomex/ViewModels/SendViewModels/Erc20SendViewModel.cs @@ -5,8 +5,8 @@ using atomex.Resources; using Atomex; using Atomex.Blockchain.Abstract; -using atomex.Common; using Atomex.Common; +using Atomex.Core; using Atomex.MarketData.Abstract; using atomex.ViewModels.CurrencyViewModels; using Atomex.Wallet.Ethereum; @@ -162,6 +162,9 @@ protected override void OnQuotesUpdatedEventHandler(object sender, EventArgs arg { if (sender is not IQuotesProvider quotesProvider) return; + + if (App.Account?.Network == Network.TestNet) + return; var quote = quotesProvider.GetQuote(CurrencyCode, BaseCurrencyCode); var ethQuote = quotesProvider.GetQuote(Currency.FeeCurrencyName, BaseCurrencyCode); diff --git a/atomex/ViewModels/SendViewModels/Fa12SendViewModel.cs b/atomex/ViewModels/SendViewModels/Fa12SendViewModel.cs index db5b91ab..125344a4 100644 --- a/atomex/ViewModels/SendViewModels/Fa12SendViewModel.cs +++ b/atomex/ViewModels/SendViewModels/Fa12SendViewModel.cs @@ -9,6 +9,7 @@ using Atomex.Blockchain.Abstract; using atomex.Common; using Atomex.Common; +using Atomex.Core; using Atomex.MarketData.Abstract; using atomex.Models; using Atomex.TezosTokens; @@ -213,6 +214,9 @@ protected override void OnQuotesUpdatedEventHandler(object sender, EventArgs arg if (sender is not IQuotesProvider quotesProvider) return; + if (App.Account?.Network == Network.TestNet) + return; + try { var quote = quotesProvider.GetQuote(CurrencyCode, BaseCurrencyCode); diff --git a/atomex/ViewModels/SendViewModels/Fa2SendViewModel.cs b/atomex/ViewModels/SendViewModels/Fa2SendViewModel.cs index eb11f2ed..120154c7 100644 --- a/atomex/ViewModels/SendViewModels/Fa2SendViewModel.cs +++ b/atomex/ViewModels/SendViewModels/Fa2SendViewModel.cs @@ -9,6 +9,7 @@ using Atomex.Blockchain.Abstract; using atomex.Common; using Atomex.Common; +using Atomex.Core; using Atomex.MarketData.Abstract; using atomex.Models; using Atomex.TezosTokens; @@ -214,6 +215,9 @@ protected override void OnQuotesUpdatedEventHandler(object sender, EventArgs arg { if (sender is not IQuotesProvider quotesProvider) return; + + if (App.Account?.Network == Network.TestNet) + return; var quote = quotesProvider.GetQuote(CurrencyCode, BaseCurrencyCode); var xtzQuote = quotesProvider.GetQuote("XTZ", BaseCurrencyCode); diff --git a/atomex/ViewModels/SendViewModels/SendViewModel.cs b/atomex/ViewModels/SendViewModels/SendViewModel.cs index 4a42a70a..33586902 100644 --- a/atomex/ViewModels/SendViewModels/SendViewModel.cs +++ b/atomex/ViewModels/SendViewModels/SendViewModel.cs @@ -304,6 +304,9 @@ public void SetFeeFromString(string value) private void SubscribeToServices() { + if (App.Account?.Network == Network.TestNet) + return; + if (App.HasQuotesProvider) App.QuotesProvider.QuotesUpdated += OnQuotesUpdatedEventHandler; } @@ -507,6 +510,9 @@ protected virtual void OnQuotesUpdatedEventHandler(object sender, EventArgs args { if (sender is not IQuotesProvider quotesProvider) return; + + if (App.Account?.Network == Network.TestNet) + return; try { @@ -549,6 +555,9 @@ protected void SetRecommededAmountWarning(MessageType messageType, RelatedTo ele public void Dispose() { + if (App.Account?.Network == Network.TestNet) + return; + if (App.HasQuotesProvider) App.QuotesProvider.QuotesUpdated -= OnQuotesUpdatedEventHandler; } diff --git a/atomex/ViewModels/SendViewModels/TezosTokensSendViewModel.cs b/atomex/ViewModels/SendViewModels/TezosTokensSendViewModel.cs index 337a0350..376fbd59 100644 --- a/atomex/ViewModels/SendViewModels/TezosTokensSendViewModel.cs +++ b/atomex/ViewModels/SendViewModels/TezosTokensSendViewModel.cs @@ -290,6 +290,9 @@ public TezosTokensSendViewModel( private void SubscribeToServices() { + if (_app.Account?.Network == Network.TestNet) + return; + if (_app.HasQuotesProvider) _app.QuotesProvider.QuotesUpdated += OnQuotesUpdatedEventHandler; } @@ -775,6 +778,9 @@ protected void OnQuotesUpdatedEventHandler(object sender, EventArgs args) { if (sender is not IQuotesProvider quotesProvider) return; + + if (_app.Account?.Network == Network.TestNet) + return; var quote = quotesProvider.GetQuote(CurrencyCode, BaseCurrencyCode); var feeQuote = quotesProvider.GetQuote(FeeCurrencyCode, BaseCurrencyCode); @@ -877,6 +883,9 @@ protected void ShowMessage(MessageType messageType, RelatedTo element, string te public void Dispose() { + if (_app.Account?.Network == Network.TestNet) + return; + if (_app.HasQuotesProvider) _app.QuotesProvider.QuotesUpdated -= OnQuotesUpdatedEventHandler; } diff --git a/atomex/Views/MainPage.xaml.cs b/atomex/Views/MainPage.xaml.cs index 40196c5d..551c4cba 100644 --- a/atomex/Views/MainPage.xaml.cs +++ b/atomex/Views/MainPage.xaml.cs @@ -78,14 +78,16 @@ public MainPage(MainViewModel mainViewModel) Title = AppResources.BuyTab }; - MainViewModel.SettingsViewModel.SetNavigationService(this); - MainViewModel.BuyViewModel.SetNavigationService(this); - MainViewModel.ConversionViewModel.SetNavigationService(this); - MainViewModel.PortfolioViewModel.SetNavigationService(this); + MainViewModel.SetNavigationService(this); Children.Add(_navigationPortfolioPage); Children.Add(_navigationConversionPage); - Children.Add(_navigationBuyPage); + + if (Device.RuntimePlatform == Device.Android) + { + Children.Add(_navigationBuyPage); + } + Children.Add(_navigationSettingsPage); mainViewModel.Locked += (s, a) => SignOut(); diff --git a/atomex/Views/Popup/TestNetWalletPopup.xaml b/atomex/Views/Popup/TestNetWalletPopup.xaml new file mode 100644 index 00000000..edad505a --- /dev/null +++ b/atomex/Views/Popup/TestNetWalletPopup.xaml @@ -0,0 +1,54 @@ + + + + + + + + + + +