Adding interactions API methods
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "base/environment.h"
|
||||
#include "brave/browser/profiles/profile_util.h"
|
||||
@@ -42,9 +43,43 @@ MoonpayOnBuyBitcoinDotComCryptoFunction::Run() {
|
||||
}
|
||||
|
||||
profile->GetPrefs()->SetBoolean(kMoonpayHasBoughtBitcoinDotComCrypto, true);
|
||||
profile->GetPrefs()->SetBoolean(kMoonpayHasInteractedBitcoinDotCom, true);
|
||||
|
||||
return RespondNow(NoArguments());
|
||||
}
|
||||
|
||||
ExtensionFunction::ResponseAction
|
||||
MoonpayOnInteractionBitcoinDotComFunction::Run() {
|
||||
Profile* profile = Profile::FromBrowserContext(browser_context());
|
||||
|
||||
if (brave::IsTorProfile(profile)) {
|
||||
return RespondNow(Error("Not available in Tor profile"));
|
||||
}
|
||||
|
||||
profile->GetPrefs()->SetBoolean(kMoonpayHasInteractedBitcoinDotCom, true);
|
||||
|
||||
return RespondNow(NoArguments());
|
||||
}
|
||||
|
||||
ExtensionFunction::ResponseAction
|
||||
MoonpayGetBitcoinDotComInteractionsFunction::Run() {
|
||||
Profile* profile = Profile::FromBrowserContext(browser_context());
|
||||
|
||||
if (brave::IsTorProfile(profile)) {
|
||||
return RespondNow(Error("Not available in Tor 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
|
||||
|
||||
@@ -36,6 +36,27 @@ class MoonpayOnBuyBitcoinDotComCryptoFunction :
|
||||
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
|
||||
|
||||
|
||||
@@ -34,6 +34,39 @@
|
||||
"type": "function",
|
||||
"description": "Marks when a user has used the bitcoin.com widget to buy crypto",
|
||||
"parameters": []
|
||||
},
|
||||
{
|
||||
"name": "onInteractionBitcoinDotCom",
|
||||
"type": "function",
|
||||
"description": "Marks user interaction with the bitcoin.com widget",
|
||||
"parameters": []
|
||||
},
|
||||
{
|
||||
"name": "getBitcoinDotComInteractions",
|
||||
"type": "function",
|
||||
"description": "Fetches user interactions with bitcoin.com",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "function",
|
||||
"name": "callback",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "interactions",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"boughtCrypto": {
|
||||
"type": "boolean",
|
||||
"description": "Has clicked the buy button"
|
||||
},
|
||||
"interacted": {
|
||||
"type": "boolean",
|
||||
"description": "Has interacted"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
|
||||
@@ -7,3 +7,5 @@ import { action } from 'typesafe-actions'
|
||||
import { types } from '../constants/bitcoin_dot_com_types'
|
||||
|
||||
export const buyBitcoinDotComCrypto = () => action(types.BUY_BITCOIN_DOT_COM_CRYPTO)
|
||||
|
||||
export const interactionBitcoinDotCom = () => action(types.INTERACTION_BITCOIN_DOT_COM)
|
||||
|
||||
@@ -25,6 +25,7 @@ interface Props {
|
||||
stackPosition: number
|
||||
onShowContent: () => void
|
||||
onBuyCrypto: () => void
|
||||
onInteraction: () => void
|
||||
}
|
||||
|
||||
class BitcoinDotCom extends React.PureComponent<Props, State> {
|
||||
@@ -72,6 +73,7 @@ class BitcoinDotCom extends React.PureComponent<Props, State> {
|
||||
this.setState({
|
||||
assetsShowing: !this.state.assetsShowing
|
||||
})
|
||||
this.props.onInteraction()
|
||||
}
|
||||
|
||||
setSelectedAsset = (asset: string) => {
|
||||
@@ -85,12 +87,14 @@ class BitcoinDotCom extends React.PureComponent<Props, State> {
|
||||
this.setState({
|
||||
currentAmount: target.value
|
||||
})
|
||||
this.props.onInteraction()
|
||||
}
|
||||
|
||||
toggleFiatCurrenciesShowing = () => {
|
||||
this.setState({
|
||||
fiatCurrenciesShowing: !this.state.fiatCurrenciesShowing
|
||||
})
|
||||
this.props.onInteraction()
|
||||
}
|
||||
|
||||
setSelectedFiat = (fiat: string) => {
|
||||
@@ -126,6 +130,7 @@ class BitcoinDotCom extends React.PureComponent<Props, State> {
|
||||
|
||||
openInfoURL = () => {
|
||||
window.open('https://bitcoincom.moonpay.io/', '_blank', 'noopener')
|
||||
this.props.onInteraction()
|
||||
}
|
||||
|
||||
renderCurrencyInput () {
|
||||
|
||||
@@ -43,7 +43,7 @@ export const BitcoinDotComIcon = styled<{}, 'div'>('div')`
|
||||
`
|
||||
|
||||
export const TitleText = styled<{}, 'div'>('div')`
|
||||
margin-top: 4px;
|
||||
margin-top: -2px;
|
||||
`
|
||||
|
||||
export const InputHeader = styled<{}, 'div'>('div')`
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
// you can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
export const enum types {
|
||||
BUY_BITCOIN_DOT_COM_CRYPTO = '@@bitcoin_dot_com/BUY_BITCOIN_DOT_COM_CRYPTO'
|
||||
BUY_BITCOIN_DOT_COM_CRYPTO = '@@bitcoin_dot_com/BUY_BITCOIN_DOT_COM_CRYPTO',
|
||||
INTERACTION_BITCOIN_DOT_COM = '@@bitcoin_dot_com/INTERACTION_BITCOIN_DOT_COM'
|
||||
}
|
||||
|
||||
@@ -410,6 +410,10 @@ class NewTabPage extends React.Component<Props, State> {
|
||||
this.props.actions.buyBitcoinDotComCrypto()
|
||||
}
|
||||
|
||||
onInteractionBitcoinDotCom = () => {
|
||||
this.props.actions.interactionBitcoinDotCom()
|
||||
}
|
||||
|
||||
onBinanceUserTLD = (userTLD: NewTab.BinanceTLD) => {
|
||||
this.props.actions.onBinanceUserTLD(userTLD)
|
||||
}
|
||||
@@ -941,6 +945,7 @@ class NewTabPage extends React.Component<Props, State> {
|
||||
showContent={showContent}
|
||||
onShowContent={this.setForegroundStackWidget.bind(this, 'bitcoinDotCom')}
|
||||
onBuyCrypto={this.onBuyBitcoinDotComCrypto}
|
||||
onInteraction={this.onInteractionBitcoinDotCom}
|
||||
lightWidget={showContent}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -11,6 +11,10 @@ const bitcoinDotComReducer: Reducer<NewTab.State | undefined> = (state: NewTab.S
|
||||
chrome.moonpay.onBuyBitcoinDotComCrypto()
|
||||
break
|
||||
|
||||
case types.INTERACTION_BITCOIN_DOT_COM:
|
||||
chrome.moonpay.onInteractionBitcoinDotCom()
|
||||
break
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import gridSitesReducer from './grid_sites_reducer'
|
||||
import binanceReducer from './binance_reducer'
|
||||
import rewardsReducer from './rewards_reducer'
|
||||
import geminiReducer from './gemini_reducer'
|
||||
import bitcoinDotComReducer from './bitcoin_dot_com_reducer'
|
||||
|
||||
export const newTabReducers = (state: NewTab.State | undefined, action: any) => {
|
||||
if (state === undefined) {
|
||||
@@ -23,6 +24,7 @@ export const newTabReducers = (state: NewTab.State | undefined, action: any) =>
|
||||
state = binanceReducer(state, action)
|
||||
state = rewardsReducer(state, action)
|
||||
state = geminiReducer(state, action)
|
||||
state = bitcoinDotComReducer(state, action)
|
||||
|
||||
if (state !== startingState) {
|
||||
storage.debouncedSave(state)
|
||||
|
||||
Vendored
+2
@@ -198,6 +198,8 @@ declare namespace chrome.braveTogether {
|
||||
declare namespace chrome.moonpay {
|
||||
const isBitcoinDotComSupported: (callback: (supported: boolean) => void) => {}
|
||||
const onBuyBitcoinDotComCrypto: () => void
|
||||
const onInteractionBitcoinDotCom: () => void
|
||||
const getBitcoinDotComInteractions: (callback: (interactions: Record<string, string>) => void) => {}
|
||||
}
|
||||
|
||||
declare namespace chrome.rewardsNotifications {
|
||||
|
||||
@@ -18,6 +18,7 @@ MoonpayPrefUtils::~MoonpayPrefUtils() {}
|
||||
void MoonpayPrefUtils::RegisterPrefs(PrefRegistrySimple* registry) {
|
||||
registry->RegisterBooleanPref(kMoonpayNewTabPageShowBitcoinDotCom, true);
|
||||
registry->RegisterBooleanPref(kMoonpayHasBoughtBitcoinDotComCrypto, false);
|
||||
registry->RegisterBooleanPref(kMoonpayHasInteractedBitcoinDotCom, false);
|
||||
}
|
||||
|
||||
} // namespace moonpay
|
||||
|
||||
@@ -7,5 +7,7 @@
|
||||
|
||||
const char kMoonpayHasBoughtBitcoinDotComCrypto[] =
|
||||
"moonpay.has_bought_bitcoin_dot_com_crypto";
|
||||
const char kMoonpayHasInteractedBitcoinDotCom[] =
|
||||
"moonpay.has_interacted_bitcoin_dot_com";
|
||||
const char kMoonpayNewTabPageShowBitcoinDotCom[] =
|
||||
"moonpay.new_tab_page.show_bitcoin_dot_com";
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#define BRAVE_COMPONENTS_MOONPAY_COMMON_MOONPAY_PREF_NAMES_H_
|
||||
|
||||
extern const char kMoonpayHasBoughtBitcoinDotComCrypto[];
|
||||
extern const char kMoonpayHasInteractedBitcoinDotCom[];
|
||||
extern const char kMoonpayNewTabPageShowBitcoinDotCom[];
|
||||
|
||||
#endif // BRAVE_COMPONENTS_MOONPAY_COMMON_MOONPAY_PREF_NAMES_H_
|
||||
|
||||
Reference in New Issue
Block a user