Exemplo n.º 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);
        }
        public StandardTokenTransferViewModel(IEthereumHostProvider ethereumHostProvider, IContractService contractService, IScreen screenHost)
        {
            this._ethereumHostProvider = ethereumHostProvider;
            this._contractService      = contractService;
            this._screenHost           = screenHost;
            this._contractService.ContractAddress.Subscribe(x => ContractAddress = x);

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



            var canExecuteTransaction = this.WhenAnyValue(
                x => x.AddressTo,
                x => x.Amount,
                x => x.ContractAddress,
                (addressTo, amount, contractAddress) =>
                Nethereum.UI.Util.Utils.IsValidAddress(addressTo) &&
                amount != null && amount > 0 &&
                contractAddress != null);

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

            this._executeTransactionCommand = ReactiveCommand.CreateFromTask(ExecuteAsync, canExecuteAndEnabled);
        }
Exemplo n.º 3
0
        public StandardTokenViewModel(IEthereumHostProvider ethereumHostProvider)
        {
            this.routingState = new RoutingState();

            var provider        = ethereumHostProvider ?? Locator.Current.GetService <IEthereumHostProvider>();
            var contractService = Locator.Current.GetService <IContractService>();

            ContractAdddressViewModel       = new ContractAdddressViewModel(contractService);
            StandardTokenBalanceOfViewModel = new StandardTokenBalanceOfViewModel(provider, contractService);
            StandardTokenTransferViewModel  = new StandardTokenTransferViewModel(provider, contractService, this);
        }
Exemplo n.º 4
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();
 }
        public CurrentAccountTransactionsService(IEthereumHostProvider ethereumHostProvider, int updateIntervalMilliseconds = 2000)
        {
            updateInterval            = TimeSpan.FromMilliseconds(updateIntervalMilliseconds);
            this.ethereumHostProvider = ethereumHostProvider;
            this.ethereumHostProvider.SelectedAccountCallback.Subscribe(address =>
            {
                if (address != currentAccount)
                {
                    currentAccount = address;
                    _transactions.Clear();
                    //We should save ... reload
                }
            });

            timer = Observable.Timer(updateInterval, updateInterval, RxApp.MainThreadScheduler)
                    .Subscribe(async _ => await CheckReceiptsAsync());
        }
Exemplo n.º 6
0
        public StandardTokenBalanceOfViewModel(IEthereumHostProvider ethereumHostProvider, IContractService contractService)
        {
            this.ethereumHostProvider = ethereumHostProvider;
            this.ethereumHostProvider.SelectedAccountCallback.Subscribe(address => AccountAddress = address);

            this.contractService = contractService;
            this.contractService.ContractAddress.Subscribe(x => ContractAddress = x);

            var hasValidAddresses = this.WhenAnyValue(x => x.AccountAddress, x => x.ContractAddress,
                                                      (address, contractAddress) => Nethereum.UI.Util.Utils.IsValidAddress(address) && Nethereum.UI.Util.Utils.IsValidAddress(contractAddress));

            var isValidRefreshBalance = Observable.CombineLatest(hasValidAddresses, this.ethereumHostProvider.EnabledCallBack, (validAdress, enabled) => validAdress && enabled);

            isValidRefreshBalance.Where(x => x == true)
            .Subscribe(async _ => await RefreshBalanceAsync());

            _refreshBalanceCommand = ReactiveCommand.CreateFromTask(RefreshBalanceAsync, isValidRefreshBalance);
        }
 public NethereumAuthenticator(IEthereumHostProvider host)
 {
     _host = host;
 }