diff --git a/browser/extensions/api/crypto_dot_com_api.cc b/browser/extensions/api/crypto_dot_com_api.cc index 8cd022f50f8..cb69b61b243 100644 --- a/browser/extensions/api/crypto_dot_com_api.cc +++ b/browser/extensions/api/crypto_dot_com_api.cc @@ -53,7 +53,7 @@ CryptoDotComGetTickerInfoFunction::Run() { } void CryptoDotComGetTickerInfoFunction::OnInfoResult( - const std::map& info) { + const CryptoDotComTickerInfo& info) { auto result = std::make_unique( base::Value::Type::DICTIONARY); @@ -85,7 +85,7 @@ CryptoDotComGetChartDataFunction::Run() { } void CryptoDotComGetChartDataFunction::OnChartDataResult( - const std::vector>& data) { + const CryptoDotComChartData& data) { auto result = std::make_unique(); for (const auto& data_point : data) { @@ -117,7 +117,7 @@ CryptoDotComGetSupportedPairsFunction::Run() { } void CryptoDotComGetSupportedPairsFunction::OnSupportedPairsResult( - const std::vector>& pairs) { + const CryptoDotComSupportedPairs& pairs) { auto result = std::make_unique(); for (const auto& pair : pairs) { @@ -149,8 +149,7 @@ CryptoDotComGetAssetRankingsFunction::Run() { } void CryptoDotComGetAssetRankingsFunction::OnAssetRankingsResult( - const std::map>>& rankings) { + const CryptoDotComAssetRankings& rankings) { auto result = std::make_unique( base::Value::Type::DICTIONARY); diff --git a/browser/extensions/api/crypto_dot_com_api.h b/browser/extensions/api/crypto_dot_com_api.h index cbe6c76cbf7..9736d10da99 100644 --- a/browser/extensions/api/crypto_dot_com_api.h +++ b/browser/extensions/api/crypto_dot_com_api.h @@ -11,6 +11,7 @@ #include #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& info); + void OnInfoResult(const CryptoDotComTickerInfo& info); ResponseAction Run() override; }; @@ -37,7 +38,7 @@ class CryptoDotComGetChartDataFunction : protected: ~CryptoDotComGetChartDataFunction() override {} void OnChartDataResult( - const std::vector>& data); + const CryptoDotComChartData& data); ResponseAction Run() override; }; @@ -50,7 +51,7 @@ class CryptoDotComGetSupportedPairsFunction : protected: ~CryptoDotComGetSupportedPairsFunction() override {} void OnSupportedPairsResult( - const std::vector>& pairs); + const CryptoDotComSupportedPairs& pairs); ResponseAction Run() override; }; @@ -63,8 +64,7 @@ class CryptoDotComGetAssetRankingsFunction : protected: ~CryptoDotComGetAssetRankingsFunction() override {} void OnAssetRankingsResult( - const std::map>>& rankings); + const CryptoDotComAssetRankings& rankings); ResponseAction Run() override; }; diff --git a/components/crypto_dot_com/browser/crypto_dot_com_json_parser.cc b/components/crypto_dot_com/browser/crypto_dot_com_json_parser.cc index fff7befccbc..cb671aed44c 100644 --- a/components/crypto_dot_com/browser/crypto_dot_com_json_parser.cc +++ b/components/crypto_dot_com/browser/crypto_dot_com_json_parser.cc @@ -24,7 +24,7 @@ void CryptoDotComJSONParser::CalculateAssetVolume( bool CryptoDotComJSONParser::GetTickerInfoFromJSON( const std::string& json, - std::map* info) { + CryptoDotComTickerInfo* info) { if (!info) { return false; } @@ -78,7 +78,7 @@ bool CryptoDotComJSONParser::GetTickerInfoFromJSON( bool CryptoDotComJSONParser::GetChartDataFromJSON( const std::string& json, - std::vector>* data) { + CryptoDotComChartData* data) { if (!data) { return false; } @@ -144,7 +144,7 @@ bool CryptoDotComJSONParser::GetChartDataFromJSON( bool CryptoDotComJSONParser::GetPairsFromJSON( const std::string& json, - std::vector>* pairs) { + CryptoDotComSupportedPairs* pairs) { if (!pairs) { return false; } @@ -198,8 +198,7 @@ bool CryptoDotComJSONParser::GetPairsFromJSON( bool CryptoDotComJSONParser::GetRankingsFromJSON( const std::string& json, - std::map>>* rankings) { + CryptoDotComAssetRankings* rankings) { if (!rankings) { return false; } diff --git a/components/crypto_dot_com/browser/crypto_dot_com_json_parser.h b/components/crypto_dot_com/browser/crypto_dot_com_json_parser.h index f5d556e4ae4..6bfe7774a7b 100644 --- a/components/crypto_dot_com/browser/crypto_dot_com_json_parser.h +++ b/components/crypto_dot_com/browser/crypto_dot_com_json_parser.h @@ -10,17 +10,18 @@ #include #include +#include "brave/components/crypto_dot_com/browser/crypto_dot_com_service.h" + class CryptoDotComJSONParser { public: static bool GetTickerInfoFromJSON(const std::string& json, - std::map* info); + CryptoDotComTickerInfo* info); static bool GetChartDataFromJSON(const std::string& json, - std::vector>* data); + CryptoDotComChartData* data); static bool GetPairsFromJSON(const std::string& json, - std::vector>* pairs); + CryptoDotComSupportedPairs* pairs); static bool GetRankingsFromJSON(const std::string& json, - std::map>>* rankings); + CryptoDotComAssetRankings* rankings); private: static void CalculateAssetVolume(const double v, const double h, diff --git a/components/crypto_dot_com/browser/crypto_dot_com_service.cc b/components/crypto_dot_com/browser/crypto_dot_com_service.cc index d26d6796e9c..543d369ae10 100644 --- a/components/crypto_dot_com/browser/crypto_dot_com_service.cc +++ b/components/crypto_dot_com/browser/crypto_dot_com_service.cc @@ -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& headers) { - std::map 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& headers) { - std::vector> 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& headers) { - std::vector> 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& headers) { - std::map>> 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); diff --git a/components/crypto_dot_com/browser/crypto_dot_com_service.h b/components/crypto_dot_com/browser/crypto_dot_com_service.h index 973f6c95822..035e3ee049f 100644 --- a/components/crypto_dot_com/browser/crypto_dot_com_service.h +++ b/components/crypto_dot_com/browser/crypto_dot_com_service.h @@ -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 CryptoDotComTickerInfo; +typedef std::vector> CryptoDotComChartData; +typedef std::vector> + CryptoDotComSupportedPairs; +typedef std::map>> + CryptoDotComAssetRankings; + class CryptoDotComService : public KeyedService { public: explicit CryptoDotComService(content::BrowserContext* context); ~CryptoDotComService() override; using GetTickerInfoCallback = - base::OnceCallback&)>; + base::OnceCallback; using GetChartDataCallback = - base::OnceCallback>&)>; + base::OnceCallback; using GetSupportedPairsCallback = - base::OnceCallback>&)>; + base::OnceCallback; using GetAssetRankingsCallback = - base::OnceCallback>>&)>; + base::OnceCallback; bool GetTickerInfo(const std::string& asset, GetTickerInfoCallback callback);