Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binance version 2 trading widget #5160

Merged
merged 60 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
dc115fc
Initial NTP widget with buy support
ryanml Mar 11, 2020
4c354c2
Adding front-end resources for full widget
ryanml Mar 20, 2020
9aa0fd3
Adding backend API, controller, service
ryanml Mar 20, 2020
2ed0595
Adding PKCE code challenge store
ryanml Mar 20, 2020
953a7ea
Adding account balance retrieval, json parser tests
ryanml Mar 20, 2020
887f80b
Adding conversion quote endpoint
ryanml Mar 23, 2020
4270169
Adding V1 API code, TickerPrice and Volume endpoints
ryanml Mar 23, 2020
8ddd979
Collapse BinanceController into BinanceService
bbondy Mar 23, 2020
c51f636
Return correct success boolean
bbondy Mar 30, 2020
33f80ef
Add BAT to currency lookup table and create a fallback
bbondy Mar 30, 2020
f3f84ff
Fixup where Binance buildflags
bbondy Mar 30, 2020
47e852b
Fix oauth flow w/ binance: protocol handler
bbondy Mar 30, 2020
3f3a22f
Fix missing dep on some buildflags
bbondy Mar 30, 2020
b1a019e
Use build config for client and secret
bbondy Mar 30, 2020
de5556d
Update callback url to com.brave.binance scheme
bbondy Mar 31, 2020
4e562ce
Fixup PKCE flow and param encoding
bbondy Mar 31, 2020
a1d2476
Handle code challenge and verifier on C++ side
bbondy Apr 1, 2020
ab59677
Fixing namespace, pref registry
ryanml Apr 1, 2020
f2ee207
Use GET method for user balance
bbondy Apr 1, 2020
7b703f3
Remove binance_client_secret
bbondy Apr 1, 2020
7f46eea
Front-end re-organization, lint fixes
ryanml Apr 1, 2020
f262184
Removing Connect flow for US users
ryanml Apr 2, 2020
ceb4010
wiring in asset volume, values in USD, BTC
ryanml Apr 2, 2020
d5e1eae
Networking for user deposit info (address, url), wiring
ryanml Apr 2, 2020
8842356
Finishing remaining backend for conversions
ryanml Apr 3, 2020
a2d993e
Fix invalid Binance oauth scope
bbondy Apr 3, 2020
5c2efc2
Front end cleanup, price and ticker fixes
ryanml Apr 4, 2020
48f882a
Adding QR code view + address copy
ryanml Apr 4, 2020
66fc997
Using just asset address for QR code, small formatting fixes
ryanml Apr 4, 2020
1d75e30
Adding convert asset lookup table, grabbing convert quote + timeout
ryanml Apr 4, 2020
1de0ab9
Adding wiring for final conversion step
ryanml Apr 4, 2020
0e66d3a
Index render refactor
ryanml Apr 4, 2020
a48c3b3
Localization, bug fixes
ryanml Apr 4, 2020
dedd323
Removing unused function
ryanml Apr 4, 2020
3ca88ff
Fixing invalid quote parameter, retyping
ryanml Apr 4, 2020
f7b194f
Setting convert expiry time to 30 seconds
ryanml Apr 5, 2020
0ddbf2f
Using full asset list for convert from
ryanml Apr 5, 2020
5adf8db
Modifying baseAsset value, including extra currencies in list
ryanml Apr 6, 2020
922d33a
Adding invalid token/reconnect flow
ryanml Apr 6, 2020
1cc4fe3
Not using URL query for convert confirm request
ryanml Apr 6, 2020
82da535
Last minute display tweaks
ryanml Apr 6, 2020
74f5ed7
Improved error handling for crypto conversions
ryanml Apr 6, 2020
c2869b0
Updating binance_enabled build flag
ryanml Apr 6, 2020
f6844ad
Addressing code review comments
ryanml Apr 7, 2020
04949e8
Displaying total account balance in BTC, total USD value
ryanml Apr 7, 2020
a6e9551
Hiding dropdowns when clicking outside of them
ryanml Apr 7, 2020
5c0fb48
Adding guard for migration, don't rely on accountBalances in buyView
ryanml Apr 7, 2020
e84402b
Fixing test build, NaN BTC value, migration path
ryanml Apr 7, 2020
f245bbe
Listing accounts with balances at the top
ryanml Apr 7, 2020
68622b7
Hiding balance by default, re-fetching clientURL on disconnect
ryanml Apr 8, 2020
cef6edd
Fixes brave/brave-browser#9079 - Removes duplicate binance toggle entry
ryanml Apr 8, 2020
96316bc
Addressing review feedback
ryanml Apr 8, 2020
fa40f54
Moving connect button from header, disconnect action to widget menu
ryanml Apr 8, 2020
596cb27
Implement review feedback
bbondy Apr 9, 2020
3972d72
Make sure no API access in extensions
bbondy Apr 9, 2020
06048c5
Add Binance service tests for all APIs
bbondy Apr 9, 2020
cb730fc
Moving data update actions to newTab, refresh action in menu
ryanml Apr 9, 2020
1d7fea7
Fixing bug where new NTP pages show un-authed view
ryanml Apr 9, 2020
8f64a15
Reordering nav menu, fixing widget menu persistence
ryanml Apr 10, 2020
74c48b1
Add and use API to revoke token
bbondy Apr 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import("//brave/build/config.gni")
import("//brave/components/binance/browser/buildflags/buildflags.gni")
import("//brave/browser/tor/buildflags/buildflags.gni")
import("//brave/components/brave_ads/browser/buildflags/buildflags.gni")
import("//brave/components/brave_perf_predictor/browser/buildflags/buildflags.gni")
Expand Down Expand Up @@ -126,12 +127,14 @@ source_set("browser_process") {
"//brave/common",
"//brave/common:pref_names",
"//brave/components/brave_ads/browser",
"//brave/components/binance/browser/buildflags",
"//brave/components/brave_component_updater/browser",
"//brave/components/brave_drm",
"//brave/components/brave_referrals/browser",
"//brave/components/brave_rewards/browser",
"//brave/components/brave_shields/browser",
"//brave/components/brave_shields/common",
"//brave/components/brave_wallet/browser/buildflags",
"//brave/components/brave_wayback_machine:buildflags",
"//brave/components/brave_webtorrent/browser/buildflags",
"//brave/components/content_settings/core/browser",
Expand Down Expand Up @@ -249,6 +252,15 @@ source_set("browser_process") {
]
}

