Adding typedefs for crypto.com responses
This commit is contained in:
@@ -53,7 +53,7 @@ CryptoDotComGetTickerInfoFunction::Run() {
|
||||
}
|
||||
|
||||
void CryptoDotComGetTickerInfoFunction::OnInfoResult(
|
||||
const std::map<std::string, std::string>& info) {
|
||||
const CryptoDotComTickerInfo& info) {
|
||||
auto result = std::make_unique<base::Value>(
|
||||
base::Value::Type::DICTIONARY);
|
||||
|
||||
@@ -85,7 +85,7 @@ CryptoDotComGetChartDataFunction::Run() {
|
||||
}
|
||||
|
||||
void CryptoDotComGetChartDataFunction::OnChartDataResult(
|
||||
const std::vector<std::map<std::string, std::string>>& data) {
|
||||
const CryptoDotComChartData& data) {
|
||||
auto result = std::make_unique<base::ListValue>();
|
||||
|
||||
for (const auto& data_point : data) {
|
||||
@@ -117,7 +117,7 @@ CryptoDotComGetSupportedPairsFunction::Run() {
|
||||
}
|
||||
|
||||
void CryptoDotComGetSupportedPairsFunction::OnSupportedPairsResult(
|
||||
const std::vector<std::map<std::string, std::string>>& pairs) {
|
||||
const CryptoDotComSupportedPairs& pairs) {
|
||||
auto result = std::make_unique<base::ListValue>();
|
||||
|
||||
for (const auto& pair : pairs) {
|
||||
@@ -149,8 +149,7 @@ CryptoDotComGetAssetRankingsFunction::Run() {
|
||||
}
|
||||
|
||||
void CryptoDotComGetAssetRankingsFunction::OnAssetRankingsResult(
|
||||
const std::map<std::string,
|
||||
std::vector<std::map<std::string, std::string>>>& rankings) {
|
||||
const CryptoDotComAssetRankings& rankings) {
|
||||
auto result = std::make_unique<base::Value>(
|
||||
base::Value::Type::DICTIONARY);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "extensions/browser/extension_function.h"
|
||||
#include "brave/components/crypto_dot_com/browser/crypto_dot_com_service.h"
|
||||
|
||||
class Profile;
|
||||
|
||||
@@ -24,7 +25,7 @@ class CryptoDotComGetTickerInfoFunction :
|
||||
|
||||
protected:
|
||||
~CryptoDotComGetTickerInfoFunction() override {}
|
||||
void OnInfoResult(const std::map<std::string, std::string>& info);
|
||||
void OnInfoResult(const CryptoDotComTickerInfo& info);
|
||||
|
||||
ResponseAction Run() override;
|
||||
};
|
||||
@@ -37,7 +38,7 @@ class CryptoDotComGetChartDataFunction :
|
||||
protected:
|
||||
~CryptoDotComGetChartDataFunction() override {}
|
||||
void OnChartDataResult(
|
||||
const std::vector<std::map<std::string, std::string>>& data);
|
||||
const CryptoDotComChartData& data);
|
||||
|
||||
ResponseAction Run() override;
|
||||
};
|
||||
@@ -50,7 +51,7 @@ class CryptoDotComGetSupportedPairsFunction :
|
||||
protected:
|
||||
~CryptoDotComGetSupportedPairsFunction() override {}
|
||||
void OnSupportedPairsResult(
|
||||
const std::vector<std::map<std::string, std::string>>& pairs);
|
||||
const CryptoDotComSupportedPairs& pairs);
|
||||
|
||||
ResponseAction Run() override;
|
||||
};
|
||||
@@ -63,8 +64,7 @@ class CryptoDotComGetAssetRankingsFunction :
|
||||
protected:
|
||||
~CryptoDotComGetAssetRankingsFunction() override {}
|
||||
void OnAssetRankingsResult(
|
||||
const std::map<std::string,
|
||||
std::vector<std::map<std::string, std::string>>>& rankings);
|
||||
const CryptoDotComAssetRankings& rankings);
|
||||
|
||||
ResponseAction Run() override;
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@ void CryptoDotComJSONParser::CalculateAssetVolume(
|
||||
|
||||
bool CryptoDotComJSONParser::GetTickerInfoFromJSON(
|
||||
const std::string& json,
|
||||
std::map<std::string, std::string>* info) {
|
||||
CryptoDotComTickerInfo* info) {
|
||||
if (!info) {
|
||||
return false;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ bool CryptoDotComJSONParser::GetTickerInfoFromJSON(
|
||||
|
||||
bool CryptoDotComJSONParser::GetChartDataFromJSON(
|
||||
const std::string& json,
|
||||
std::vector<std::map<std::string, std::string>>* data) {
|
||||
CryptoDotComChartData* data) {
|
||||
if (!data) {
|
||||
return false;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ bool CryptoDotComJSONParser::GetChartDataFromJSON(
|
||||
|
||||
bool CryptoDotComJSONParser::GetPairsFromJSON(
|
||||
const std::string& json,
|
||||
std::vector<std::map<std::string, std::string>>* pairs) {
|
||||
CryptoDotComSupportedPairs* pairs) {
|
||||
if (!pairs) {
|
||||
return false;
|
||||
}
|
||||
@@ -198,8 +198,7 @@ bool CryptoDotComJSONParser::GetPairsFromJSON(
|
||||
|
||||
bool CryptoDotComJSONParser::GetRankingsFromJSON(
|
||||
const std::string& json,
|
||||
std::map<std::string,
|
||||
std::vector<std::map<std::string, std::string>>>* rankings) {
|
||||
CryptoDotComAssetRankings* rankings) {
|
||||
if (!rankings) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -10,17 +10,18 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "brave/components/crypto_dot_com/browser/crypto_dot_com_service.h"
|
||||
|
||||
class CryptoDotComJSONParser {
|
||||
public:
|
||||
static bool GetTickerInfoFromJSON(const std::string& json,
|
||||
std::map<std::string, std::string>* info);
|
||||
CryptoDotComTickerInfo* info);
|
||||
static bool GetChartDataFromJSON(const std::string& json,
|
||||
std::vector<std::map<std::string, std::string>>* data);
|
||||
CryptoDotComChartData* data);
|
||||
static bool GetPairsFromJSON(const std::string& json,
|
||||
std::vector<std::map<std::string, std::string>>* pairs);
|
||||
CryptoDotComSupportedPairs* pairs);
|
||||
static bool GetRankingsFromJSON(const std::string& json,
|
||||
std::map<std::string,
|
||||
std::vector<std::map<std::string, std::string>>>* rankings);
|
||||
CryptoDotComAssetRankings* rankings);
|
||||
private:
|
||||
static void CalculateAssetVolume(const double v,
|
||||
const double h,
|
||||
|
||||
@@ -62,6 +62,10 @@ GURL GetURLWithPath(const std::string& host, const std::string& path) {
|
||||
return GURL(std::string(url::kHttpsScheme) + "://" + host).Resolve(path);
|
||||
}
|
||||
|
||||
std::string GetFormattedResponseBody(const std::string& json_response) {
|
||||
return "{\"response\": " + json_response + "}";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CryptoDotComService::CryptoDotComService(content::BrowserContext* context)
|
||||
@@ -89,9 +93,9 @@ void CryptoDotComService::OnTickerInfo(
|
||||
GetTickerInfoCallback callback,
|
||||
const int status, const std::string& body,
|
||||
const std::map<std::string, std::string>& headers) {
|
||||
std::map<std::string, std::string> info;
|
||||
CryptoDotComTickerInfo info;
|
||||
if (status >= 200 && status <= 299) {
|
||||
const std::string json_body = "{\"response\": " + body + "}";
|
||||
const std::string json_body = GetFormattedResponseBody(body);
|
||||
CryptoDotComJSONParser::GetTickerInfoFromJSON(json_body, &info);
|
||||
}
|
||||
std::move(callback).Run(info);
|
||||
@@ -113,9 +117,9 @@ void CryptoDotComService::OnChartData(
|
||||
GetChartDataCallback callback,
|
||||
const int status, const std::string& body,
|
||||
const std::map<std::string, std::string>& headers) {
|
||||
std::vector<std::map<std::string, std::string>> data;
|
||||
CryptoDotComChartData data;
|
||||
if (status >= 200 && status <= 299) {
|
||||
const std::string json_body = "{\"response\": " + body + "}";
|
||||
const std::string json_body = GetFormattedResponseBody(body);
|
||||
CryptoDotComJSONParser::GetChartDataFromJSON(json_body, &data);
|
||||
}
|
||||
std::move(callback).Run(data);
|
||||
@@ -135,9 +139,9 @@ void CryptoDotComService::OnSupportedPairs(
|
||||
GetSupportedPairsCallback callback,
|
||||
const int status, const std::string& body,
|
||||
const std::map<std::string, std::string>& headers) {
|
||||
std::vector<std::map<std::string, std::string>> pairs;
|
||||
CryptoDotComSupportedPairs pairs;
|
||||
if (status >= 200 && status <= 299) {
|
||||
const std::string json_body = "{\"response\": " + body + "}";
|
||||
const std::string json_body = GetFormattedResponseBody(body);
|
||||
CryptoDotComJSONParser::GetPairsFromJSON(json_body, &pairs);
|
||||
}
|
||||
std::move(callback).Run(pairs);
|
||||
@@ -157,10 +161,9 @@ void CryptoDotComService::OnAssetRankings(
|
||||
GetAssetRankingsCallback callback,
|
||||
const int status, const std::string& body,
|
||||
const std::map<std::string, std::string>& headers) {
|
||||
std::map<std::string,
|
||||
std::vector<std::map<std::string, std::string>>> rankings;
|
||||
CryptoDotComAssetRankings rankings;
|
||||
if (status >= 200 && status <= 299) {
|
||||
const std::string json_body = "{\"response\": " + body + "}";
|
||||
const std::string json_body = GetFormattedResponseBody(body);
|
||||
CryptoDotComJSONParser::GetRankingsFromJSON(json_body, &rankings);
|
||||
}
|
||||
std::move(callback).Run(rankings);
|
||||
|
||||
@@ -43,23 +43,26 @@ const char get_chart_data_path[] = "/v2/public/get-candlestick";
|
||||
const char get_pairs_path[] = "/v2/public/get-instruments";
|
||||
const char get_gainers_losers_path[] = "/fe-ex-api/widget/get-gainers";
|
||||
|
||||
typedef std::map<std::string, std::string> CryptoDotComTickerInfo;
|
||||
typedef std::vector<std::map<std::string, std::string>> CryptoDotComChartData;
|
||||
typedef std::vector<std::map<std::string, std::string>>
|
||||
CryptoDotComSupportedPairs;
|
||||
typedef std::map<std::string, std::vector<std::map<std::string, std::string>>>
|
||||
CryptoDotComAssetRankings;
|
||||
|
||||
class CryptoDotComService : public KeyedService {
|
||||
public:
|
||||
explicit CryptoDotComService(content::BrowserContext* context);
|
||||
~CryptoDotComService() override;
|
||||
|
||||
using GetTickerInfoCallback =
|
||||
base::OnceCallback<void(const std::map<std::string, std::string>&)>;
|
||||
base::OnceCallback<void(const CryptoDotComTickerInfo&)>;
|
||||
using GetChartDataCallback =
|
||||
base::OnceCallback<void(
|
||||
const std::vector<std::map<std::string, std::string>>&)>;
|
||||
base::OnceCallback<void(const CryptoDotComChartData&)>;
|
||||
using GetSupportedPairsCallback =
|
||||
base::OnceCallback<void(
|
||||
const std::vector<std::map<std::string, std::string>>&)>;
|
||||
base::OnceCallback<void(const CryptoDotComSupportedPairs&)>;
|
||||
using GetAssetRankingsCallback =
|
||||
base::OnceCallback<void(
|
||||
const std::map<std::string,
|
||||
std::vector<std::map<std::string, std::string>>>&)>;
|
||||
base::OnceCallback<void(const CryptoDotComAssetRankings&)>;
|
||||
|
||||
bool GetTickerInfo(const std::string& asset,
|
||||
GetTickerInfoCallback callback);
|
||||
|
||||
Reference in New Issue
Block a user