Skip to content

Commit dbe71f4

Browse files
committed
use selectors for token ids
1 parent 9b26ae6 commit dbe71f4

24 files changed

Lines changed: 520 additions & 215 deletions

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
### [0.11.2](https://github.com/xdevguild/buildo.dev/releases/tag/v0.11.2) (2023-12-31)
1+
### [0.12.0](https://github.com/xdevguild/buildo.dev/releases/tag/v0.12.0) (2024-01-01)
22
- improve roles and properties selectors to make them less confusing
3+
- use tokenId selectors for fungible ids and collections
34

45
### [0.11.1](https://github.com/xdevguild/buildo.dev/releases/tag/v0.11.1) (2023-12-29)
56
- update dependencies (some improvements in useElven)

app/page.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const Home: NextPage = () => {
99
<h1 className="text-2xl md:text-4xl lg:text-6xl font-black text-center mb-8 max-w-2xl lg:max-w-4xl m-auto">
1010
Buildo is your companion through the MultiversX!
1111
</h1>
12-
<h2 className="text-sm md:text-xl lg:text-2xl font-light text-center max-w-2xl lg:max-w-4xl m-auto mb-8">
12+
<h2 className="text-sm md:text-xl lg:text-2xl font-light text-center max-w-2xl lg:max-w-4xl m-auto sm:mb-8">
1313
Buildo.dev is a{' '}
1414
<a
1515
href="https://multiversx.com"
@@ -21,7 +21,7 @@ const Home: NextPage = () => {
2121
app that helps with blockchain interactions, like issuing tokens and
2222
querying smart contracts.
2323
</h2>
24-
<h3 className="text-xs md:text-lg font-extralight m-auto max-w-2xl lg:max-w-4xl text-center">
24+
<h3 className="hidden sm:block text-xs md:text-sm font-extralight m-auto max-w-2xl lg:max-w-4xl text-center">
2525
If you like to work with CLI tools, check the{' '}
2626
<a
2727
href="https://github.com/xdevguild/buildo-begins"
@@ -30,16 +30,24 @@ const Home: NextPage = () => {
3030
>
3131
Buildo Begins
3232
</a>{' '}
33-
CLI!
34-
<br />
35-
Check the{' '}
33+
CLI! Check the{' '}
3634
<a
3735
href="https://chat.openai.com/g/g-GN0Zq0iZP-buildo-expert"
3836
target="_blank"
3937
className="underline"
4038
>
4139
Buildo Expert GPT Assistant
4240
</a>
41+
<br />
42+
Remember that there are different{' '}
43+
<a
44+
className="underline"
45+
href="https://github.com/multiversx/mx-api-service/blob/main/src/utils/cache.info.ts"
46+
target="_blank"
47+
>
48+
cache strategies for API
49+
</a>
50+
, so not all changes will be visible immediately.
4351
</h3>
4452
<OperationsAuthCheck />
4553
</div>

components/home-cards.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,6 @@ export const HomeCards = () => {
170170
onClick: () => {},
171171
disabled: true,
172172
},
173-
{
174-
title: 'Guardians related operations',
175-
description: 'Set/unset a guardian, guard an account',
176-
onClick: () => {},
177-
disabled: true,
178-
},
179173
]}
180174
/>
181175
<HomeCard
@@ -218,6 +212,12 @@ export const HomeCards = () => {
218212
setDialogState('utilities', 'verifySignature');
219213
},
220214
},
215+
{
216+
title: 'Hash functions',
217+
description: 'Hash data using different hash functions',
218+
onClick: () => {},
219+
disabled: true,
220+
},
221221
{
222222
title: 'Read account storage',
223223
description: 'Check account storage by key',

components/operations/common/change-properties.tsx

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ContractCallPayloadBuilder,
66
ContractFunction,
77
} from '@multiversx/sdk-core';
8-
import { useForm } from 'react-hook-form';
8+
import { useForm, useWatch } from 'react-hook-form';
99
import { zodResolver } from '@hookform/resolvers/zod';
1010
import { Form } from '@/components/ui/form';
1111
import {
@@ -21,18 +21,23 @@ import {
2121
builtInSC,
2222
TokenPropertyOrRole,
2323
} from '@/components/operations/constants';
24-
import { OperationsInputField } from '@/components/operations/operations-input-field';
2524
import { OperationsCheckboxGroup } from '@/components/operations/operations-checkbox-group';
2625
import { OperationsSubmitButton } from '@/components/operations/operations-submit-button';
27-
import { useContext } from 'react';
26+
import { useContext, useEffect } from 'react';
2827
import { OperationsStateDialogContext } from '@/components/operations/operations-status-dialog';
2928
import { CommonOpertationContentProps } from '@/components/operations/operations-common-types';
29+
import { OperationsSelectField } from '@/components/operations/operations-select-field';
30+
import { useCreatorTokens } from '@/hooks/use-creator-tokens';
3031

3132
const formSchema = z.object({
3233
tokenId: z.string().min(1, 'The field is required'),
3334
properties: z.array(z.string()),
3435
});
3536

37+
type CreatorTokens = {
38+
ticker: string;
39+
};
40+
3641
const propertiesMap: Record<
3742
CommonOpertationContentProps['tokenType'],
3843
TokenPropertyOrRole[]
@@ -52,14 +57,20 @@ export const ChangeProperties = ({
5257
OperationsStateDialogContext
5358
);
5459

60+
const { tokens } = useCreatorTokens<CreatorTokens>({
61+
tokenType,
62+
});
63+
5564
const form = useForm<z.infer<typeof formSchema>>({
5665
resolver: zodResolver(formSchema),
5766
defaultValues: {
5867
tokenId: '',
59-
properties: propertiesMap[tokenType].map((property) => property.name),
68+
properties: [],
6069
},
6170
});
6271

72+
const watchTokenId = useWatch({ control: form.control, name: 'tokenId' });
73+
6374
const onSubmit = ({ tokenId, properties }: z.infer<typeof formSchema>) => {
6475
const args: TypedValue[] = [BytesValue.fromUTF8(tokenId.trim())];
6576

@@ -91,6 +102,21 @@ export const ChangeProperties = ({
91102
close();
92103
};
93104

105+
useEffect(() => {
106+
const tokenData = tokens?.find((token) => token.ticker === watchTokenId);
107+
if (tokenData) {
108+
const properties = propertiesMap[tokenType].filter((property) => {
109+
const key = property.name as keyof typeof tokenData;
110+
return tokenData[key];
111+
});
112+
form.setValue(
113+
'properties',
114+
properties.map((property) => property.name)
115+
);
116+
}
117+
// eslint-disable-next-line react-hooks/exhaustive-deps
118+
}, [tokenType, tokens, watchTokenId]);
119+
94120
return (
95121
<>
96122
<DialogHeader className="p-8 pb-0">
@@ -109,11 +135,18 @@ export const ChangeProperties = ({
109135
className="space-y-8"
110136
>
111137
<div className="flex-1 overflow-auto p-1">
112-
<OperationsInputField
138+
<OperationsSelectField
113139
name="tokenId"
114140
label="Token id"
115-
placeholder="Example: MyToken-23432"
116141
description="Please provide your token id"
142+
options={
143+
tokens
144+
? tokens?.map((token) => ({
145+
value: token.ticker,
146+
label: token.ticker,
147+
}))
148+
: []
149+
}
117150
/>
118151
<OperationsCheckboxGroup
119152
items={propertiesMap[tokenType]}

components/operations/common/stop-creation.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@ import {
1818
commonOpertationsGasLimit,
1919
builtInSC,
2020
} from '@/components/operations/constants';
21-
import { OperationsInputField } from '@/components/operations/operations-input-field';
2221
import { OperationsSubmitButton } from '@/components/operations/operations-submit-button';
2322
import { useContext } from 'react';
2423
import { OperationsStateDialogContext } from '@/components/operations/operations-status-dialog';
25-
import { OperationContentProps } from '@/components/operations/operations-common-types';
24+
import { CommonOpertationContentProps } from '@/components/operations/operations-common-types';
25+
import { OperationsTokenIdInput } from '../operations-tokenid-input';
2626

2727
const formSchema = z.object({
2828
tokenId: z.string().min(1, 'The field is required!'),
2929
});
3030

31-
export const StopCreation = ({ triggerTx, close }: OperationContentProps) => {
31+
export const StopCreation = ({
32+
triggerTx,
33+
close,
34+
tokenType,
35+
}: CommonOpertationContentProps) => {
3236
const { setOpen: setTxStatusDialogOpen } = useContext(
3337
OperationsStateDialogContext
3438
);
@@ -77,12 +81,7 @@ export const StopCreation = ({ triggerTx, close }: OperationContentProps) => {
7781
className="space-y-8"
7882
>
7983
<div className="flex-1 overflow-auto p-1">
80-
<OperationsInputField
81-
name="tokenId"
82-
label="Token id"
83-
placeholder="Example: MyToken-23432"
84-
description="Please provide your token id"
85-
/>
84+
<OperationsTokenIdInput tokenType={tokenType} />
8685
</div>
8786
</form>
8887
</Form>

components/operations/common/toggle-special-roles.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ import { useContext, useEffect, useState } from 'react';
3232
import { OperationsStateDialogContext } from '@/components/operations/operations-status-dialog';
3333
import { CommonOpertationContentProps } from '@/components/operations/operations-common-types';
3434
import { OperationsRadioGroup } from '@/components/operations/operations-radio-group';
35-
import { useCreatorTokens } from '@/hooks/use-creator-tokens';
36-
import { OperationsSelectField } from '@/components/operations/operations-select-field';
3735
import { useAccount } from '@useelven/core';
3836
import { useTokenRolesByAccount } from '@/hooks/use-token-roles-by-account';
37+
import { OperationsTokenIdInput } from '@/components/operations/operations-tokenid-input';
3938

4039
const formSchema = z.object({
4140
tokenId: z.string().min(1, 'The field is required'),
@@ -68,8 +67,6 @@ export const ToggleSpecialRoles = ({
6867

6968
const [disabledRoles, setDisabledRoles] = useState<string[]>();
7069

71-
const { tokens } = useCreatorTokens<{ ticker: string }>({ tokenType });
72-
7370
const form = useForm<z.infer<typeof formSchema>>({
7471
resolver: zodResolver(formSchema),
7572
defaultValues: {
@@ -186,19 +183,7 @@ export const ToggleSpecialRoles = ({
186183
label="Operation type"
187184
description="Please choose the type of the operation. Set or Unset."
188185
/>
189-
<OperationsSelectField
190-
name="tokenId"
191-
label="Token id"
192-
description="Example: MyToken-23432"
193-
options={
194-
tokens
195-
? tokens?.map((token) => ({
196-
value: token.ticker,
197-
label: token.ticker,
198-
}))
199-
: []
200-
}
201-
/>
186+
<OperationsTokenIdInput tokenType={tokenType} />
202187
<OperationsInputField
203188
name="address"
204189
label="Address"

components/operations/common/transfer-creation-role.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import { OperationsInputField } from '@/components/operations/operations-input-f
2424
import { OperationsSubmitButton } from '@/components/operations/operations-submit-button';
2525
import { useContext } from 'react';
2626
import { OperationsStateDialogContext } from '@/components/operations/operations-status-dialog';
27-
import { OperationContentProps } from '@/components/operations/operations-common-types';
27+
import { CommonOpertationContentProps } from '@/components/operations/operations-common-types';
28+
import { OperationsTokenIdInput } from '../operations-tokenid-input';
2829

2930
const formSchema = z.object({
3031
addressWithRole: z.string().min(1, 'The field is required'),
@@ -35,7 +36,8 @@ const formSchema = z.object({
3536
export const TransferCreationRole = ({
3637
triggerTx,
3738
close,
38-
}: OperationContentProps) => {
39+
tokenType,
40+
}: CommonOpertationContentProps) => {
3941
const { setOpen: setTxStatusDialogOpen } = useContext(
4042
OperationsStateDialogContext
4143
);
@@ -95,12 +97,7 @@ export const TransferCreationRole = ({
9597
className="space-y-8"
9698
>
9799
<div className="flex-1 overflow-auto p-1">
98-
<OperationsInputField
99-
name="tokenId"
100-
label="Token id"
101-
placeholder="Example: MyToken-23432"
102-
description="Please provide your token id"
103-
/>
100+
<OperationsTokenIdInput tokenType={tokenType} />
104101
<OperationsInputField
105102
name="addressWithRole"
106103
label="Current address with create role"

components/operations/common/transfer-ownership.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import { OperationsInputField } from '@/components/operations/operations-input-f
2525
import { OperationsSubmitButton } from '../operations-submit-button';
2626
import { useContext } from 'react';
2727
import { OperationsStateDialogContext } from '@/components/operations/operations-status-dialog';
28-
import { OperationContentProps } from '@/components/operations/operations-common-types';
28+
import { CommonOpertationContentProps } from '@/components/operations/operations-common-types';
29+
import { OperationsTokenIdInput } from '@/components/operations/operations-tokenid-input';
2930

3031
const formSchema = z.object({
3132
tokenId: z.string().min(1, 'The field is required'),
@@ -35,7 +36,8 @@ const formSchema = z.object({
3536
export const TransferOwnership = ({
3637
triggerTx,
3738
close,
38-
}: OperationContentProps) => {
39+
tokenType,
40+
}: CommonOpertationContentProps) => {
3941
const { setOpen: setTxStatusDialogOpen } = useContext(
4042
OperationsStateDialogContext
4143
);
@@ -93,12 +95,7 @@ export const TransferOwnership = ({
9395
className="space-y-8"
9496
>
9597
<div className="flex-1 overflow-auto p-1">
96-
<OperationsInputField
97-
name="tokenId"
98-
label="Token id"
99-
placeholder="Example: MyToken-23432"
100-
description="Please provide your token id"
101-
/>
98+
<OperationsTokenIdInput tokenType={tokenType} />
10299
<OperationsInputField
103100
name="address"
104101
label="Address"

components/operations/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const esdtTokenProperties: TokenPropertyOrRole[] = [
5858
export const sftNftTokenProperties: TokenPropertyOrRole[] = [
5959
...esdtTokenProperties,
6060
{
61-
name: 'canTransferNFTCreateRole',
61+
name: 'canTransferNftCreateRole',
6262
description: 'The token manager can transfer NFT/SFT/Meta creation role',
6363
},
6464
];

components/operations/fungible-tokens/freeze-unfreeze.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import {
2222
commonOpertationsGasLimit,
2323
} from '@/components/operations/constants';
2424
import { OperationsInputField } from '@/components/operations/operations-input-field';
25-
import { OperationsSubmitButton } from '../operations-submit-button';
25+
import { OperationsSubmitButton } from '@/components/operations/operations-submit-button';
2626
import { useContext } from 'react';
2727
import { OperationsStateDialogContext } from '@/components/operations/operations-status-dialog';
2828
import { OperationContentProps } from '@/components/operations/operations-common-types';
29-
import { OperationsRadioGroup } from '../operations-radio-group';
29+
import { OperationsRadioGroup } from '@/components/operations/operations-radio-group';
30+
import { OperationsTokenIdInput } from '@/components/operations/operations-tokenid-input';
3031

3132
const formSchema = z.object({
3233
tokenId: z.string().min(1, 'The field is required'),
@@ -106,12 +107,7 @@ export const FreezeUnfreeze = ({ triggerTx, close }: OperationContentProps) => {
106107
label="Operation type"
107108
description="Please choose the type of the operation. Freeze or Unfreeze."
108109
/>
109-
<OperationsInputField
110-
name="tokenId"
111-
label="Token id"
112-
placeholder="Example: MyToken-23432"
113-
description="Please provide your token id"
114-
/>
110+
<OperationsTokenIdInput tokenType="fungible" />
115111
<OperationsInputField
116112
name="address"
117113
label="Address"

0 commit comments

Comments
 (0)