Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
0
        public async Task <WalletAddresses> GetAddressesForAssetAsync(WalletAddressAssetContext context)
        {
            var api = ApiProvider.GetApi(context);

            var r = await api.GetDepositAddressAsync(context.Asset.ShortCode).ConfigureAwait(false);

            var walletAddresses = new WalletAddresses
            {
                new WalletAddress(this, context.Asset)
                {
                    Address = r.address
                }
            };

            return(walletAddresses);
        }
Ejemplo n.º 7
0
        public async Task <WalletAddresses> GetAddressesAsync(WalletAddressContext context)
        {
            var addresses = new WalletAddresses();
            var wac       = new WalletAddressAssetContext("ETH".ToAsset(this), context.UserContext, context.L);

            addresses.AddRange(await GetAddressesForAssetAsync(wac).ConfigureAwait(false));

            wac.Asset = "BTC".ToAsset(this);
            addresses.AddRange(await GetAddressesForAssetAsync(wac).ConfigureAwait(false));

            wac.Asset = "XRP".ToAsset(this);
            addresses.AddRange(await GetAddressesForAssetAsync(wac).ConfigureAwait(false));

            wac.Asset = "LTC".ToAsset(this);
            addresses.AddRange(await GetAddressesForAssetAsync(wac).ConfigureAwait(false));

            return(addresses);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public async Task <WalletAddresses> GetAddressesForAssetAsync(WalletAddressAssetContext context)
        {
            var api          = ApiProvider.GetApi(context);
            var currencyPath = GetCurrencyPath(context.Asset);

            var r = await api.GetDepositAddressAsync(currencyPath).ConfigureAwait(false);

            var processedAddress = ProcessAddressResponce(context.Asset, r);

            //if (!this.ExchangeHas(context.Asset))
            //    return null;

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

            var addresses = new WalletAddresses(walletAddress);

            return(addresses);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        public async Task <WalletAddresses> GetAddressesAsync(WalletAddressContext context)
        {
            var api    = ApiProvider.GetApi(context);
            var assets = await GetAssetPairsAsync(context).ConfigureAwait(false);

            var addresses = new WalletAddresses();

            foreach (var pair in assets)
            {
                var fundingMethod = await GetFundingMethodAsync(context, pair.Asset1).ConfigureAwait(false);

                if (fundingMethod == null)
                {
                    throw new NullReferenceException("No funding method is found");
                }

                var localAddresses = await GetAddressesLocalAsync(api, fundingMethod, pair.Asset1).ConfigureAwait(false);

                addresses.AddRange(localAddresses);
            }

            return(addresses);
        }
Ejemplo n.º 13
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);
        }