From ca913fc2aaf65fb5ad1fea31f6994a726a60b3d4 Mon Sep 17 00:00:00 2001 From: Nejc Zdovc Date: Sat, 27 Apr 2019 16:41:56 +0200 Subject: [PATCH] Merge pull request #2337 from brave/claimed-grant-date Removes date from ads grants in the wallet --- browser/ui/webui/brave_donate_ui.cc | 1 + browser/ui/webui/brave_rewards_ui.cc | 2 + browser/ui/webui/brave_webui_source.cc | 1 + common/extensions/api/brave_rewards.json | 4 ++ .../extension_rewards_service_observer.cc | 1 + .../browser/rewards_service_impl.cc | 2 + .../_locales/en_US/messages.json | 4 ++ .../background/api/locale_api.ts | 1 + .../extension/brave_rewards/utils.ts | 8 +-- .../resources/ui/components/pageWallet.tsx | 8 +-- .../resources/brave_components_strings.grd | 1 + package-lock.json | 51 ++++++------------- package.json | 2 +- .../src/bat/ledger/internal/bat_client.cc | 1 + .../src/bat/ledger/internal/bat_helper.cc | 11 ++++ .../src/bat/ledger/internal/ledger_impl.cc | 1 + 16 files changed, 51 insertions(+), 48 deletions(-) diff --git a/browser/ui/webui/brave_donate_ui.cc b/browser/ui/webui/brave_donate_ui.cc index 172fde80096f..78d8465d370a 100644 --- a/browser/ui/webui/brave_donate_ui.cc +++ b/browser/ui/webui/brave_donate_ui.cc @@ -165,6 +165,7 @@ void RewardsDonateDOMHandler::OnWalletProperties( auto grant = std::make_unique(); grant->SetString("probi", item.probi); grant->SetInteger("expiryTime", item.expiryTime); + grant->SetString("type", item.type); grants->Append(std::move(grant)); } walletInfo->SetList("grants", std::move(grants)); diff --git a/browser/ui/webui/brave_rewards_ui.cc b/browser/ui/webui/brave_rewards_ui.cc index 0dabd38b115e..25d52a84c668 100644 --- a/browser/ui/webui/brave_rewards_ui.cc +++ b/browser/ui/webui/brave_rewards_ui.cc @@ -410,6 +410,7 @@ void RewardsDOMHandler::OnGetAutoContributeProps( auto grant = std::make_unique(); grant->SetString("probi", item.probi); grant->SetInteger("expiryTime", item.expiryTime); + grant->SetString("type", item.type); grants->Append(std::move(grant)); } walletInfo->SetList("grants", std::move(grants)); @@ -530,6 +531,7 @@ void RewardsDOMHandler::OnRecoverWallet( auto grant = std::make_unique(); grant->SetString("probi", item.probi); grant->SetInteger("expiryTime", item.expiryTime); + grant->SetString("type", item.type); newGrants->Append(std::move(grant)); } recover.SetList("grants", std::move(newGrants)); diff --git a/browser/ui/webui/brave_webui_source.cc b/browser/ui/webui/brave_webui_source.cc index 8d3520fd2ab1..3e6c0726273a 100644 --- a/browser/ui/webui/brave_webui_source.cc +++ b/browser/ui/webui/brave_webui_source.cc @@ -268,6 +268,7 @@ void CustomizeWebUIHTMLSource(const std::string &name, { "addFundsQR", IDS_BRAVE_UI_ADD_FUNDS_QR}, { "addFundsText", IDS_BRAVE_UI_ADD_FUNDS_TEXT}, { "addFundsTitle", IDS_BRAVE_UI_ADD_FUNDS_TITLE}, + { "adsEarnings", IDS_BRAVE_UI_ADS_EARNINGS }, { "allowTip", IDS_BRAVE_UI_ALLOW_TIP }, { "amount", IDS_BRAVE_UI_AMOUNT }, { "backup", IDS_BRAVE_UI_BACKUP }, diff --git a/common/extensions/api/brave_rewards.json b/common/extensions/api/brave_rewards.json index d0f85815844b..e5bff92dcb6a 100644 --- a/common/extensions/api/brave_rewards.json +++ b/common/extensions/api/brave_rewards.json @@ -172,6 +172,10 @@ "expiryTime": { "type": "integer", "description": "when grant expires, timestamp in seconds" + }, + "type": { + "type": "string", + "description": "grant type, ugp or ads" } } } diff --git a/components/brave_rewards/browser/extension_rewards_service_observer.cc b/components/brave_rewards/browser/extension_rewards_service_observer.cc index 0cc83e13078f..9693c5156b49 100644 --- a/components/brave_rewards/browser/extension_rewards_service_observer.cc +++ b/components/brave_rewards/browser/extension_rewards_service_observer.cc @@ -79,6 +79,7 @@ void ExtensionRewardsServiceObserver::OnWalletProperties( grant.altcurrency = wallet_properties->grants[i].altcurrency; grant.probi = wallet_properties->grants[i].probi; grant.expiry_time = wallet_properties->grants[i].expiryTime; + grant.type = wallet_properties->grants[i].type; } std::unique_ptr args( diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index b7d15611787b..69ee09125fb6 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -796,6 +796,7 @@ void RewardsServiceImpl::OnWalletProperties( grant.altcurrency = wallet_info->grants_[i].altcurrency; grant.probi = wallet_info->grants_[i].probi; grant.expiryTime = wallet_info->grants_[i].expiryTime; + grant.type = wallet_info->grants_[i].type; wallet_properties->grants.push_back(grant); } @@ -1395,6 +1396,7 @@ void RewardsServiceImpl::TriggerOnRecoverWallet(ledger::Result result, grant.altcurrency = grants[i].altcurrency; grant.probi = grants[i].probi; grant.expiryTime = grants[i].expiryTime; + grant.type = grants[i].type; newGrants.push_back(grant); } diff --git a/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json b/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json index 6ee43e4f5994..6a4725805773 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json +++ b/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json @@ -356,5 +356,9 @@ "turnOnAds": { "message": "Turn on Ads", "description": "Prompt to turn on Ads via notification" + }, + "adsEarnings": { + "message": "earned from ads", + "description": "Description text for ad grants in grant details" } } diff --git a/components/brave_rewards/resources/extension/brave_rewards/background/api/locale_api.ts b/components/brave_rewards/resources/extension/brave_rewards/background/api/locale_api.ts index 22d75c196c10..6d6fe7b10f0b 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background/api/locale_api.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background/api/locale_api.ts @@ -86,6 +86,7 @@ export const getUIMessages = (): Record => { 'unVerifiedText', 'unVerifiedTextMore', 'verifiedPublisher', + 'adsEarnings', 'welcomeButtonTextOne', 'welcomeButtonTextTwo', 'welcomeDescOne', diff --git a/components/brave_rewards/resources/extension/brave_rewards/utils.ts b/components/brave_rewards/resources/extension/brave_rewards/utils.ts index 60a4289a3660..76d7e0e11f98 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/utils.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/utils.ts @@ -39,14 +39,10 @@ export const getGrants = (grants?: RewardsExtension.Grant[]) => { } return grants.map((grant: RewardsExtension.Grant) => { - let expireDate = '' - if (grant.type !== 'ads') { - expireDate = new Date(grant.expiryTime * 1000).toLocaleDateString() - } - return { tokens: convertProbiToFixed(grant.probi), - expireDate + expireDate: new Date(grant.expiryTime * 1000).toLocaleDateString(), + type: grant.type || 'ugp' } }) } diff --git a/components/brave_rewards/resources/ui/components/pageWallet.tsx b/components/brave_rewards/resources/ui/components/pageWallet.tsx index aa77edb48612..3f5ead06ad10 100644 --- a/components/brave_rewards/resources/ui/components/pageWallet.tsx +++ b/components/brave_rewards/resources/ui/components/pageWallet.tsx @@ -156,14 +156,10 @@ class PageWallet extends React.Component { } return grants.map((grant: Rewards.Grant) => { - let expireDate = '' - if (grant.type !== 'ads') { - expireDate = new Date(grant.expiryTime * 1000).toLocaleDateString() - } - return { tokens: utils.convertProbiToFixed(grant.probi), - expireDate + expireDate: new Date(grant.expiryTime * 1000).toLocaleDateString(), + type: grant.type || 'ugp' } }) } diff --git a/components/resources/brave_components_strings.grd b/components/resources/brave_components_strings.grd index d316fe9fb2fb..dbf93f7f8b8c 100644 --- a/components/resources/brave_components_strings.grd +++ b/components/resources/brave_components_strings.grd @@ -487,6 +487,7 @@ NOTE: This creator has not yet signed up to receive contributions from Brave users. Your browser will keep trying to contribute until they verify, or until 90 days have passed. Learn more. + earned from ads diff --git a/package-lock.json b/package-lock.json index de28d217f5b9..17cf8253cb0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -226,9 +226,9 @@ } }, "@ctrl/tinycolor": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/@ctrl/tinycolor/-/tinycolor-2.2.1.tgz", - "integrity": "sha512-HFYW2zo5H9L61it865F/6fMOphYRVxdSztcB3DHn9AoaNOO9G+uIBuNXwkt+BwT7CbjQoJ6N5L6VjF5Mumztkw==", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/@ctrl/tinycolor/-/tinycolor-2.4.0.tgz", + "integrity": "sha512-ZLjdsst8/ENM6spDmh3qPQSM+iDSerTGjA05KhAXog7o/aOa9tn7qzWMeOtJzGaDMmsBLxh4IuZ5GH7nfda9gg==", "dev": true }, "@jest/console": { @@ -1597,8 +1597,8 @@ } }, "brave-ui": { - "version": "github:brave/brave-ui#b94af34d0e556795b912499ab80ba2e08d689b8a", - "from": "github:brave/brave-ui#b94af34d0e556795b912499ab80ba2e08d689b8a", + "version": "github:brave/brave-ui#45a826dab14438b564fdf37e3b2d81b0e7027c56", + "from": "github:brave/brave-ui#45a826dab14438b564fdf37e3b2d81b0e7027c56", "dev": true, "requires": { "@ctrl/tinycolor": "^2.2.1", @@ -3470,8 +3470,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -3492,14 +3491,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3514,20 +3511,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -3644,8 +3638,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -3657,7 +3650,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3672,7 +3664,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3680,14 +3671,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -3706,7 +3695,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -3787,8 +3775,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -3800,7 +3787,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -3886,8 +3872,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -3923,7 +3908,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -3943,7 +3927,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3987,14 +3970,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, diff --git a/package.json b/package.json index 334023b10946..959ab592cfda 100644 --- a/package.json +++ b/package.json @@ -276,7 +276,7 @@ "@types/react-redux": "6.0.4", "@types/redux-logger": "^3.0.7", "awesome-typescript-loader": "^5.2.1", - "brave-ui": "github:brave/brave-ui#b94af34d0e556795b912499ab80ba2e08d689b8a", + "brave-ui": "github:brave/brave-ui#45a826dab14438b564fdf37e3b2d81b0e7027c56", "css-loader": "^2.1.1", "csstype": "^2.5.5", "deep-freeze-node": "^1.1.3", diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/bat_client.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/bat_client.cc index b65f0301c40e..22d73bfc710f 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/bat_client.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/bat_client.cc @@ -276,6 +276,7 @@ ledger::WalletInfo BatClient::WalletPropertiesToWalletInfo( grant.altcurrency = properties.grants_[i].altcurrency; grant.probi = properties.grants_[i].probi; grant.expiryTime = properties.grants_[i].expiryTime; + grant.type = properties.grants_[i].type; info.grants_.push_back(grant); } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc index 94991bb5acf0..8b0f8d2a5428 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc @@ -896,6 +896,10 @@ bool WALLET_PROPERTIES_ST::loadFromJson(const std::string & json) { grant.expiryTime = obj["expiryTime"].GetUint64(); } + if (obj.HasMember("type")) { + grant.type = obj["type"].GetString(); + } + grants_.push_back(grant); } } else { @@ -1140,6 +1144,9 @@ void saveToJson(JsonWriter* writer, const GRANT& data) { writer->String("promotionId"); writer->String(data.promotionId.c_str()); + writer->String("type"); + writer->String(data.type.c_str()); + writer->EndObject(); } @@ -2050,6 +2057,10 @@ bool getJSONRecoverWallet(const std::string& json, grant.expiryTime = obj["expiryTime"].GetUint64(); } + if (obj.HasMember("type")) { + grant.type = obj["type"].GetString(); + } + grants->push_back(grant); } } else { diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc index c68feaef872a..9369a7e20e98 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc @@ -650,6 +650,7 @@ void LedgerImpl::OnRecoverWallet( tempGrant.altcurrency = grants[i].altcurrency; tempGrant.probi = grants[i].probi; tempGrant.expiryTime = grants[i].expiryTime; + tempGrant.type = grants[i].type; ledgerGrants.push_back(tempGrant); }