Exemplo n.º 1
0
        private void GenerateTransaction()
        {
            double amount = 0;

            string amountString = this.txtTransferAmount.Text.Trim();

            if (!double.TryParse(amountString, out amount) || amount <= 0)
            {
                MessageBox.Show(Properties.Strings.TransferWindow_AmountFormatError);
                return;
            }

            if (amount > xdagWallet.Balance)
            {
                MessageBox.Show(Properties.Strings.TransferWindow_InsufficientAmount);
                return;
            }

            string targetWalletAddress = this.txtTransferTargetAddress.Text.Trim();

            if (!xdagRuntime.ValidateWalletAddress(targetWalletAddress))
            {
                MessageBox.Show(Properties.Strings.TransferWindow_AccountFormatError);
                return;
            }

            string remarkString = this.txtTransferRemark.Text.Trim();

            if (remarkString.Length > 0)
            {
                if (!xdagRuntime.ValidateRemark(remarkString))
                {
                    MessageBox.Show(Properties.Strings.TransferWindow_RemarkFormatError);
                    return;
                }
            }
            else
            {
                remarkString = " ";
            }

            string           confirmMessage = string.Format(Properties.Strings.TransferWindow_ConfirmTransfer, amount, targetWalletAddress);
            MessageBoxResult result         = MessageBox.Show(confirmMessage, Properties.Strings.Common_ConfirmTitle, MessageBoxButton.YesNo);

            if (result == MessageBoxResult.No)
            {
                return;
            }

            BackgroundWork.CreateWork(
                this,
                () => {
                this.materialTabControl.IsEnabled = false;
                ShowStatus(Properties.Strings.TransferWindow_CommittingTransaction);
            },
                () => {
                xdagRuntime.TransferToAddress(targetWalletAddress, amount, remarkString);

                return(0);
            },
                (taskResult) => {
                if (taskResult.HasError)
                {
                    if (taskResult.Exception is PasswordIncorrectException)
                    {
                        MessageBox.Show(Properties.Strings.Message_PasswordIncorrect, Properties.Strings.Common_MessageTitle);
                    }
                    else
                    {
                        MessageBox.Show(Properties.Strings.TransferWindow_CommitFailed + taskResult.Exception.Message);
                    }
                }
                else
                {
                    // Success
                    MessageBox.Show(Properties.Strings.TransferWindow_CommitSuccess, Properties.Strings.Common_MessageTitle);
                    this.txtTransferAmount.Text = string.Empty;
                    this.tabAccount.IsSelected  = true;
                }

                this.materialTabControl.IsEnabled = true;
                HideStatus();
            }
                ).Execute();
        }