2018-09-26 19:48:07 +02:00
// @flow
2020-03-13 01:56:02 +01:00
import React , { useState } from 'react' ;
2017-12-21 22:08:54 +01:00
import { Modal } from 'modal/modal' ;
2020-03-13 01:56:02 +01:00
import { FormField } from 'component/common/form' ;
2017-12-21 22:08:54 +01:00
import * as txnTypes from 'constants/transaction_types' ;
2017-10-27 21:42:54 +02:00
2018-09-26 19:48:07 +02:00
type Props = {
closeModal : ( ) => void ,
abandonClaim : ( string , number ) => void ,
txid : string ,
nout : number ,
2019-01-10 02:38:26 +01:00
transactionItems : Array < Transaction > ,
2018-09-26 19:48:07 +02:00
} ;
2017-10-27 21:42:54 +02:00
2020-03-13 01:56:02 +01:00
export default function ModalRevokeClaim ( props : Props ) {
const { transactionItems , txid , nout , closeModal } = props ;
const { type , claim _name : name } = transactionItems . find ( claim => claim . txid === txid && claim . nout === nout ) || { } ;
const [ channelName , setChannelName ] = useState ( '' ) ;
2017-10-30 17:25:56 +01:00
2020-03-13 01:56:02 +01:00
function getButtonLabel ( type : string ) {
2018-09-26 19:48:07 +02:00
if ( type === txnTypes . TIP ) {
2017-12-21 22:08:54 +01:00
return 'Confirm Tip Unlock' ;
2019-07-19 22:21:41 +02:00
} else if ( type === txnTypes . SUPPORT ) {
return 'Confirm Support Revoke' ;
2017-11-01 21:23:30 +01:00
}
2017-12-21 22:08:54 +01:00
return 'Confirm Claim Revoke' ;
2017-11-01 21:23:30 +01:00
}
2020-03-13 01:56:02 +01:00
function getMsgBody ( type : string , name : string ) {
2018-09-26 19:48:07 +02:00
if ( type === txnTypes . TIP ) {
2017-11-01 21:23:30 +01:00
return (
2018-09-26 19:48:07 +02:00
< React.Fragment >
< p > { _ _ ( 'Are you sure you want to unlock these credits?' ) } < / p >
2017-11-01 21:23:30 +01:00
< p >
{ _ _ (
2018-09-26 19:48:07 +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.'
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
) ;
2019-07-17 05:23:45 +02:00
} else if ( type === txnTypes . SUPPORT ) {
return (
< React.Fragment >
< p > { _ _ ( 'Are you sure you want to remove this support?' ) } < / p >
< p >
{ _ _ (
"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."
) }
< / p >
< / React.Fragment >
) ;
2020-04-06 19:37:54 +02:00
} else if ( type === txnTypes . CHANNEL || ( type === txnTypes . UPDATE && name . startsWith ( '@' ) ) ) {
2020-03-13 01:56:02 +01:00
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 >
) ;
2017-12-21 22:08:54 +01:00
}
2020-03-13 01:56:02 +01:00
2017-12-21 22:08:54 +01:00
return (
2018-09-26 19:48:07 +02:00
< React.Fragment >
< p > { _ _ ( 'Are you sure want to revoke this claim?' ) } < / p >
2017-12-21 22:08:54 +01:00
< p >
{ _ _ (
2018-09-26 19:48:07 +02:00
'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.'
2017-12-21 22:08:54 +01:00
) }
< / p >
2019-12-28 20:39:08 +01:00
< 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-12-21 22:08:54 +01:00
) ;
2017-10-27 21:42:54 +02:00
}
2020-03-13 01:56:02 +01:00
function revokeClaim ( ) {
const { txid , nout } = props ;
2018-09-26 19:48:07 +02:00
2020-03-13 01:56:02 +01:00
props . closeModal ( ) ;
props . abandonClaim ( txid , nout ) ;
2018-09-26 19:48:07 +02:00
}
2020-03-13 01:56:02 +01:00
return (
< Modal
isOpen
title = { getButtonLabel ( type ) }
contentLabel = { getButtonLabel ( type ) }
type = "confirm"
confirmButtonLabel = { getButtonLabel ( type ) }
onConfirmed = { revokeClaim }
onAborted = { closeModal }
confirmButtonDisabled = { type === txnTypes . CHANNEL && name !== channelName }
>
< section > { getMsgBody ( type , name ) } < / section >
< / Modal >
) ;
2017-10-27 21:42:54 +02:00
}