Skip to content

Commit

Permalink
Merge branch 'release/2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
theofanis committed Oct 14, 2024
2 parents b9a829a + b316f3a commit b2f90c8
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 52 deletions.
6 changes: 6 additions & 0 deletions src/BolWallet.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Solution>
<Project Path="BolWallet/BolWallet.csproj">
<Configuration Solution="Debug|Any CPU" Project="Debug|Any CPU|Deploy" />
<Configuration Solution="Release|Any CPU" Project="Release|Any CPU|Deploy" />
</Project>
</Solution>
10 changes: 10 additions & 0 deletions src/BolWallet/Extensions/ConfigureWalletExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Bol.Core.Abstractions;
using Bol.Core.Accessors;
using Bol.Core.Model;
using Bol.Core.Rpc;
using Bol.Core.Rpc.Abstractions;
using Bol.Core.Services;
using Bol.Core.Transactions;
using Microsoft.Extensions.Options;

namespace BolWallet.Extensions;
Expand All @@ -13,6 +16,13 @@ public static IServiceCollection ConfigureWalletServices(this IServiceCollection
services.AddTransient<WalletContextAccessor>();
services.AddTransient<IContextAccessor, BolWalletContextAccessor>();

// For SDK services with a direct or indirect dependency to IOptions<BolConfig>
// make them transient to use a new IOptions<BolConfig> instance properly and
// avoid using an incorrect BolConfig after closing/opening wallets.
services.AddTransient<IRpcClient, RpcClient>();
services.AddTransient<ITransactionService, TransactionService>();
services.AddSingleton<HttpClient>();

services.AddScoped<BolService>();
services.AddSingleton<BolServiceFactory>();
services.AddTransient<IBolService>(sp => sp.GetRequiredService<BolServiceFactory>().Create());
Expand Down
10 changes: 5 additions & 5 deletions src/BolWallet/Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.bol.bolwallet" android:versionCode="2" android:versionName="2.3.0">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:supportsRtl="true" android:label="BoL Wallet"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<queries>
Expand Down
4 changes: 2 additions & 2 deletions src/BolWallet/Platforms/MacCatalyst/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
<string>processing</string>
</array>
<key>CFBundleVersion</key>
<string>2024.1009.1430</string>
<string>2024.1014.1830</string>
<key>CFBundleShortVersionString</key>
<string>2.2.0</string>
<string>2.3.0</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>NSHumanReadableCopyright</key>
Expand Down
4 changes: 2 additions & 2 deletions src/BolWallet/Platforms/iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
<key>NSPhotoLibraryUsageDescription</key>
<string>The app can use the photo library to select photos from your library and use them when creating a new wallet.</string>
<key>CFBundleVersion</key>
<string>2024.1009.1430</string>
<string>2024.1014.1830</string>
<key>CFBundleShortVersionString</key>
<string>2.2.0</string>
<string>2.3.0</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>NSHumanReadableCopyright</key>
Expand Down
14 changes: 7 additions & 7 deletions src/BolWallet/ViewModels/AddMultiCitizenshipViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,24 +142,24 @@ public void ValidateNin()
var nin = MultiCitizenshipModel.Nin;

if (string.IsNullOrWhiteSpace(countryCode) || string.IsNullOrWhiteSpace(nin)) return;
const string Pattern = @"^[A-Z0-9]*$";

string Pattern = _registerContent.NinPerCountryCode[countryCode].Regex;
var regex = new Regex(Pattern);

var ninRequiredDigits = _registerContent.NinPerCountryCode[countryCode].Digits;

bool isNinValid = regex.IsMatch(nin);
bool isNinLengthCorrect = ninRequiredDigits == nin.Length;
bool isNinLengthCorrect = nin.Length == 5;

if (isNinValid && isNinLengthCorrect)
{
NinValidationErrorMessage = "";
return;
}

NinValidationErrorMessage =
$"The National Identification Number (NIN) provided does not match the expected length of {ninRequiredDigits} digits for the country code {countryCode}." +
" Please ensure that only capital letters (A-Z) and numbers are used in the NIN.";
NinValidationErrorMessage =
$"The National Identification Number (NIN) provided does not match the expected length of 5 digits." +
" Please ensure that only capital letters (A-Z) and numbers are used in the NIN.";
}

public string NinValidationErrorMessage { get; set; }
Expand Down
13 changes: 12 additions & 1 deletion src/BolWallet/ViewModels/GetCertifiedViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ public partial class GetCertifiedViewModel : BaseViewModel
private readonly ISecureRepository _secureRepository;
private readonly IBolService _bolService;
private readonly IFileDownloadService _fileDownloadService;
private readonly ICloseWalletService _closeWalletService;

public GetCertifiedViewModel(
INavigationService navigationService,
ISecureRepository secureRepository,
IBolService bolService,
IFileDownloadService fileDownloadService) : base(navigationService)
IFileDownloadService fileDownloadService,
ICloseWalletService closeWalletService) : base(navigationService)
{
_secureRepository = secureRepository;
_bolService = bolService;
_fileDownloadService = fileDownloadService;
_closeWalletService = closeWalletService;
}

