Skip to content

Commit a855e45

Browse files
michaeldev5dudo50
authored andcommitted
feat: Add support for transact XCM instruction 🪄
1 parent 9b008d5 commit a855e45

File tree

122 files changed

+2745
-1426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+2745
-1426
lines changed

‎apps/playground/src/components/AssetClaim/AssetClaimForm.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { type FC, useEffect } from 'react';
66

77
import { DEFAULT_ADDRESS, MAIN_FORM_NAME } from '../../constants';
88
import { useWallet } from '../../hooks';
9-
import { advancedOptionsParsers } from '../../parsers/advancedOptions';
9+
import { advancedOptionsParsers } from '../../parsers';
1010
import type { TAdvancedOptions } from '../../types';
1111
import { isValidWalletAddress, validateCustomEndpoint } from '../../utils';
1212
import {
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import {
2+
ActionIcon,
3+
Button,
4+
Fieldset,
5+
Group,
6+
NumberInput,
7+
Select,
8+
Stack,
9+
TextInput,
10+
useMantineColorScheme,
11+
} from '@mantine/core';
12+
import { createFormActions, type UseFormReturnType } from '@mantine/form';
13+
import { useDisclosure } from '@mantine/hooks';
14+
import { TRANSACT_ORIGINS } from '@paraspell/sdk';
15+
import { IconPlus, IconTrash } from '@tabler/icons-react';
16+
17+
import { DEFAULT_TRANSACT_OPTIONS, MAIN_FORM_NAME } from '../../constants';
18+
import type { TTransactFields } from '../../types';
19+
20+
const formActions = createFormActions<TTransactFields>(MAIN_FORM_NAME);
21+
22+
type Props<T extends TTransactFields> = {
23+
form: UseFormReturnType<T>;
24+
};
25+
26+
export const Transact = <T extends TTransactFields>({ form }: Props<T>) => {
27+
const { colorScheme } = useMantineColorScheme();
28+
29+
const [opened, { open, close }] = useDisclosure(
30+
form.values.transactOptions.call !== '',
31+
);
32+
33+
const onRemove = () => {
34+
formActions.setFieldValue('transactOptions', DEFAULT_TRANSACT_OPTIONS);
35+
close();
36+
};
37+
38+
const ensureMaxWeight = () => {
39+
if (!form.values.transactOptions.maxWeight) {
40+
formActions.setFieldValue('transactOptions.maxWeight', {
41+
refTime: 0,
42+
proofSize: 0,
43+
});
44+
}
45+
};
46+
47+
const refTimeProps = form.getInputProps('transactOptions.maxWeight.refTime');
48+
const proofSizeProps = form.getInputProps(
49+
'transactOptions.maxWeight.proofSize',
50+
);
51+
52+
return (
53+
<Stack gap="md" py={opened ? 'sm' : '0'}>
54+
{!opened && (
55+
<Button
56+
variant="transparent"
57+
size="compact-xs"
58+
leftSection={<IconPlus size={16} />}
59+
onClick={open}
60+
>
61+
Add Transact
62+
</Button>
63+
)}
64+
{opened && (
65+
<Fieldset legend="Transact" pos="relative">
66+
<Group>
67+
<Stack>
68+
<TextInput
69+
label="Call"
70+
description="Hex-encoded call data"
71+
placeholder="Enter hex"
72+
data-testid="transact-call-input"
73+
{...form.getInputProps('transactOptions.call')}
74+
/>
75+
<Select
76+
label="Origin Kind"
77+
data={TRANSACT_ORIGINS}
78+
data-testid="transact-origin-select"
79+
{...form.getInputProps('transactOptions.originKind')}
80+
/>
81+
<Group>
82+
<NumberInput
83+
flex={1}
84+
label="Ref Time"
85+
placeholder="Enter number"
86+
min={0}
87+
data-testid="transact-ref-time-input"
88+
{...form.getInputProps('transactOptions.maxWeight.refTime')}
89+
onFocus={(e) => {
90+
ensureMaxWeight();
91+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
92+
refTimeProps.onFocus?.(e);
93+
}}
94+
/>
95+
<NumberInput
96+
flex={1}
97+
label="Proof Size"
98+
placeholder="Enter number"
99+
min={0}
100+
data-testid="transact-proof-size-input"
101+
{...form.getInputProps('transactOptions.maxWeight.proofSize')}
102+
onFocus={(e) => {
103+
ensureMaxWeight();
104+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
105+
proofSizeProps.onFocus?.(e);
106+
}}
107+
/>
108+
</Group>
109+
</Stack>
110+
<ActionIcon
111+
color="red"
112+
variant="subtle"
113+
bg={colorScheme === 'light' ? 'white' : 'dark.7'}
114+
pos="absolute"
115+
right={20}
116+
top={-25}
117+
onClick={onRemove}
118+
>
119+
<IconTrash size={16} />
120+
</ActionIcon>
121+
</Group>
122+
</Fieldset>
123+
)}
124+
</Stack>
125+
);
126+
};

‎apps/playground/src/components/XcmRouter/XcmRouterForm.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { useEffect, useState } from 'react';
5050

5151
import { DEFAULT_ADDRESS, MAIN_FORM_NAME } from '../../constants';
5252
import { useRouterCurrencyOptions, useWallet } from '../../hooks';
53-
import { advancedOptionsParsers } from '../../parsers/advancedOptions';
53+
import { advancedOptionsParsers } from '../../parsers';
5454
import type {
5555
TAdvancedOptions,
5656
TRouterSubmitType,

0 commit comments

Comments
 (0)