Skip to content

Commit

Permalink
Merge pull request #2502 from brave/panel-twip-screen-name
Browse files Browse the repository at this point in the history
Twip from panel must use Twitter handle not name
  • Loading branch information
emerick authored May 27, 2019
2 parents 323dddf + 87f3345 commit 8f07fc0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions browser/extensions/api/brave_rewards_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ ExtensionFunction::ResponseAction BraveRewardsTipSiteFunction::Run() {

auto params_dict = std::make_unique<base::DictionaryValue>();
params_dict->SetString("publisherKey", params->publisher_key);
params_dict->SetString(
"url", contents ? contents->GetLastCommittedURL().spec() : std::string());
::brave_rewards::OpenTipDialog(contents, std::move(params_dict));

return RespondNow(NoArguments());
Expand Down Expand Up @@ -143,6 +145,7 @@ void BraveRewardsTipTwitterUserFunction::OnTwitterPublisherInfoSaved(

auto params_dict = std::make_unique<base::DictionaryValue>();
params_dict->SetString("publisherKey", publisher_info->id);
params_dict->SetString("url", publisher_info->url);

auto tweet_meta_data_dict = std::make_unique<base::DictionaryValue>();
tweet_meta_data_dict->SetString("name", publisher_info->name);
Expand Down
8 changes: 6 additions & 2 deletions components/brave_rewards/resources/tip/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import TipTwitterUser from './tipTwitterUser'
import * as rewardsActions from '../actions/tip_actions'

interface TipDialogArgs {
url: string
publisherKey: string
tweetMetaData?: RewardsTip.TweetMetaData
}
Expand All @@ -27,17 +28,19 @@ export class App extends React.Component<Props, {}> {
return this.props.actions
}

getTipBanner = (publisher: RewardsTip.Publisher, tweetMetaData?: RewardsTip.TweetMetaData) => {
getTipBanner = (url: string, publisher: RewardsTip.Publisher, tweetMetaData?: RewardsTip.TweetMetaData) => {
if (tweetMetaData) {
return (
<TipTwitterUser
url={url}
publisher={publisher}
tweetMetaData={tweetMetaData}
/>
)
} else {
return (
<TipSite
url={url}
publisher={publisher}
/>
)
Expand All @@ -51,6 +54,7 @@ export class App extends React.Component<Props, {}> {
return null
}

const url = this.props.dialogArgs.url
const tweetMetaData = this.props.dialogArgs.tweetMetaData
const publisherKey = this.props.dialogArgs.publisherKey
const publisher = publishers[publisherKey]
Expand All @@ -61,7 +65,7 @@ export class App extends React.Component<Props, {}> {

return (
<div>
{this.getTipBanner(publisher, tweetMetaData)}
{this.getTipBanner(url, publisher, tweetMetaData)}
</div>
)
}
Expand Down
11 changes: 10 additions & 1 deletion components/brave_rewards/resources/tip/components/tipSite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import TransientTipOverlay from './transientTipOverlay'
import * as rewardsActions from '../actions/tip_actions'

interface Props extends RewardsTip.ComponentProps {
url: string
publisher: RewardsTip.Publisher
}

Expand All @@ -23,7 +24,15 @@ class TipSite extends React.Component<Props, {}> {
}

onTweet = () => {
this.actions.onTweet(this.props.publisher.name, '')
let name = this.props.publisher.name
if (this.props.publisher.provider === 'twitter') {
const url = this.props.url
if (url && url.length > 0) {
name = `@${url.replace(/^.*\/(.*)$/, '$1')}`
}
}

this.actions.onTweet(name, '')
this.actions.onCloseDialog()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as rewardsActions from '../actions/tip_actions'
import { getLocale } from '../../../../common/locale'

interface Props extends RewardsTip.ComponentProps {
url: string
publisher: RewardsTip.Publisher
tweetMetaData: RewardsTip.TweetMetaData
}
Expand Down

0 comments on commit 8f07fc0

Please sign in to comment.