From 2d77d417858b965ccd32fefcd6d58fb4cced8d58 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 | 45 ++++++------------- 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, 48 insertions(+), 45 deletions(-) diff --git a/browser/ui/webui/brave_donate_ui.cc b/browser/ui/webui/brave_donate_ui.cc index 77608736f31c..4da37501806c 100644 --- a/browser/ui/webui/brave_donate_ui.cc +++ b/browser/ui/webui/brave_donate_ui.cc @@ -174,6 +174,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 f6ce64cd862a..337ad35d5dba 100644 --- a/browser/ui/webui/brave_rewards_ui.cc +++ b/browser/ui/webui/brave_rewards_ui.cc @@ -422,6 +422,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)); @@ -542,6 +543,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 1d3c3490f5fc..041ae803a175 100644 --- a/browser/ui/webui/brave_webui_source.cc +++ b/browser/ui/webui/brave_webui_source.cc @@ -270,6 +270,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 fa8ba0f0bb90..bd742e176ef9 100644 --- a/common/extensions/api/brave_rewards.json +++ b/common/extensions/api/brave_rewards.json @@ -177,6 +177,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 7639b5e88710..b4365e9b5416 100644 --- a/components/brave_rewards/browser/extension_rewards_service_observer.cc +++ b/components/brave_rewards/browser/extension_rewards_service_observer.cc @@ -80,6 +80,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 64381d627c97..97e3f7be728b 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -802,6 +802,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); } @@ -1428,6 +1429,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 d2adaa1c5eed..a66d9be7b6bb 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 @@ -408,5 +408,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 6c384eb74dbf..1b13eeb68ab7 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 @@ -98,6 +98,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 65489b11310e..70fd7c64863f 100644 --- a/components/resources/brave_components_strings.grd +++ b/components/resources/brave_components_strings.grd @@ -498,6 +498,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 c8954617c850..5a0bb167f94d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1597,8 +1597,8 @@ } }, "brave-ui": { - "version": "github:brave/brave-ui#e26bab758d81f6056b36c5a2dfbb3d7b3b5bea6b", - "from": "github:brave/brave-ui#e26bab758d81f6056b36c5a2dfbb3d7b3b5bea6b", + "version": "github:brave/brave-ui#770f19c385f6fab0055e2d32411417ef76128ad2", + "from": "github:brave/brave-ui#770f19c385f6fab0055e2d32411417ef76128ad2", "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 4f300a6a67d0..9217b56b8702 100644 --- a/package.json +++ b/package.json @@ -277,7 +277,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#e26bab758d81f6056b36c5a2dfbb3d7b3b5bea6b", + "brave-ui": "github:brave/brave-ui#770f19c385f6fab0055e2d32411417ef76128ad2", "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 853bdb931d24..f288ebceb60a 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 @@ -277,6 +277,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 4a74499a4bcc..dee27b976c73 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 @@ -897,6 +897,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 { @@ -1164,6 +1168,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(); } @@ -2075,6 +2082,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 858ccab4f112..9ccce02be7a6 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 @@ -729,6 +729,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); }