コード例 #1
0
        public TransferViewModel(IEthWalletService walletService,
                                 ITokenRegistryService tokenRegistryService,
                                 IAccountRegistryService accountRegistryService,
                                 ITransactionSenderService transactionSenderService,
                                 IMvxNavigationService navigationService,
                                 ITransactionHistoryService transactionHistoryService
                                 )
        {
            Icon  = "transfer.png";
            Title = Texts.Transfer;

            this.walletService             = walletService;
            this.tokenRegistryService      = tokenRegistryService;
            this.accountRegistryService    = accountRegistryService;
            this.transactionSenderService  = transactionSenderService;
            this.navigationService         = navigationService;
            this.transactionHistoryService = transactionHistoryService;

            RegisteredAccounts = new ObservableCollection <string>();
            RegisteredTokens   = new ObservableCollection <ContractToken>();
            confirmTransfer    = new Interaction <string, bool>();

            SelectedToken       = -1;
            SelectedAccountFrom = -1;
            GasPrice            = Web3.Convert.FromWei(TransactionBase.DEFAULT_GAS_PRICE, UnitConversion.EthUnit.Gwei);
            Gas = (long)Web3.Convert.FromWei(TransactionBase.DEFAULT_GAS_LIMIT, UnitConversion.EthUnit.Wei);

#if DEBUG
            SelectedToken       = 0;
            SelectedAccountFrom = 0;
            Amount    = 0.01M;
            Gas       = 21000;
            GasPrice  = 10;
            ToAddress = "0x92c66ca0bb8c3f9c9be8001d97211e4f732deb63";
#endif


            this.WhenAnyValue(x =>
                              x.SelectedToken,
                              x => x.SelectedAccountFrom,
                              (selectedToken, selectedAccountFrom) => selectedToken != -1 && selectedAccountFrom != -1)
            .Subscribe(async(p) => await RefreshTokenBalanceAsync());

            var canExecuteTransaction = this.WhenAnyValue(
                x => x.ToAddress,
                x => x.Amount,
                x => x.SelectedToken,
                x => x.SelectedAccountFrom,
                (addressTo, amount, selectedToken, selectedAccountFrom) => //true ||
                !string.IsNullOrEmpty(ToAddress) &&                        //TODO: valid address
                amount > 0 &&
                selectedToken != -1 &&
                selectedAccountFrom != -1
                );

            executeTransactionCommand = ReactiveCommand.CreateFromTask(ExecuteAsync, canExecuteTransaction);
        }
コード例 #2
0
        public TransferTokenViewModel(IEthWalletService walletService,
                                      ITokenRegistryService tokenRegistryService,
                                      IAccountRegistryService accountRegistryService,
                                      ITransactionSenderService transactionSenderService,
                                      IMvxNavigationService navigationService,
                                      ITransactionHistoryService transactionHistoryService
                                      )
        {
            _walletService             = walletService;
            _tokenRegistryService      = tokenRegistryService;
            _accountRegistryService    = accountRegistryService;
            _transactionSenderService  = transactionSenderService;
            _navigationService         = navigationService;
            _transactionHistoryService = transactionHistoryService;
            _registeredAccounts        = new ObservableCollection <string>();
            _registeredTokens          = new ObservableCollection <ContractToken>();
            _confirmTransfer           = new Interaction <string, bool>();

            _selectedToken       = -1;
            _selectedAccountFrom = -1;
            _gasPrice            = Web3.Web3.Convert.FromWei(TransactionBase.DEFAULT_GAS_PRICE, UnitConversion.EthUnit.Gwei);

            Title = "Transfer Token";
            Icon  = "ethIcon.png";

            this.WhenAnyValue(x => x.SelectedToken,
                              x => x.SelectedAccountFrom, (selectedToken, selectedAccountFrom) => selectedToken != -1 &&
                              selectedAccountFrom != -1).Subscribe(async _ =>
                                                                   await RefreshTokenBalanceAsync());

            var canExecuteTransaction = this.WhenAnyValue(
                x => x.ToAddress,
                x => x.Amount,
                x => x.SelectedToken,
                x => x.SelectedAccountFrom,
                (addressTo, amount, selectedToken, selectedAccountFrom) =>
                !string.IsNullOrEmpty(ToAddress) &&     //todo valid address
                amount > 0 &&
                selectedToken != -1 &&
                selectedAccountFrom != -1);

            _executeTransactionCommand = ReactiveCommand.CreateFromTask(ExecuteAsync, canExecuteTransaction);
        }