Skip to content

Commit

Permalink
feat(compose_txn): set manager, freeze, clawback & reserve when recon…
Browse files Browse the repository at this point in the history
…figuring asset

Use the retrieve asset information to automatically set the manager, freeze, clawback and reserve
addresses. This should prevent mistakenly disabling feature of an asset.
  • Loading branch information
No-Cash-7970 committed Dec 27, 2023
1 parent ff00134 commit ce17de5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/app/[lang]/txn/compose/components/ComposeForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,15 @@ describe('Compose Form Component', () => {

// Check if asset name appears
expect(screen.getByText('Foo Token')).toBeInTheDocument();
// TODO: Check if asset addresses have the retrieved values
// Check if asset addresses have the retrieved values
expect(screen.getByLabelText(/fields.apar_m.label/))
.toHaveValue('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
expect(screen.getByLabelText(/fields.apar_f.label/))
.toHaveValue('BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB');
expect(screen.getByLabelText(/fields.apar_c.label/))
.toHaveValue('CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC');
expect(screen.getByLabelText(/fields.apar_r.label/))
.toHaveValue('DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD');
});

it('has fields for asset freeze transaction type if "Asset Freeze" transaction type is selected',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ function UseSenderAddr({ t }: { t: TFunction }) {
export function ClawbackAddrInput({ t }: { t: TFunction }) {
const form = useAtomValue(assetConfigFormControlAtom);
const showFormErrors = useAtomValue(showFormErrorsAtom);
const preset = useSearchParams().get(Preset.ParamName);
const setApar_c = useSetAtom(txnDataAtoms.apar_c);
const retrievedAssetInfo = useAtomValue(txnDataAtoms.retrievedAssetInfo);

useEffect(() => {
if (
preset !== Preset.AssetDestroy && !form.touched.apar_c && retrievedAssetInfo?.value?.clawback
) {
setApar_c(retrievedAssetInfo.value.clawback);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},[retrievedAssetInfo]);

return (<>
<TextField label={t('fields.apar_c.label')}
name='apar_c'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ function UseSenderAddr({ t }: { t: TFunction }) {
export function FreezeAddrInput({ t }: { t: TFunction }) {
const form = useAtomValue(assetConfigFormControlAtom);
const showFormErrors = useAtomValue(showFormErrorsAtom);
const preset = useSearchParams().get(Preset.ParamName);
const setApar_f = useSetAtom(txnDataAtoms.apar_f);
const retrievedAssetInfo = useAtomValue(txnDataAtoms.retrievedAssetInfo);

useEffect(() => {
if (
preset !== Preset.AssetDestroy && !form.touched.apar_f && retrievedAssetInfo?.value?.freeze
) {
setApar_f(retrievedAssetInfo.value.freeze);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},[retrievedAssetInfo]);

return (<>
<TextField label={t('fields.apar_f.label')}
name='apar_f'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ function UseSenderAddr({ t }: { t: TFunction }) {
export function ManagerAddrInput({ t }: { t: TFunction }) {
const form = useAtomValue(assetConfigFormControlAtom);
const showFormErrors = useAtomValue(showFormErrorsAtom);
const preset = useSearchParams().get(Preset.ParamName);
const setApar_m = useSetAtom(txnDataAtoms.apar_m);
const retrievedAssetInfo = useAtomValue(txnDataAtoms.retrievedAssetInfo);

useEffect(() => {
if (
preset !== Preset.AssetDestroy && !form.touched.apar_m && retrievedAssetInfo?.value?.manager
) {
setApar_m(retrievedAssetInfo.value.manager);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},[retrievedAssetInfo]);

return (<>
<TextField label={t('fields.apar_m.label')}
name='apar_m'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ function UseSenderAddr({ t }: { t: TFunction }) {
export function ReserveAddrInput({ t }: { t: TFunction }) {
const form = useAtomValue(assetConfigFormControlAtom);
const showFormErrors = useAtomValue(showFormErrorsAtom);
const preset = useSearchParams().get(Preset.ParamName);
const setApar_r = useSetAtom(txnDataAtoms.apar_r);
const retrievedAssetInfo = useAtomValue(txnDataAtoms.retrievedAssetInfo);

useEffect(() => {
if (
preset !== Preset.AssetDestroy && !form.touched.apar_r && retrievedAssetInfo?.value?.reserve
) {
setApar_r(retrievedAssetInfo.value.reserve);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},[retrievedAssetInfo]);

return (<>
<TextField label={t('fields.apar_r.label')}
name='apar_r'
Expand Down

0 comments on commit ce17de5

Please sign in to comment.