diff --git a/src/Angor/Client/NetworkConfiguration.cs b/src/Angor/Client/NetworkConfiguration.cs index 6b484480..c6527f0f 100644 --- a/src/Angor/Client/NetworkConfiguration.cs +++ b/src/Angor/Client/NetworkConfiguration.cs @@ -8,29 +8,75 @@ namespace Angor.Client; public class NetworkConfiguration : INetworkConfiguration { public static string AngorTestKey = "tpubD8JfN1evVWPoJmLgVg6Usq2HEW9tLqm6CyECAADnH5tyQosrL6NuhpL9X1cQCbSmndVrgLSGGdbRqLfUbE6cRqUbrHtDJgSyQEY2Uu7WwTL"; + public static string AngorMainKey = "todo: add an Angor key here"; + + private Network currentNetwork; + + public void SetNetwork(Network network) + { + currentNetwork = network; + } public Network GetNetwork() { - return new BitcoinSignet(); + if (currentNetwork == null) + { + throw new ApplicationException("Network not set"); + } + + return currentNetwork; } public SettingsUrl GetIndexerUrl() { - return new SettingsUrl { Name = "", Url = "https://tbtc.indexer.angor.io/api" }; + if (currentNetwork.NetworkType == NetworkType.Testnet) + { + return new SettingsUrl { Name = "", Url = "https://tbtc.indexer.angor.io/api" }; + } + + if (currentNetwork.NetworkType == NetworkType.Mainnet) + { + return new SettingsUrl { Name = "", Url = "https://btc.indexer.angor.io/api" }; + } + + throw new ApplicationException("Network not set"); } public SettingsUrl GetExplorerUrl() { + if (currentNetwork.NetworkType == NetworkType.Testnet) + { + return new SettingsUrl { Name = "", Url = "https://explorer.angor.io/tbtc/explorer" }; + } + + if (currentNetwork.NetworkType == NetworkType.Mainnet) + { + return new SettingsUrl { Name = "", Url = "https://explorer.angor.io/btc/explorer" }; + } - return new SettingsUrl { Name = "", Url = "https://explorer.angor.io/tbtc/explorer" }; + throw new ApplicationException("Network not set"); } public List GetDefaultIndexerUrls() { - return new List + if (currentNetwork.NetworkType == NetworkType.Testnet) { - new SettingsUrl { Name = "", Url = "https://tbtc.indexer.angor.io", IsPrimary = true }, - }; + return new List + { + new SettingsUrl { Name = "", Url = "https://tbtc.indexer.angor.io", IsPrimary = true }, + }; + } + + if (currentNetwork.NetworkType == NetworkType.Mainnet) + { + return new List + { + new SettingsUrl { Name = "", Url = "https://btc.indexer.angor.io", IsPrimary = true }, + }; + } + + throw new ApplicationException("Network not set"); + } public List GetDefaultRelayUrls() @@ -45,58 +91,23 @@ public List GetDefaultRelayUrls() public List GetDefaultExplorerUrl() { - return new List + if (currentNetwork.NetworkType == NetworkType.Testnet) { - new SettingsUrl { Name = "", Url = "https://explorer.angor.io/tbtc/explorer", IsPrimary = true }, - }; - } + return new List + { + new SettingsUrl { Name = "", Url = "https://explorer.angor.io/tbtc/explorer", IsPrimary = true }, + }; + } - public static List CreateFakeProjects() - { - return new List + if (currentNetwork.NetworkType == NetworkType.Mainnet) + { + return new List { - new ProjectInfo - { - StartDate = DateTime.UtcNow, - PenaltyDays = 100, - ExpiryDate = DateTime.UtcNow, - TargetAmount = 300, - ProjectIdentifier = "angor" + Guid.NewGuid().ToString("N"), - Stages = new List - { - new Stage { AmountToRelease = 10, ReleaseDate = DateTime.UtcNow.AddDays(1) }, - new Stage { AmountToRelease = 30, ReleaseDate = DateTime.UtcNow.AddDays(2) }, - new Stage { AmountToRelease = 60, ReleaseDate = DateTime.UtcNow.AddDays(3) }, - } - }, - new ProjectInfo - { - StartDate = DateTime.UtcNow, - PenaltyDays = 100, - ExpiryDate = DateTime.UtcNow, - TargetAmount = 200, - ProjectIdentifier = "angor" + Guid.NewGuid().ToString("N"), - Stages = new List - { - new Stage { AmountToRelease = 10, ReleaseDate = DateTime.UtcNow.AddDays(1) }, - new Stage { AmountToRelease = 30, ReleaseDate = DateTime.UtcNow.AddDays(2) }, - new Stage { AmountToRelease = 60, ReleaseDate = DateTime.UtcNow.AddDays(3) }, - } - }, - new ProjectInfo - { - StartDate = DateTime.UtcNow, - PenaltyDays = 100, - ExpiryDate = DateTime.UtcNow, - TargetAmount = 100, - ProjectIdentifier = "angor" + Guid.NewGuid().ToString("N"), - Stages = new List - { - new Stage { AmountToRelease = 10, ReleaseDate = DateTime.UtcNow.AddDays(1) }, - new Stage { AmountToRelease = 30, ReleaseDate = DateTime.UtcNow.AddDays(2) }, - new Stage { AmountToRelease = 60, ReleaseDate = DateTime.UtcNow.AddDays(3) }, - } - }, + new SettingsUrl { Name = "", Url = "https://explorer.angor.io/btc/explorer", IsPrimary = true }, }; + } + + throw new ApplicationException("Network not set"); } + } \ No newline at end of file diff --git a/src/Angor/Client/Pages/Settings.razor b/src/Angor/Client/Pages/Settings.razor index 44b1e131..a78b6547 100644 --- a/src/Angor/Client/Pages/Settings.razor +++ b/src/Angor/Client/Pages/Settings.razor @@ -12,6 +12,7 @@ @inject IWalletStorage _walletStorage; @inject NavMenuState NavMenuState @inject ILogger Logger; +@inject NavigationManager _navManager @inherits BaseComponent @@ -58,6 +59,17 @@ {

Please tick the box to wipe all storage!

} + +
+ + +
+ + +
@@ -190,6 +202,7 @@ private bool showWipeallModal = false; private bool confirmWipe = false; private bool showConfirmWipeMessage = false; + private string selectedNetwork = "testnet"; // Default to "testnet" private SettingsInfo settingsInfo; @@ -201,6 +214,9 @@ networkType = _networkConfiguration.GetNetwork().Name; + if (!networkType.ToLower().Contains("test")) + selectedNetwork = "mainnet"; + return base.OnInitializedAsync(); } @@ -389,8 +405,12 @@ showWipeallModal = false; showConfirmWipeMessage = false; + _networkService.CheckAndSetNetwork(_navManager.Uri.ToLower(), selectedNetwork); _networkService.AddSettingsIfNotExist(); + networkType = _networkConfiguration.GetNetwork().Name; + settingsInfo = _clientStorage.GetSettingsInfo(); + hasWallet = _walletStorage.HasWallet(); StateHasChanged(); diff --git a/src/Angor/Client/Pages/Wallet.razor b/src/Angor/Client/Pages/Wallet.razor index 9357e2b4..9a70fcc5 100644 --- a/src/Angor/Client/Pages/Wallet.razor +++ b/src/Angor/Client/Pages/Wallet.razor @@ -947,15 +947,15 @@ var res = await _httpClient.GetAsync($"/api/faucet/send/{receiveAddress}"); - if (res.IsSuccessStatusCode) - { - var trxhex = await res.Content.ReadAsStringAsync(); - var trx = network.CreateTransaction(trxhex); - var unconfirmedInboundFunds = _cacheStorage.GetUnconfirmedInboundFunds(); - unconfirmedInboundFunds.Add(new UtxoData { PendingSpent = true, address = receiveAddress, value = trx.Outputs.FirstOrDefault()?.Value.Satoshi ?? Money.Coins(50).Satoshi, outpoint = new Outpoint(trx.GetHash().ToString(), 0) }); - _cacheStorage.SetUnconfirmedInboundFunds(unconfirmedInboundFunds); - accountBalanceInfo.UpdateAccountBalanceInfo(accountBalanceInfo.AccountInfo, unconfirmedInboundFunds); - } + res.EnsureSuccessStatusCode(); + + var trxhex = await res.Content.ReadAsStringAsync(); + var trx = network.CreateTransaction(trxhex); + var unconfirmedInboundFunds = _cacheStorage.GetUnconfirmedInboundFunds(); + unconfirmedInboundFunds.Add(new UtxoData { PendingSpent = true, address = receiveAddress, value = trx.Outputs.FirstOrDefault()?.Value.Satoshi ?? Money.Coins(50).Satoshi, outpoint = new Outpoint(trx.GetHash().ToString(), 0) }); + _cacheStorage.SetUnconfirmedInboundFunds(unconfirmedInboundFunds); + accountBalanceInfo.UpdateAccountBalanceInfo(accountBalanceInfo.AccountInfo, unconfirmedInboundFunds); + } catch (Exception e) { diff --git a/src/Angor/Client/Program.cs b/src/Angor/Client/Program.cs index af8fcb7f..1f2aadef 100644 --- a/src/Angor/Client/Program.cs +++ b/src/Angor/Client/Program.cs @@ -21,7 +21,7 @@ builder.Services.AddBlazoredLocalStorage(); builder.Services.AddBlazoredSessionStorage(); -builder.Services.AddTransient(); +builder.Services.AddSingleton(); builder.Services.AddTransient(); builder.Services.AddTransient (); builder.Services.AddTransient(); diff --git a/src/Angor/Client/Shared/MainLayout.razor b/src/Angor/Client/Shared/MainLayout.razor index 1f847b2c..9aa70438 100644 --- a/src/Angor/Client/Shared/MainLayout.razor +++ b/src/Angor/Client/Shared/MainLayout.razor @@ -1,7 +1,14 @@ @using Angor.Client.Storage @using System.Reflection +@using Angor.Shared +@using Angor.Shared.Networks +@using Angor.Shared.Services +@using Blockcore.Networks @inherits LayoutComponentBase @inject IJSRuntime Js; +@inject INetworkConfiguration _networkConfiguration +@inject INetworkService _networkService +@inject NavigationManager _navManager