示例#1
0
        public async Task <WalletAddresses> GetAddressesForAssetAsync(WalletAddressAssetContext context)
        {
            var api  = ApiProvider.GetApi(context);
            var body = CreatePoloniexBody(PoloniexBodyType.ReturnDepositAddresses);

            var addresses = new WalletAddresses();

            try
            {
                var r = await api.GetDepositAddressesAsync(body).ConfigureAwait(false);

                var assetBalances = r.Where(x => Equals(x.Key.ToAsset(this), context.Asset)).ToArray();

                foreach (var balance in assetBalances)
                {
                    if (string.IsNullOrWhiteSpace(balance.Value))
                    {
                        continue;
                    }

                    addresses.Add(new WalletAddress(this, balance.Key.ToAsset(this))
                    {
                        Address = balance.Value
                    });
                }
            }
            catch (Exception e)
            {
                // "Unable to get deposit addresses, please check that your account is verified"
                throw new ApiResponseException(e, this);
            }

            return(addresses);
        }
示例#2
0
        public async Task <WalletAddresses> GetAddressesAsync(WalletAddressContext context)
        {
            var api  = ApiProvider.GetApi(context);
            var accs = await api.GetAccountsAsync().ConfigureAwait(false);

            var addresses = new WalletAddresses();

            var accountIds = accs.data.Select(x => new KeyValuePair <string, string>(x.currency, x.id));

            foreach (var kvp in accountIds)
            {
                var r = await api.GetAddressesAsync(kvp.Value).ConfigureAwait(false);

                foreach (var rAddress in r.data)
                {
                    if (string.IsNullOrWhiteSpace(rAddress.address))
                    {
                        continue;
                    }

                    addresses.Add(new WalletAddress(this, kvp.Key.ToAsset(this))
                    {
                        Address = rAddress.address
                    });
                }
            }

            return(addresses);
        }
示例#3
0
        public async Task <WalletAddresses> GetAddressesAsync(WalletAddressContext context)
        {
            throw new NotImplementedException();

            var api       = ApiProvider.GetApi(context);
            var addresses = new WalletAddresses();

            // TODO: re-implement, incorrect implementation.

            foreach (var assetPair in Pairs)
            {
                var adjustedCode = AdjustAssetCode(assetPair.Asset1.ShortCode);

                var depositAddress = await api.GetUserDepositAddressAsync(adjustedCode).ConfigureAwait(false);

                depositAddress = depositAddress.Trim('\"');

                // BUG: how to convert XBt from Pairs to BTC?
                addresses.Add(new WalletAddress(this, Asset.Btc)
                {
                    Address = depositAddress
                });
            }

            return(addresses);
        }
示例#4
0
        public ReceiveViewModel()
        {
            if (IsInDesignMode)
            {
                return;
            }

            var uc = UserContext.Current;

            ClickCommand = new RelayCommand(AddAddress);

            M.RegisterAsyncD <WalletAddressResponseMessage>(this, uc.Token, UiDispatcher, m =>
            {
                WalletAddresses.Add(m.Address);
            });

            M.RegisterAsyncD <WalletAllResponseMessage>(this, uc.Token, UiDispatcher, m =>
            {
                foreach (var a in m.Addresses)
                {
                    WalletAddresses.Add(a);
                }
            });

            M.RegisterAsyncD <AssetNetworkResponseMessage>(this, UiDispatcher, m =>
            {
                UpdateAssets(m.Assets);
            });

            Services        = Networks.I.BalanceProviders;
            ServiceSelected = Services.FirstProvider();

            ServiceChanged();
        }
