lbry-desktop/ui/modal/modalRevokeClaim/view.jsx

116 lines
4.2 KiB
React
Raw Normal View History

2018-09-26 19:48:07 +02:00
// @flow
import React, { useState } from 'react';
import { Modal } from 'modal/modal';
import { FormField } from 'component/common/form';
import * as txnTypes from 'constants/transaction_types';
2020-05-01 19:55:42 +02:00
import Card from 'component/common/card';
import Button from 'component/button';
2020-09-02 22:08:37 +02:00
import I18nMessage from 'component/i18nMessage';
import LbcSymbol from 'component/common/lbc-symbol';
2017-10-27 21:42:54 +02:00
2018-09-26 19:48:07 +02:00
type Props = {
closeModal: () => void,
abandonTxo: (Txo, () => void) => void,
abandonClaim: (string, number, ?() => void) => void,
tx: Txo,
claim: GenericClaim,
cb: () => void,
2018-09-26 19:48:07 +02:00
};
2017-10-27 21:42:54 +02:00
export default function ModalRevokeClaim(props: Props) {
const { tx, claim, closeModal, abandonTxo, abandonClaim, cb } = props;
2020-05-22 03:19:01 +02:00
const { value_type: valueType, type, normalized_name: name, is_my_input: isSupport } = tx || claim;
const [channelName, setChannelName] = useState('');
2017-10-30 17:25:56 +01:00
2020-06-07 21:17:18 +02:00
const shouldConfirmChannel =
valueType === txnTypes.CHANNEL || type === txnTypes.CHANNEL || (type === txnTypes.UPDATE && name.startsWith('@'));
2020-05-22 03:19:01 +02:00
function getButtonLabel(type: string, isSupport: boolean) {
if (isSupport && type === txnTypes.SUPPORT) {
2020-06-20 16:17:11 +02:00
return __('Confirm Support Revoke');
2020-05-22 03:19:01 +02:00
} else if (type === txnTypes.SUPPORT) {
2020-06-20 16:17:11 +02:00
return __('Confirm Tip Unlock');
2017-11-01 21:23:30 +01:00
}
2020-06-20 16:17:11 +02:00
return __('Confirm Claim Revoke');
2017-11-01 21:23:30 +01:00
}
2020-05-22 03:19:01 +02:00
function getMsgBody(type: string, isSupport: boolean, name: string) {
if (isSupport && type === txnTypes.SUPPORT) {
2017-11-01 21:23:30 +01:00
return (
2018-09-26 19:48:07 +02:00
<React.Fragment>
2020-05-22 03:19:01 +02:00
<p>{__('Are you sure you want to remove this support?')}</p>
2017-11-01 21:23:30 +01:00
<p>
2020-09-02 22:08:37 +02:00
<I18nMessage tokens={{ lbc: <LbcSymbol /> }}>
These credits are permanently yours and can be removed at any time. Removing this support will reduce the
claim's discoverability and return the %lbc% to your spendable balance.
</I18nMessage>
2017-11-01 21:23:30 +01:00
</p>
2018-09-26 19:48:07 +02:00
</React.Fragment>
2017-11-01 21:23:30 +01:00
);
} else if (type === txnTypes.SUPPORT) {
return (
<React.Fragment>
2020-05-22 03:19:01 +02:00
<p>{__('Are you sure you want to unlock these credits?')}</p>
<p>
{__(
2020-05-22 03:19:01 +02:00
'These credits are permanently yours and can be unlocked at any time. Unlocking them allows you to spend them, but can hurt the performance of your content in lookups and search results. It is recommended you leave tips locked until you need or want to spend them.'
)}
</p>
</React.Fragment>
);
2020-06-07 21:17:18 +02:00
} else if (shouldConfirmChannel) {
return (
<React.Fragment>
<p>
{__(
"You're about to permanently delete a channel. Content published under this channel will be orphaned and their signing channel invalid. Content sync programs using this channel will fail."
)}
</p>
<p>{__('Are you sure? Type %name% to confirm that you wish to delete the channel.', { name })}</p>
<FormField type={'text'} onChange={e => setChannelName(e.target.value)} />
</React.Fragment>
);
}
return (
2018-09-26 19:48:07 +02:00
<React.Fragment>
<p>{__('Are you sure want to revoke this claim?')}</p>
<p>
2020-09-02 22:08:37 +02:00
<I18nMessage tokens={{ lbc: <LbcSymbol /> }}>
This will prevent others from resolving and accessing the content you published. It will return the %lbc% to
your spendable balance, less a small transaction fee.
</I18nMessage>
</p>
<p className="help error__text"> {__('FINAL WARNING: This action is permanent and cannot be undone.')}</p>
2018-09-26 19:48:07 +02:00
</React.Fragment>
);
2017-10-27 21:42:54 +02:00
}
function revokeClaim() {
tx ? abandonTxo(tx, cb) : abandonClaim(claim.txid, claim.nout, cb);
closeModal();
2018-09-26 19:48:07 +02:00
}
2020-05-22 03:19:01 +02:00
const label = getButtonLabel(type, isSupport);
2020-05-01 19:55:42 +02:00
return (
2020-06-07 21:17:18 +02:00
<Modal isOpen contentLabel={label} type="card" onAborted={closeModal}>
2020-05-01 19:55:42 +02:00
<Card
title={label}
2020-05-22 03:19:01 +02:00
body={getMsgBody(type, isSupport, name)}
2020-05-01 19:55:42 +02:00
actions={
<div className="section__actions">
2020-06-07 21:17:18 +02:00
<Button
disabled={shouldConfirmChannel && name !== channelName}
button="primary"
label={label}
onClick={revokeClaim}
/>
2020-05-01 19:55:42 +02:00
<Button button="link" label={__('Cancel')} onClick={closeModal} />
</div>
}
/>
</Modal>
);
2017-10-27 21:42:54 +02:00
}