-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rewards 3.0] Validate explore card links and thumbnails
- Loading branch information
1 parent
3c33663
commit 8aaf712
Showing
5 changed files
with
80 additions
and
29 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
components/brave_rewards/resources/rewards_page/components/explore/card_item_view.tsx
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,46 @@ | ||
/* Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. */ | ||
|
||
import * as React from 'react' | ||
|
||
import { UICardItem } from '../../lib/app_state' | ||
import { NewTabLink } from '../../../shared/components/new_tab_link' | ||
|
||
function sanitizeURL(url: string) { | ||
try { | ||
return new URL(url).protocol === 'https:' ? url : '' | ||
} catch { | ||
return '' | ||
} | ||
} | ||
|
||
function thumbnailURL(url: string) { | ||
url = sanitizeURL(url) | ||
try { | ||
if (/(^|\.)brave\.com$/i.test(new URL(url).hostname)) { | ||
return `chrome://rewards-image/${url}` | ||
} | ||
return '' | ||
} catch { | ||
return '' | ||
} | ||
} | ||
|
||
interface Props { | ||
item: UICardItem | ||
} | ||
|
||
export function CardItemView(props: Props) { | ||
const { item } = props | ||
return ( | ||
<NewTabLink href={sanitizeURL(item.url)}> | ||
<img src={thumbnailURL(item.thumbnail)} /> | ||
<span className='item-info'> | ||
<span className='title'>{item.title}</span> | ||
<span className='description'>{item.description}</span> | ||
</span> | ||
</NewTabLink> | ||
) | ||
} |
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