if (binance_enabled) {
sources += [
"binance/binance_service_factory.cc",
"binance/binance_service_factory.h",
]

deps += [ "//brave/components/binance/browser" ]
}

if (enable_tor) {
deps += [
"//brave/browser/tor",
Expand Down
41 changes: 41 additions & 0 deletions browser/binance/binance_service_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/binance/binance_service_factory.h"

#include "brave/components/binance/browser/binance_service.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"

// static
BinanceServiceFactory* BinanceServiceFactory::GetInstance() {
return base::Singleton<BinanceServiceFactory>::get();
}

// static
BinanceService* BinanceServiceFactory::GetForProfile(Profile* profile) {
return static_cast<BinanceService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}

BinanceServiceFactory::BinanceServiceFactory()
: BrowserContextKeyedServiceFactory(
"BinanceService",
BrowserContextDependencyManager::GetInstance()) {
}

BinanceServiceFactory::~BinanceServiceFactory() {
}

KeyedService* BinanceServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new BinanceService(Profile::FromBrowserContext(context));
}

content::BrowserContext* BinanceServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
35 changes: 35 additions & 0 deletions browser/binance/binance_service_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_BINANCE_BINANCE_SERVICE_FACTORY_H_
#define BRAVE_BROWSER_BINANCE_BINANCE_SERVICE_FACTORY_H_

#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"

class BinanceService;
class Profile;

class BinanceServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static BinanceService* GetForProfile(Profile* profile);
static BinanceServiceFactory* GetInstance();

private:
friend struct base::DefaultSingletonTraits<BinanceServiceFactory>;

BinanceServiceFactory();
~BinanceServiceFactory() override;

// BrowserContextKeyedServiceFactory overrides:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;

DISALLOW_COPY_AND_ASSIGN(BinanceServiceFactory);
};

#endif // BRAVE_BROWSER_BINANCE_BINANCE_SERVICE_FACTORY_H_
13 changes: 13 additions & 0 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "brave/browser/tor/buildflags.h"
#include "brave/common/pref_names.h"
#include "brave/common/webui_url_constants.h"
#include "brave/components/binance/browser/buildflags/buildflags.h"
#include "brave/components/brave_ads/browser/buildflags/buildflags.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
Expand Down Expand Up @@ -102,6 +103,10 @@ using extensions::ChromeContentBrowserClientExtensionsPart;
#include "content/public/common/resource_type.h"
#endif

#if BUILDFLAG(BINANCE_ENABLED)
#include "brave/components/binance/browser/binance_protocol_handler.h"
#endif

namespace {

bool HandleURLReverseOverrideRewrite(GURL* url,
Expand Down Expand Up @@ -186,6 +191,14 @@ bool BraveContentBrowserClient::HandleExternalProtocol(
}
#endif

#if BUILDFLAG(BINANCE_ENABLED)
if (binance::IsBinanceProtocol(url)) {
binance::HandleBinanceProtocol(url, std::move(web_contents_getter),
page_transition, has_user_gesture);
return true;
}
#endif

return ChromeContentBrowserClient::HandleExternalProtocol(
url, std::move(web_contents_getter), child_id, navigation_data,
is_main_frame, page_transition, has_user_gesture, initiating_origin,
Expand Down
7 changes: 7 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "brave/browser/themes/brave_dark_mode_utils.h"
#include "brave/common/brave_wallet_constants.h"
#include "brave/common/pref_names.h"
#include "brave/components/binance/browser/buildflags/buildflags.h"
#include "brave/components/brave_perf_predictor/browser/buildflags.h"
#include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h"
#include "brave/components/brave_sync/brave_sync_prefs.h"
Expand Down Expand Up @@ -203,6 +204,12 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterIntegerPref(kBraveWalletWeb3Provider,
static_cast<int>(BraveWalletWeb3ProviderTypes::ASK));

// Binance widget
#if BUILDFLAG(BINANCE_ENABLED)
registry->RegisterStringPref(kBinanceAccessToken, "");
registry->RegisterStringPref(kBinanceRefreshToken, "");
bbondy marked this conversation as resolved.
Show resolved Hide resolved
#endif

// Autocomplete in address bar
registry->RegisterBooleanPref(kAutocompleteEnabled, true);

Expand Down
2 changes: 1 addition & 1 deletion browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import("//brave/browser/tor/buildflags/buildflags.gni")
import("//brave/components/binance/buildflags.gni")
import("//brave/components/binance/browser/buildflags/buildflags.gni")
import("//brave/components/brave_rewards/browser/buildflags/buildflags.gni")
import("//brave/components/brave_sync/buildflags/buildflags.gni")
import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni")
Expand Down
Loading