protected override async void OnAppearing() { base.OnAppearing(); Device.StartTimer(TimeSpan.FromSeconds(0.3), () => { canvasView.InvalidateSurface(); lock (drawStageLock) { if (drawStage < 0) { return(false); } drawStage++; if (drawStage > MAX_DRAW_STAGE) { drawStage = 0; } } return(true); // True = Repeat again, False = Stop the timer }); if (Device.RuntimePlatform == Device.Android) { var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location); if (status != PermissionStatus.Granted) { if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location)) { await DisplayAlert("Need Location Permission", "Soter Wallet needs Location Permission in order to search for the device.", "OK"); } var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location); //Best practice to always check that the key exists if (results.ContainsKey(Permission.Location)) { status = results[Permission.Location]; } } if (status != PermissionStatus.Granted) { await DisplayAlert("Location Permission Denied", "Can not continue, try again.", "OK"); } } ISoterDevice device = null; await SoterDeviceFactoryBle.Instance.StartDeviceSearchAsync(); Log.Information("Wait for search results"); await Task.Delay(500); Log.Information("Wait finished"); await SoterDeviceFactoryBle.Instance.StopDeviceSearchAsync(); Log.Information("Search stopped"); if (SoterDeviceFactoryBle.Instance.Devices.Count == 0) { await DisplayAlert("Error", "Can't find any Soter Wallet device!", "OK"); } else if (SoterDeviceFactoryBle.Instance.Devices.Count == 1) { device = SoterDeviceFactoryBle.Instance.Devices.First(); } else { var action = await DisplayActionSheet("Select the device", "Cancel", null, SoterDeviceFactoryBle.Instance.Devices.Select(d => d.Name).ToArray()); device = SoterDeviceFactoryBle.Instance.Devices.FirstOrDefault(d => d.Name.Equals(action)); } if (device != null) { try { await SoterDeviceFactoryBle.Instance.ConnectByIdAsync(device.Id); await device.InitializeAsync(); lock (drawStageLock) { drawStage = -1; } if (device.Features.Initialized) { await DeviceCommPage.UpdateCoinTable(this); Application.Current.MainPage = new NavigationPage(new MainTabbedPage()); return; } else { Application.Current.MainPage = new NavigationPage(new DeviceLabelPage()); return; } } catch (Exception ex) { Log.Error(ex.ToString()); await DisplayAlert("Error", "Can't connect to the Soter Wallet!", "OK"); } } Application.Current.MainPage = new StartPairingPage(); }
static async Task ResetDevice() { IEnumerable <CoinType> coinTable; await SoterDeviceFactoryHid.Instance.StartDeviceSearchAsync(); await Task.Delay(1000); await SoterDeviceFactoryHid.Instance.StopDeviceSearchAsync(); if (SoterDeviceFactoryHid.Instance.Devices.Count == 0) { throw new Exception("Do Soter Wallet device detected!"); } _soterDevice = (SoterDeviceHid)SoterDeviceFactoryHid.Instance.Devices.FirstOrDefault(); _soterDevice.EnterPinCallback = _soterDevice_EnterPinCallback;; await _soterDevice.InitializeAsync(); await _soterDevice.CancelAsync(); if (_soterDevice.Features.Initialized) { coinTable = await _soterDevice.GetCoinTableAsync(24); _soterDevice.CoinUtility = new CoinUtility(coinTable); //Get Bitcoin Testnet Address Log.Information(await GetAddressAsync(1, false, 0, false, false, false)); await _soterDevice.WipeDeviceAsync(); } await _soterDevice.ResetDeviceAsync("Digbig Wallet"); await _soterDevice.InitializeAsync(); if (!_soterDevice.Features.Initialized) { Log.Error("Reset Device Failed!!!"); return; } await _soterDevice.ChangePinAsync(); await _soterDevice.ChangeAutoLockDelayAsync(1200000); await _soterDevice.ChangeDeviceNameAsync("Test Wallet"); coinTable = await _soterDevice.GetCoinTableAsync(); _soterDevice.CoinUtility = new CoinUtility(coinTable); //Get Bitcoin Address Log.Information(await GetAddressAsync(0, false, 0, false)); Log.Information(await GetAddressAsync(0, false, 0, false, true, false)); Log.Information(await GetAddressAsync(0, false, 0, false, true, true)); Log.Information(await GetAddressAsync(0, false, 0, true)); //Get Litecoin Address Log.Information(await GetAddressAsync(2, false, 0, false)); //Get Dodge Address Log.Information(await GetAddressAsync(3, false, 0, false)); //Get Dash Address Log.Information(await GetAddressAsync(5, false, 0, false)); //Get Ethereum Address Log.Information(await GetAddressAsync(60, false, 0, false)); //Get BitcoinCash Address Log.Information(await GetAddressAsync(145, false, 0, false)); //await SignBitcoinTransactionAsync(); Log.Information("All Done!"); }