[ObservableProperty]
Expand Down Expand Up @@ -50,6 +53,11 @@ public GetCertifiedViewModel(
[ObservableProperty]
private List<CertifierListItem> _certifiers = new();

[ObservableProperty]
private bool _doesNotSupportsThreeDotMenuToolbarItem =
DeviceInfo.Platform == DevicePlatform.iOS ||
DeviceInfo.Platform == DevicePlatform.MacCatalyst;

public async Task Initialize(CancellationToken token)
{
try
Expand Down Expand Up @@ -279,6 +287,9 @@ private async Task DownloadBolWalletAsync(CancellationToken cancellationToken =
{
await _fileDownloadService.DownloadDataAsync(userData.BolWallet, "BolWallet.json", cancellationToken);
}

[RelayCommand]
private async Task CloseWallet() => await _closeWalletService.CloseWallet();
}

public class CertifierListItem
Expand Down
24 changes: 18 additions & 6 deletions src/BolWallet/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,25 @@ private async Task TrySetBolContractHash()
[RelayCommand]
private async Task SwitchNetwork()
{
var confirm = await Application.Current.MainPage.DisplayAlert(
var prompt = await Application.Current.MainPage.DisplayPromptAsync(
"Network Change",
$"The target network will change from {_networkPreferences.Name} to {_networkPreferences.AlternativeName}!!!",
$"Yes, change to {_networkPreferences.AlternativeName}!",
"Cancel, I don't know what I'm doing!");
$"You are currently connected to {_networkPreferences.Name}." +
$"{Environment.NewLine}{Environment.NewLine}" +
$"To switch to {_networkPreferences.AlternativeName}, type its name below:",
keyboard: Keyboard.Plain,
initialValue: "",
accept: $"Yes, change to {_networkPreferences.AlternativeName}!",
cancel: "Cancel, I don't know what I'm doing!");

if (!confirm)
if (string.IsNullOrWhiteSpace(prompt) || !prompt.Equals(_networkPreferences.AlternativeName))
{
await Application.Current.MainPage.DisplayAlert("Network Change",
$"{_networkPreferences.AlternativeName} network name wasn't verified, no switch will occur.",
"OK");

return;
}

IsLoading = true;
LoadingText = "Changing network...";

Expand All @@ -82,6 +90,10 @@ private async Task SwitchNetwork()

LoadingText = string.Empty;
IsLoading = false;

await Application.Current.MainPage.DisplayAlert("Network Change",
$"Switch to {_networkPreferences.Name} network completed successfully.",
"OK");
}

[RelayCommand]
Expand Down
60 changes: 44 additions & 16 deletions src/BolWallet/ViewModels/MainWithAccountViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using CommunityToolkit.Maui.Alerts;

namespace BolWallet.ViewModels;
public partial class MainWithAccountViewModel : BaseViewModel
public partial class MainWithAccountViewModel : BaseViewModel, IDisposable
{
private readonly ISecureRepository _secureRepository;
private readonly IBolService _bolService;
Expand All @@ -14,6 +14,8 @@ public partial class MainWithAccountViewModel : BaseViewModel
private readonly INetworkPreferences _networkPreferences;
private readonly ICloseWalletService _closeWalletService;

private readonly CancellationTokenSource _cts = new();

public string WelcomeText => "Welcome";
public string BalanceText => "Total Balance";
public string AccountText => "Account";
Expand Down Expand Up @@ -147,15 +149,15 @@ public async Task FetchBolAccountData(CancellationToken token)
catch (RpcException ex)
{
IsWhiteListed = false;
await Toast.Make(ex.Message).Show();
await Toast.Make(ex.Message).Show(token);
}

CanWhiteList = !IsWhiteListed && !IsRegistered;
CanRegister = IsWhiteListed && !IsRegistered;
}
catch (Exception ex)
{
await Toast.Make(ex.Message).Show();
await Toast.Make(ex.Message).Show(token);
}
}

Expand All @@ -168,16 +170,22 @@ private async Task Register(CancellationToken token)

await _bolService.Register(token);

while (!IsRegistered)
var cancellationToken = CancellationTokenSource.CreateLinkedTokenSource(_cts.Token, token);

while (!IsRegistered && !cancellationToken.IsCancellationRequested)
{
await Task.Delay(TimeSpan.FromSeconds(5), token);
await FetchBolAccountData(token);
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken.Token);
await FetchBolAccountData(cancellationToken.Token);
}

