private async void BtnAddWallet_Click(System.Object sender, RoutedEventArgs e) { BNWAPI = new BNWalletAPI(); try { GetAccountIDResult gair = BNWAPI.getAccountID(Passphrase.Text, ""); if (gair.success) { GetAccountResult gar = BNWAPI.getAccount(gair.accountRS); if (gar.success) { UADB = new UserAccountsDB(); UA = UADB.Get(gar.name); if (UA != null) { MessageDialog incorrectAlert = new MessageDialog("Wallet Already Exists" + UA.AccountName); incorrectAlert.Title = "Error"; incorrectAlert.Commands.Add(new UICommand("Ok") { Id = 0 }); incorrectAlert.DefaultCommandIndex = 0; var result = await incorrectAlert.ShowAsync(); } else { UARDB = new UserAccountRuntimeDB(); UAR = UARDB.Get(); string password = UAR.Password; UA = new UserAccounts(); string plaintext = Passphrase.Text; string encryptedstring = StringCipher.Encrypt(plaintext); if (gar.name == "") { UA.AccountName = "No Name Set"; } else { UA.AccountName = gar.name; } UA.BurstAddress = gar.accountRS; UA.PassPhrase = encryptedstring; UADB.Save(UA); MessageDialog Success = new MessageDialog("Wallet Added Successfully :" + UA.BurstAddress); Success.Title = "Success"; Success.Commands.Add(new UICommand("Ok") { Id = 0 }); Success.DefaultCommandIndex = 0; var SuccessResult = await Success.ShowAsync(); PopulateWalletList(); } } else { UADB = new UserAccountsDB(); UARDB = new UserAccountRuntimeDB(); UAR = UARDB.Get(); string password = UAR.Password; UA = new UserAccounts(); string plaintext = Passphrase.Text; string encryptedstring = StringCipher.Encrypt(plaintext); UA.AccountName = "Unknown Account"; UA.BurstAddress = gair.accountRS; UA.PassPhrase = encryptedstring; UADB.Save(UA); MessageDialog Success = new MessageDialog("Wallet Added Successfully :" + UA.BurstAddress); Success.Title = "Success"; Success.Commands.Add(new UICommand("Ok") { Id = 0 }); Success.DefaultCommandIndex = 0; var SuccessResult = await Success.ShowAsync(); PopulateWalletList(); } } else { MessageDialog ErrorAlert = new MessageDialog("Received Error: Please enter a valid passphrase for an existing Burstcoin wallet or click the generate new passphrase button."); ErrorAlert.Title = "Error"; ErrorAlert.Commands.Add(new UICommand("Ok") { Id = 0 }); ErrorAlert.DefaultCommandIndex = 0; var result = await ErrorAlert.ShowAsync(); } } catch { MessageDialog ConfirmationDetailsDialog = new MessageDialog("Received Error: Please enter a valid passphrase for an existing Burstcoin wallet or click the generate new passphrase button."); ConfirmationDetailsDialog.Title = "Error"; ConfirmationDetailsDialog.Commands.Add(new UICommand("Ok") { Id = 0 }); var ConfResult = await ConfirmationDetailsDialog.ShowAsync(); } }
public GetAccountIDResult getAccountID(string secretPhrase, string publicKey) { GetAccountIDResult GAIR = new GetAccountIDResult(); BNWalletAPIClasses.ErrorCodes er; HttpResponseMessage resp = new HttpResponseMessage(); string respStr; fp = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("requestType", "getAccountId"), new KeyValuePair <string, string>("secretPhrase", secretPhrase), new KeyValuePair <string, string>("publicKey", publicKey) }); try { resp = client.PostAsync("burst", fp).Result; respStr = resp.Content.ReadAsStringAsync().Result; } catch { respStr = null; } if (!string.IsNullOrEmpty(respStr)) { if (respStr.Contains("\"errorCode\":")) { try { er = JsonConvert.DeserializeObject <BNWalletAPIClasses.ErrorCodes>(respStr); GAIR.success = false; GAIR.errorMsg = er.errorDescription; } catch (Exception e) { GAIR.success = false; GAIR.errorMsg = "Exception Error Deserializing Error Code: " + e.Message; } //GAIR.errorMsg = fp; } else { try { BNWalletAPIClasses.GetAccountIDResponse gair = JsonConvert.DeserializeObject <BNWalletAPIClasses.GetAccountIDResponse>(respStr); GAIR.success = true; GAIR.accountRS = gair.accountRS; GAIR.account = gair.account; } catch (Exception e) { GAIR.success = false; GAIR.errorMsg = "Exception Error Deserializing GetAccountIDResponse: " + e.Message; } } } else { GAIR.success = false; GAIR.errorMsg = "Cannot get Wallet info as Online wallet is possibly offline"; } return(GAIR); }
private async void WalletList_SelectionChanged(object sender, SelectionChangedEventArgs e) { UserAccountsDB userAccountDB = new UserAccountsDB(); UserAccounts[] userAccount = userAccountDB.GetAccountList(); if (WalletList.SelectedItems.Count > 0) { string Wallet = WalletList.SelectedItems[0].ToString(); Balance.Text = ""; BurstAddress.Text = userAccount[userAccountIndex[Wallet]].BurstAddress; string SecretPhrase = StringCipher.Decrypt(userAccount[userAccountIndex[Wallet]].PassPhrase); BNWAPI = new BNWalletAPI(); GetAccountIDResult gair = BNWAPI.getAccountID(SecretPhrase, ""); try { if (gair.success) { GetAccountResult gar = BNWAPI.getAccount(gair.accountRS); if (gar.success) { if (gar.name == null) { WalletName.Text = "Unknown Account"; } else { WalletName.Text = gar.name; } BurstAddress.Text = gar.accountRS; WalletName.Text = Wallet; string BB; BB = gar.balanceNQT; double burstdbl = Convert.ToDouble(BB); burstdbl = burstdbl / 100000000; Balance.Text = "Balance: " + burstdbl.ToString("#,0.00000000") + " BURST"; TransactionNumber.Text = "100"; GetTransactionListResult gtlr = BNWAPI.getTransactionList(gair.accountRS, TransactionNumber.Text); if (gtlr.success) { TransactionList_ListView.Items.Clear(); //TransactionList_ListView.Items.Add("Date & Time" + " " + "Amount + Fee" + " "+"Account" + " " + "Confirmations"); for (int i = 0; i < gtlr.transactions.Length; i++) { DateTime date = UnixTimeStampToDateTime(gtlr.transactions[i].timestamp); string transactionlist = gtlr.transactions[i].transaction; string amount = gtlr.transactions[i].amountNQT; double amnt = Convert.ToDouble(amount); amnt = amnt / 100000000; string newamnt = amnt.ToString("#,0.00000000"); string Fee = gtlr.transactions[i].feeNQT; double feeamnt = Convert.ToDouble(Fee); feeamnt = feeamnt / 100000000; string newFeeAmnt = feeamnt.ToString("#,0"); string SenderAccount = gtlr.transactions[i].senderRS; string Confirmations = gtlr.transactions[i].confirmations; double Conf = Convert.ToDouble(Confirmations); string Recipient = gtlr.transactions[i].recipientRS; if (Recipient == BurstAddress.Text) { newamnt = "+" + newamnt; } else { newamnt = "-" + newamnt; SenderAccount = Recipient; if (SenderAccount == "") { SenderAccount = "/ "; } } if (Conf > 9) { Conf = 10; string newConf = Conf.ToString() + "+"; TransactionList_ListView.Items.Add(date + " " + newamnt + "+" + newFeeAmnt + " " + SenderAccount + " " + newConf); } else { string newConf = Conf.ToString(); TransactionList_ListView.Items.Add(date + " " + newamnt + "+" + newFeeAmnt + " " + SenderAccount + " " + newConf); } } } } else { MessageDialog ConfirmationDetailsDialog = new MessageDialog("Received Error: " + gar.errorMsg); ConfirmationDetailsDialog.Title = "API Error"; ConfirmationDetailsDialog.Commands.Add(new UICommand("Ok") { Id = 0 }); var ConfResult = await ConfirmationDetailsDialog.ShowAsync(); TransactionList_ListView.Items.Clear(); Balance.Text = "Balance: 0.00000000 BURST"; } CreateQRCode(); } else { MessageDialog ConfirmationDetailsDialog = new MessageDialog("Received Error: " + gair.errorMsg); ConfirmationDetailsDialog.Title = "API Error"; ConfirmationDetailsDialog.Commands.Add(new UICommand("Ok") { Id = 0 }); var ConfResult = await ConfirmationDetailsDialog.ShowAsync(); } } catch { MessageDialog ConfirmationDetailsDialog = new MessageDialog("Received Error: " + gair.errorMsg); ConfirmationDetailsDialog.Title = "API Error"; ConfirmationDetailsDialog.Commands.Add(new UICommand("Ok") { Id = 0 }); var ConfResult = await ConfirmationDetailsDialog.ShowAsync(); } } }