-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6681 from brave/ntp-update-bdc
Adding Bitcoin.com widget to the NTP
- Loading branch information
Showing
64 changed files
with
1,606 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* 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/extensions/api/moonpay_api.h" | ||
|
||
#include <string> | ||
#include <memory> | ||
#include <utility> | ||
|
||
#include "brave/browser/profiles/profile_util.h" | ||
#include "brave/components/moonpay/browser/regions.h" | ||
#include "brave/components/moonpay/common/pref_names.h" | ||
#include "brave/components/ntp_widget_utils/browser/ntp_widget_utils_region.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "components/prefs/pref_service.h" | ||
|
||
namespace { | ||
bool IsMoonpayAPIAvailable(content::BrowserContext* context) { | ||
return brave::IsRegularProfile(context); | ||
} | ||
} | ||
|
||
namespace extensions { | ||
namespace api { | ||
|
||
ExtensionFunction::ResponseAction | ||
MoonpayIsBitcoinDotComSupportedFunction::Run() { | ||
Profile* profile = Profile::FromBrowserContext(browser_context()); | ||
|
||
if (!IsMoonpayAPIAvailable(browser_context())) { | ||
return RespondNow(Error("Not available in Tor/incognito/guest profile")); | ||
} | ||
|
||
bool is_supported = ntp_widget_utils::IsRegionSupported( | ||
profile->GetPrefs(), moonpay::bitcoin_dot_com_supported_regions, true); | ||
return RespondNow(OneArgument( | ||
std::make_unique<base::Value>(is_supported))); | ||
} | ||
|
||
ExtensionFunction::ResponseAction | ||
MoonpayOnBuyBitcoinDotComCryptoFunction::Run() { | ||
Profile* profile = Profile::FromBrowserContext(browser_context()); | ||
|
||
if (!IsMoonpayAPIAvailable(browser_context())) { | ||
return RespondNow(Error("Not available in Tor/incognito/guest profile")); | ||
} | ||
|
||
profile->GetPrefs()->SetBoolean(kMoonpayHasBoughtBitcoinDotComCrypto, true); | ||
profile->GetPrefs()->SetBoolean(kMoonpayHasInteractedBitcoinDotCom, true); | ||
|
||
return RespondNow(NoArguments()); | ||
} | ||
|
||
ExtensionFunction::ResponseAction | ||
MoonpayOnInteractionBitcoinDotComFunction::Run() { | ||
Profile* profile = Profile::FromBrowserContext(browser_context()); | ||
|
||
if (!IsMoonpayAPIAvailable(browser_context())) { | ||
return RespondNow(Error("Not available in Tor/incognito/guest profile")); | ||
} | ||
|
||
profile->GetPrefs()->SetBoolean(kMoonpayHasInteractedBitcoinDotCom, true); | ||
|
||
return RespondNow(NoArguments()); | ||
} | ||
|
||
ExtensionFunction::ResponseAction | ||
MoonpayGetBitcoinDotComInteractionsFunction::Run() { | ||
Profile* profile = Profile::FromBrowserContext(browser_context()); | ||
|
||
if (!IsMoonpayAPIAvailable(browser_context())) { | ||
return RespondNow(Error("Not available in Tor/incognito/guest profile")); | ||
} | ||
|
||
bool has_bought = profile->GetPrefs()->GetBoolean( | ||
kMoonpayHasBoughtBitcoinDotComCrypto); | ||
bool has_interacted = profile->GetPrefs()->GetBoolean( | ||
kMoonpayHasInteractedBitcoinDotCom); | ||
|
||
auto interactions = std::make_unique<base::DictionaryValue>(); | ||
interactions->SetBoolean("boughtCrypto", has_bought); | ||
interactions->SetBoolean("interacted", has_interacted); | ||
|
||
return RespondNow(OneArgument(std::move(interactions))); | ||
} | ||
|
||
} // namespace api | ||
} // namespace extensions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* 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_EXTENSIONS_API_MOONPAY_API_H_ | ||
#define BRAVE_BROWSER_EXTENSIONS_API_MOONPAY_API_H_ | ||
|
||
#include <map> | ||
#include <string> | ||
|
||
#include "extensions/browser/extension_function.h" | ||
|
||
class Profile; | ||
|
||
namespace extensions { | ||
namespace api { | ||
|
||
class MoonpayIsBitcoinDotComSupportedFunction : | ||
public ExtensionFunction { | ||
public: | ||
DECLARE_EXTENSION_FUNCTION("moonpay.isBitcoinDotComSupported", UNKNOWN) | ||
|
||
protected: | ||
~MoonpayIsBitcoinDotComSupportedFunction() override {} | ||
ResponseAction Run() override; | ||
}; | ||
|
||
class MoonpayOnBuyBitcoinDotComCryptoFunction : | ||
public ExtensionFunction { | ||
public: | ||
DECLARE_EXTENSION_FUNCTION("moonpay.onBuyBitcoinDotComCrypto", UNKNOWN) | ||
|
||
protected: | ||
~MoonpayOnBuyBitcoinDotComCryptoFunction() override {} | ||
ResponseAction Run() override; | ||
}; | ||
|
||
class MoonpayOnInteractionBitcoinDotComFunction : | ||
public ExtensionFunction { | ||
public: | ||
DECLARE_EXTENSION_FUNCTION("moonpay.onInteractionBitcoinDotCom", UNKNOWN) | ||
|
||
protected: | ||
~MoonpayOnInteractionBitcoinDotComFunction() override {} | ||
ResponseAction Run() override; | ||
}; | ||
|
||
class MoonpayGetBitcoinDotComInteractionsFunction : | ||
public ExtensionFunction { | ||
public: | ||
DECLARE_EXTENSION_FUNCTION("moonpay.getBitcoinDotComInteractions", UNKNOWN) | ||
|
||
protected: | ||
~MoonpayGetBitcoinDotComInteractionsFunction() override {} | ||
ResponseAction Run() override; | ||
}; | ||
|
||
|
||
} // namespace api | ||
} // namespace extensions | ||
|
||
#endif // BRAVE_BROWSER_EXTENSIONS_API_MOONPAY_API_H_ |
Oops, something went wrong.