if (IsRegistered)
{
await Toast.Make("Your Account has been registered.").Show(token);
}
await Toast.Make("Your Account has been registered.").Show();
}
catch (Exception ex)
catch (Exception ex) when (ex is not TaskCanceledException)
{
await Toast.Make(ex.Message).Show();
await Toast.Make(ex.Message).Show(token);
}
finally
{
Expand All @@ -195,16 +203,22 @@ private async Task Whitelist(CancellationToken token)
Uri uri = new Uri($"{_networkPreferences.TargetNetworkConfig.BolCertifierEndpoint}/{MainAddress}");
await Browser.Default.OpenAsync(uri, BrowserLaunchMode.SystemPreferred);

while (!IsWhiteListed)
var cancellationToken = CancellationTokenSource.CreateLinkedTokenSource(_cts.Token, token);

while (!IsWhiteListed && !cancellationToken.IsCancellationRequested)
{
await Task.Delay(TimeSpan.FromSeconds(5), token);
await FetchBolAccountData(token);
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken.Token);
await FetchBolAccountData(cancellationToken.Token);
}

if (IsWhiteListed)
{
await Toast.Make("Your Main Address has been Whitelisted.").Show(token);
}
await Toast.Make("Your Main Address has been Whitelisted.").Show();
}
catch (Exception ex)
catch (Exception ex) when (ex is not TaskCanceledException)
{
await Toast.Make(ex.Message).Show();
await Toast.Make(ex.Message).Show(token);
}
finally
{
Expand Down Expand Up @@ -249,5 +263,19 @@ private async Task NavigateToAccountPage()
}

[RelayCommand]
private async Task CloseWallet() => await _closeWalletService.CloseWallet();
private async Task CloseWallet()
{
await _cts.CancelAsync();
await _closeWalletService.CloseWallet();
}

public void Dispose()
{
if (_cts is { IsCancellationRequested: false })
{
_cts.Cancel();
}

_cts.Dispose();
}
}
51 changes: 39 additions & 12 deletions src/BolWallet/Views/GetCertifiedPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,63 @@
x:DataType="viewModels:GetCertifiedViewModel"
xmlns:helpers="clr-namespace:BolWallet.Helpers"
Title="Certify Your Account"
BackgroundColor="{DynamicResource SecondaryColor}">

BackgroundColor="{DynamicResource SecondaryColor}"
NavigationPage.HasBackButton="False">

<ContentPage.Resources>
<toolkit:InvertedBoolConverter x:Key="InvertedBoolConverter" />
</ContentPage.Resources>

<ContentPage.ToolbarItems>
<ToolbarItem
<ToolbarItem
Text="Download Certification Files"
Order="Primary"
Priority="0"
Command="{Binding DownloadEdiFilesCommand}"
IsEnabled="{Binding IsLoading, Converter={StaticResource InvertedBoolConverter}}" />
<ToolbarItem
Text="Download BolAccount"
Order="Secondary"
Priority="0"
Priority="1"
Command="{Binding DownloadAccountCommand}"
IsEnabled="{Binding IsLoading, Converter={StaticResource InvertedBoolConverter}}" />
<ToolbarItem
Text="Download BolWallet"
Order="Secondary"
Priority="0"
Priority="2"
Command="{Binding DownloadBolWalletCommand}"
IsEnabled="{Binding IsLoading, Converter={StaticResource InvertedBoolConverter}}" />
<ToolbarItem
Text="Download Certification Files"
Order="Primary"
Priority="0"
Command="{Binding DownloadEdiFilesCommand}"
IsEnabled="{Binding IsLoading, Converter={StaticResource InvertedBoolConverter}}" />
<ToolbarItem
Text="Close Wallet"
Order="Secondary"
Priority="3"
Command="{Binding CloseWalletCommand}"
IsEnabled="{Binding IsLoading, Converter={StaticResource InvertedBoolConverter}}"/>
</ContentPage.ToolbarItems>

<ScrollView>
<StackLayout>
<StackLayout Spacing="15" Padding="10" Margin="10,10,20,10" >
<StackLayout Spacing="15" Padding="10" Margin="10,10,20,10"
IsVisible="{Binding DoesNotSupportsThreeDotMenuToolbarItem}">
<Button
Text="Download Certification Files"
BackgroundColor="{DynamicResource Primary}"
TextColor="White"
Command="{Binding DownloadEdiFilesCommand}"
IsVisible="{Binding DoesNotSupportsThreeDotMenuToolbarItem}" />
<Button
Text="Download BoL Account"
BackgroundColor="{DynamicResource Primary}"
TextColor="White"
Command="{Binding DownloadAccountCommand}" />
<Button
Text="Download BoL Wallet"
BackgroundColor="{DynamicResource Primary}"
TextColor="White"
Command="{Binding DownloadBolWalletCommand}" />
</StackLayout>

<StackLayout Spacing="15" Padding="10" Margin="10,10,20,10" >
<Label Text="Refresh" IsVisible="{Binding IsLoading, Converter={StaticResource InvertedBoolConverter}}" VerticalTextAlignment="End" HorizontalTextAlignment="End" FontSize="Small"/>
<ImageButton IsVisible="{Binding IsLoading, Converter={StaticResource InvertedBoolConverter}}" Command="{Binding RefreshCommand}" VerticalOptions="Start" HorizontalOptions="EndAndExpand">
<ImageButton.Source>
Expand Down
Loading

0 comments on commit b2f90c8

Please sign in to comment.