2022-08-05 11:13:27 +00:00
|
|
|
import { Conditional } from 'components/Conditional'
|
2022-08-04 09:16:42 +00:00
|
|
|
import { FormGroup } from 'components/FormGroup'
|
2022-09-01 06:27:23 +00:00
|
|
|
import { useInputState } from 'components/forms/FormInput.hooks'
|
2023-01-12 10:01:11 +00:00
|
|
|
import { useWallet } from 'contexts/wallet'
|
2022-08-05 11:13:27 +00:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2022-08-04 09:16:42 +00:00
|
|
|
|
2023-01-12 10:01:11 +00:00
|
|
|
import { resolveAddress } from '../../../utils/resolveAddress'
|
2022-08-04 09:16:42 +00:00
|
|
|
import { NumberInput, TextInput } from '../../forms/FormInput'
|
|
|
|
|
|
|
|
interface RoyaltyDetailsProps {
|
|
|
|
onChange: (data: RoyaltyDetailsDataProps) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RoyaltyDetailsDataProps {
|
2022-08-05 11:13:27 +00:00
|
|
|
royaltyType: RoyaltyState
|
2022-08-04 09:16:42 +00:00
|
|
|
paymentAddress: string
|
|
|
|
share: number
|
|
|
|
}
|
|
|
|
|
2022-08-05 11:13:27 +00:00
|
|
|
type RoyaltyState = 'none' | 'new'
|
|
|
|
|
2022-08-04 09:16:42 +00:00
|
|
|
export const RoyaltyDetails = ({ onChange }: RoyaltyDetailsProps) => {
|
2023-01-12 10:01:11 +00:00
|
|
|
const wallet = useWallet()
|
2022-08-05 11:13:27 +00:00
|
|
|
const [royaltyState, setRoyaltyState] = useState<RoyaltyState>('none')
|
|
|
|
|
2022-08-04 09:16:42 +00:00
|
|
|
const royaltyPaymentAddressState = useInputState({
|
|
|
|
id: 'royalty-payment-address',
|
|
|
|
name: 'royaltyPaymentAddress',
|
|
|
|
title: 'Payment Address',
|
|
|
|
subtitle: 'Address to receive royalties',
|
|
|
|
placeholder: 'stars1234567890abcdefghijklmnopqrstuvwxyz...',
|
|
|
|
})
|
|
|
|
|
2022-09-01 06:27:23 +00:00
|
|
|
const royaltyShareState = useInputState({
|
2022-08-04 09:16:42 +00:00
|
|
|
id: 'royalty-share',
|
|
|
|
name: 'royaltyShare',
|
|
|
|
title: 'Share Percentage',
|
|
|
|
subtitle: 'Percentage of royalties to be paid',
|
2022-09-01 06:27:23 +00:00
|
|
|
placeholder: '8%',
|
2022-08-04 09:16:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-01-12 10:01:11 +00:00
|
|
|
void resolveAddress(
|
|
|
|
royaltyPaymentAddressState.value
|
2022-11-18 16:54:02 +00:00
|
|
|
.toLowerCase()
|
|
|
|
.replace(/,/g, '')
|
|
|
|
.replace(/"/g, '')
|
|
|
|
.replace(/'/g, '')
|
|
|
|
.replace(/ /g, ''),
|
2023-01-12 10:01:11 +00:00
|
|
|
wallet,
|
|
|
|
).then((royaltyPaymentAddress) => {
|
|
|
|
royaltyPaymentAddressState.onChange(royaltyPaymentAddress)
|
|
|
|
const data: RoyaltyDetailsDataProps = {
|
|
|
|
royaltyType: royaltyState,
|
|
|
|
paymentAddress: royaltyPaymentAddressState.value,
|
|
|
|
share: Number(royaltyShareState.value),
|
|
|
|
}
|
|
|
|
onChange(data)
|
|
|
|
})
|
2022-08-04 09:16:42 +00:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2022-08-09 11:42:55 +00:00
|
|
|
}, [royaltyState, royaltyPaymentAddressState.value, royaltyShareState.value])
|
2022-08-04 09:16:42 +00:00
|
|
|
|
|
|
|
return (
|
2022-08-05 11:13:27 +00:00
|
|
|
<div className="py-3 px-8 rounded border-2 border-white/20">
|
|
|
|
<div className="flex justify-center">
|
|
|
|
<div className="ml-4 font-bold form-check form-check-inline">
|
|
|
|
<input
|
|
|
|
checked={royaltyState === 'none'}
|
2022-09-13 05:19:04 +00:00
|
|
|
className="peer sr-only"
|
2022-08-05 11:13:27 +00:00
|
|
|
id="royaltyRadio1"
|
|
|
|
name="royaltyRadioOptions1"
|
|
|
|
onClick={() => {
|
|
|
|
setRoyaltyState('none')
|
|
|
|
}}
|
|
|
|
type="radio"
|
|
|
|
value="None"
|
|
|
|
/>
|
2022-09-13 05:19:04 +00:00
|
|
|
<label
|
2022-09-19 08:14:30 +00:00
|
|
|
className="inline-block py-1 px-2 text-gray peer-checked:text-white hover:text-white peer-checked:bg-black hover:rounded-sm peer-checked:border-b-2 hover:border-b-2 peer-checked:border-plumbus hover:border-plumbus cursor-pointer form-check-label"
|
2022-09-13 05:19:04 +00:00
|
|
|
htmlFor="royaltyRadio1"
|
|
|
|
>
|
2022-08-05 11:13:27 +00:00
|
|
|
No royalty
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div className="ml-4 font-bold form-check form-check-inline">
|
|
|
|
<input
|
|
|
|
checked={royaltyState === 'new'}
|
2022-09-13 05:19:04 +00:00
|
|
|
className="peer sr-only"
|
2022-08-05 11:13:27 +00:00
|
|
|
id="royaltyRadio2"
|
|
|
|
name="royaltyRadioOptions2"
|
|
|
|
onClick={() => {
|
|
|
|
setRoyaltyState('new')
|
|
|
|
}}
|
|
|
|
type="radio"
|
|
|
|
value="Existing"
|
|
|
|
/>
|
2022-09-13 05:19:04 +00:00
|
|
|
<label
|
2022-09-19 08:14:30 +00:00
|
|
|
className="inline-block py-1 px-2 text-gray peer-checked:text-white hover:text-white peer-checked:bg-black hover:rounded-sm peer-checked:border-b-2 hover:border-b-2 peer-checked:border-plumbus hover:border-plumbus cursor-pointer form-check-label"
|
2022-09-13 05:19:04 +00:00
|
|
|
htmlFor="royaltyRadio2"
|
|
|
|
>
|
2022-08-09 11:42:55 +00:00
|
|
|
Configure royalty details
|
2022-08-05 11:13:27 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Conditional test={royaltyState === 'new'}>
|
|
|
|
<FormGroup subtitle="Information about royalty" title="Royalty Details">
|
2022-09-01 06:27:23 +00:00
|
|
|
<TextInput {...royaltyPaymentAddressState} isRequired />
|
|
|
|
<NumberInput {...royaltyShareState} isRequired />
|
2022-08-05 11:13:27 +00:00
|
|
|
</FormGroup>
|
|
|
|
</Conditional>
|
2022-08-04 09:16:42 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|