示例#5
0
        public async Task <WalletAddresses> GetAddressesForAssetAsync(WalletAddressAssetContext context)
        {
            var api = ApiProvider.GetApi(context);

            var accid = "";

            var accs = await api.GetAccountsAsync().ConfigureAwait(false);

            var ast = context.Asset.ToRemoteCode(this);

            var acc = accs.data.FirstOrDefault(x => string.Equals(x.currency, ast, StringComparison.OrdinalIgnoreCase));

            if (acc == null)
            {
                return(null);
            }

            accid = acc.id;

            if (accid == null)
            {
                return(null);
            }

            var r = await api.GetAddressesAsync(acc.id).ConfigureAwait(false);

            // TODO: re-implement.
            //if (r.data.Count == 0 && context.CanGenerateAddress)
            //{
            //    var cr = await api.CreateAddressAsync(accid);
            //    if (cr != null)
            //        r.data.AddRange(cr.data);
            //}

            var addresses = new WalletAddresses();

            foreach (var a in r.data)
            {
                if (string.IsNullOrWhiteSpace(a.address))
                {
                    continue;
                }

                var forasset = FromNetwork(a.network);
                if (!context.Asset.Equals(forasset))
                {
                    continue;
                }

                addresses.Add(new WalletAddress(this, context.Asset)
                {
                    Address = a.address
                });
            }

            return(addresses);
        }
示例#6
0
        public async Task <WalletAddresses> GetAddressesForAssetAsync(WalletAddressAssetContext context)
        {
            var api = ApiProvider.GetApi(context);

            var remoteAssetCode = context.Asset.ToRemoteCode(this);
            var depositAddress  = await api.GetUserDepositAddressAsync(remoteAssetCode).ConfigureAwait(false);

            depositAddress = depositAddress.Trim('\"');

            var addresses     = new WalletAddresses();
            var walletAddress = new WalletAddress(this, context.Asset)
            {
                Address = depositAddress
            };

            addresses.Add(walletAddress);

            return(addresses);
        }
示例#7
0
        public async Task <WalletAddresses> GetAddressesAsync(WalletAddressContext context)
        {
            var api = ApiProvider.GetApi(context);

            var r = await api.GetAllBalancesAsync().ConfigureAwait(false);

            CheckResponseErrors(r);

            var addresses = new WalletAddresses();

            foreach (var rBalance in r.result)
            {
                addresses.Add(new WalletAddress(this, rBalance.Currency.ToAsset(this))
                {
                    Address = rBalance.CryptoAddress
                });
            }

            return(addresses);
        }
示例#8
0
        public async Task <WalletAddresses> GetAddressesForAssetAsync(WalletAddressAssetContext context)
        {
            var api = ApiProvider.GetApi(context);

            var r = await api.GetAllBalancesAsync().ConfigureAwait(false);

            CheckResponseErrors(r);

            var addresses = new WalletAddresses();

            var address = r.result.FirstOrDefault(x => x.Currency.ToAsset(this).Equals(context.Asset));

            if (address != null)
            {
                addresses.Add(new WalletAddress(this, context.Asset)
                {
                    Address = address.CryptoAddress
                });
            }

            return(addresses);
        }
示例#9
0
        private async Task <WalletAddresses> GetAddressesLocalAsync(IKrakenApi api, string fundingMethod, Asset asset, bool generateNew = false)
        {
            var body = CreateKrakenBody();

            // BUG: do we need "aclass"?
            //body.Add("aclass", asset.ToRemoteCode(this));
            body.Add("asset", asset.ToRemoteCode(this));
            body.Add("method", fundingMethod);
            body.Add("new", generateNew);

            var r = await api.GetDepositAddressesAsync(body).ConfigureAwait(false);

            CheckResponseErrors(r);

            var walletAddresses = new WalletAddresses();

            foreach (var addr in r.result)
            {
                var walletAddress = new WalletAddress(this, asset)
                {
                    Address = addr.address
                };

                if (addr.expiretm != 0)
                {
                    var time = addr.expiretm.ToUtcDateTime();
                    walletAddress.ExpiresUtc = time;
                }

                walletAddresses.Add(new WalletAddress(this, asset)
                {
                    Address = addr.address
                });
            }

            return(walletAddresses);
        }