Beispiel #1
0
        public SendTransactionViewModel(IEthereumHostProvider ethereumHostProvider, IScreen hostScreen = null, CurrentAccountTransactionsService currentAccountTransactionsService = null)
        {
            this.HostScreen       = hostScreen;
            _ethereumHostProvider = ethereumHostProvider ?? Locator.Current.GetService <IEthereumHostProvider>();
            _currentAccountTransactionsService = currentAccountTransactionsService ?? Locator.Current.GetService <CurrentAccountTransactionsService>();

            _ethereumHostProvider.SelectedAccountCallback.Subscribe(x => Address = x);

            this._confirmTransfer = new Interaction <string, bool>();

            Gas      = (ulong)Signer.Transaction.DEFAULT_GAS_LIMIT;
            GasPrice = Web3.Web3.Convert.FromWei(Signer.Transaction.DEFAULT_GAS_PRICE, Nethereum.Util.UnitConversion.EthUnit.Gwei);

            this.ValidationRule(x => x.AddressTo, address => Util.Utils.IsValidAddress(address), "Address is not valid");
            this.ValidationRule(x => x.AmountInEther, amount => amount >= 0, "Amount cannot be negative");

            IObservable <IValidationState> balanceValidated =
                this.WhenAnyValue(x => x.AmountInEther, x => x.Gas, x => x.GasPrice)
                .Throttle(TimeSpan.FromSeconds(1), RxApp.TaskpoolScheduler)
                .SelectMany(x => ValidateEnoughBalance(x.Item1, x.Item2, x.Item3))
                .ObserveOn(RxApp.MainThreadScheduler);

            this.ValidationRule(vm => vm.AmountInEther, balanceValidated);

            var canExecuteTransaction = this.IsValid();

            var canExecuteTransactionAndEnabled = Observable.CombineLatest(canExecuteTransaction, _ethereumHostProvider.EnabledCallBack, (valid, enabled) => valid && enabled);

            this._executeTrasnactionCommand = ReactiveCommand.CreateFromTask(ExecuteAsync, canExecuteTransactionAndEnabled);

            this._goBackCommand = ReactiveCommand.CreateFromTask(GoBackAsync);
        }
Beispiel #2
0
 public TransactionsViewModel(IEthereumHostProvider ethereumHostProvider, CurrentAccountTransactionsService currentAccountTransactionsService)
 {
     this.currentAccountTransactionsService = currentAccountTransactionsService;
     this.currentAccountTransactionsService.Transactions.Connect()
     .Transform(transaction => new TransactionViewModel(transaction))
     .AutoRefresh()
     .Sort(SortExpressionComparer <TransactionViewModel> .Descending(t => t.Status).ThenByDescending(t => t.BlockNumber))
     .ObserveOn(RxApp.MainThreadScheduler)
     .Bind(out _transactions)
     .DisposeMany()
     .Subscribe();
 }
Beispiel #3
0
        // Avalonia configuration, don't remove; also used by visual designer.
        public static AppBuilder BuildAvaloniaApp()
        {
            var nethereumHostProvider             = new NethereumHostProvider();
            var currentAccountTransactionsService = new CurrentAccountTransactionsService(nethereumHostProvider);
            var accountsService = new AccountsService(nethereumHostProvider);

            Locator.CurrentMutable.RegisterConstant(accountsService);
            Locator.CurrentMutable.RegisterConstant(nethereumHostProvider);
            Locator.CurrentMutable.RegisterConstant(nethereumHostProvider, typeof(IEthereumHostProvider));
            Locator.CurrentMutable.RegisterConstant(new ContractService(), typeof(IContractService));
            Locator.CurrentMutable.RegisterConstant(currentAccountTransactionsService);
            Locator.CurrentMutable.Register(() => new SendTransactionUserControl(), typeof(IViewFor <SendTransactionViewModel>));

            return(AppBuilder.Configure <App>()
                   .UsePlatformDetect()
                   .LogToTrace()
                   .UseReactiveUI());
        }