Example #1
0
        // Perform request to get usds value and set the price to be used by calculator.
        public async void GetCurrentPriceUsd()
        {
            RestService _restService = new RestService();
            BTCtoUSDto  result       = await _restService.GetCurrentPrice(Constants.btcEndpoint);

            currPrice.Text = result.Price.ToString();
            priceInUSD     = Convert.ToDouble(result.Price);
            // System.Console.WriteLine("price: --> " + priceInUSD.ToString());
            // By default start calculation on 1 btc, done here because need to wait
            // RestService get the price for caculations.
            if (string.IsNullOrEmpty(btcs.Text))
            {
                btcs.Text = "1";
            }
            else
            {
                double inBtcs = Convert.ToDouble(btcs.Text);
                // Cast to int to verify if the value is integer, then convert to USD when refresh button is clicked
                int btcsInt = (int)inBtcs;
                if (btcsInt == inBtcs)
                {
                    CalculateUSDs();
                }
                else
                {
                    CalculateBTCs();
                }
            }
        }
Example #2
0
        public async Task <BTCtoUSDto> GetCurrentPrice(string uri)
        {
            BTCtoUSDto currentBtc = null;

            try
            {
                HttpResponseMessage response = await _client.GetAsync(uri);

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    currentBtc = JsonConvert.DeserializeObject <BTCtoUSDto>(content);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }

            return(currentBtc);
        }