Skip to content

Commit

Permalink
add fractional token check
Browse files Browse the repository at this point in the history
  • Loading branch information
NickJ202 committed Jan 16, 2024
1 parent 18cb0e5 commit a7180b0
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 23 deletions.
5 changes: 3 additions & 2 deletions src/helpers/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ export const language = {
comment: `Comment`,
comments: `Comments`,
community: `Community`,
contentTokens: `Content tokens`,
contentTokensInfo: `This balance will be assigned to each newly created asset.`,
contentTokens: `Fractional tokens`,
contentTokensInfo: `Atomic assets can be fractionalized by inputting a number greater than one. This enables multiple users to own fractions of the same atomic asset.`,
contentTokensCheckInfo: `These assets will use fractionalized tokens`,
conversion: `Conversion`,
connect: `Connect`,
connectToContinue: `Connect your wallet to continue`,
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export type UploadPayloadType =
| 'description'
| 'collectionCode'
| 'contentTokens'
| 'useFractionalTokens'
| 'topics'
| 'content'
| 'contentList'
Expand All @@ -200,6 +201,8 @@ export type UploadReduxType = {
title: string;
description: string;
collectionCode: string;
contentTokens: number;
useFractionalTokens: boolean;
thumbnail: any;
topics: string[];
type: string;
Expand Down
3 changes: 3 additions & 0 deletions src/store/upload/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const initStateUploadReducer = {
description: '',
collectionCode: '',
contentTokens: 100,
useFractionalTokens: true,
banner: null,
thumbnail: null,
topics: [],
Expand Down Expand Up @@ -84,6 +85,7 @@ export function uploadReducer(state: UploadReduxType = initStateUploadReducer, a
description: '',
collectionCode: '',
contentTokens: 100,
useFractionalTokens: true,
banner: null,
thumbnail: null,
topics: [],
Expand All @@ -110,6 +112,7 @@ export function uploadReducer(state: UploadReduxType = initStateUploadReducer, a
description: '',
collectionCode: '',
contentTokens: 100,
useFractionalTokens: true,
banner: null,
thumbnail: null,
topics: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ReactSVG } from 'react-svg';
import { checkDuplicateTitle } from 'gql';

import { Button } from 'components/atoms/Button';
import { Checkbox } from 'components/atoms/Checkbox';
import { FormField } from 'components/atoms/FormField';
import { TextArea } from 'components/atoms/TextArea';
import { Modal } from 'components/molecules/Modal';
Expand Down Expand Up @@ -103,6 +104,17 @@ export default function UploadStepsDetails() {
);
}

function handleUseFractionalChange() {
dispatch(
uploadActions.setUpload([
{
field: 'useFractionalTokens',
data: !uploadReducer.data.useFractionalTokens,
},
])
);
}

function handleTopicChange(topic: string) {
let topics = [...uploadReducer.data.topics];
if (topics.includes(topic)) {
Expand Down Expand Up @@ -184,16 +196,29 @@ export default function UploadStepsDetails() {
/>
</>
)}
<FormField
type={'number'}
label={language.contentTokens}
value={uploadReducer.data.contentTokens}
onChange={(e: any) => handleInputChange(e, 'contentTokens')}
disabled={false}
invalid={getInvalidContentTokens()}
tooltip={language.contentTokensInfo}
required
/>
<S.COWrapper className={'border-wrapper-alt1'}>
<S.CWrapper>
<span>{language.contentTokensCheckInfo}</span>
<Checkbox
checked={uploadReducer.data.useFractionalTokens}
handleSelect={handleUseFractionalChange}
disabled={false}
/>
</S.CWrapper>
{uploadReducer.data.useFractionalTokens && (
<FormField
type={'number'}
label={language.contentTokens}
value={uploadReducer.data.useFractionalTokens ? uploadReducer.data.contentTokens : 1}
onChange={(e: any) => handleInputChange(e, 'contentTokens')}
disabled={!uploadReducer.data.useFractionalTokens}
invalid={getInvalidContentTokens()}
tooltip={language.contentTokensInfo}
required
hideErrorMessage
/>
)}
</S.COWrapper>
{uploadReducer.uploadType === 'collection' && (
<FormField
label={language.collectionCode}
Expand Down
18 changes: 18 additions & 0 deletions src/views/Upload/UploadSteps/UploadStepsDetails/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ export const Wrapper = styled.div`
}
`;

export const COWrapper = styled.div`
padding: 15px;
margin: 0 0 25px 0;
border: none;
`;

export const CWrapper = styled.div`
display: flex;
align-items: center;
span {
color: ${(props) => props.theme.colors.font.primary};
font-size: ${(props) => props.theme.typography.size.xSmall};
font-weight: ${(props) => props.theme.typography.weight.bold};
display: block;
margin: 0 5px 0 0;
}
`;

export const TWrapper = styled.div``;

export const THeader = styled.div`
Expand Down
24 changes: 13 additions & 11 deletions src/views/Upload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,19 @@ export default function Upload() {
const [collectionResponse, setCollectionResponse] = React.useState<string | null>(null);
const [collectionResponseError, setCollectionResponseError] = React.useState<string | null>(null);

React.useEffect(() => {
const handleBeforeUnload = (e: any) => {
e.preventDefault();
e.returnValue = '';
};
// TODO: add
// React.useEffect(() => {
// const handleBeforeUnload = (e: any) => {
// e.preventDefault();
// e.returnValue = '';
// };

window.addEventListener('beforeunload', handleBeforeUnload);
// window.addEventListener('beforeunload', handleBeforeUnload);

return () => {
window.removeEventListener('beforeunload', handleBeforeUnload);
};
}, [uploadReducer]);
// return () => {
// window.removeEventListener('beforeunload', handleBeforeUnload);
// };
// }, [uploadReducer]);

React.useEffect(() => {
if (!arProvider.wallet) dispatch(uploadActions.setUploadDisabled(true));
Expand Down Expand Up @@ -219,11 +220,12 @@ export default function Upload() {
? uploadReducer.data.description
: data.file.name;
const type = data.file.type;
const balance = uploadReducer.data.useFractionalTokens ? Number(uploadReducer.data.contentTokens) : 1;

try {
let initStateAssetJson: any = {
balances: {
[arProvider.walletAddress]: Number(uploadReducer.data.contentTokens),
[arProvider.walletAddress]: balance,
},
title: title,
description: description,
Expand Down

0 comments on commit a7180b0

Please sign in to comment.