From ce17de5e7e2ed6bf25c5bb86dd220f63cd625ec8 Mon Sep 17 00:00:00 2001 From: No-Cash-7970 Date: Wed, 27 Dec 2023 13:07:54 -0800 Subject: [PATCH] feat(compose_txn): set manager, freeze, clawback & reserve when reconfiguring 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. --- .../txn/compose/components/ComposeForm.test.tsx | 10 +++++++++- .../fields/AssetConfigFields/ClawbackAddr.tsx | 13 +++++++++++++ .../fields/AssetConfigFields/FreezeAddr.tsx | 13 +++++++++++++ .../fields/AssetConfigFields/ManagerAddr.tsx | 13 +++++++++++++ .../fields/AssetConfigFields/ReserveAddr.tsx | 13 +++++++++++++ 5 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/app/[lang]/txn/compose/components/ComposeForm.test.tsx b/src/app/[lang]/txn/compose/components/ComposeForm.test.tsx index 3254ce88..9f4c3bcd 100644 --- a/src/app/[lang]/txn/compose/components/ComposeForm.test.tsx +++ b/src/app/[lang]/txn/compose/components/ComposeForm.test.tsx @@ -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', diff --git a/src/app/[lang]/txn/compose/components/fields/AssetConfigFields/ClawbackAddr.tsx b/src/app/[lang]/txn/compose/components/fields/AssetConfigFields/ClawbackAddr.tsx index 7dac9264..2b2aead4 100644 --- a/src/app/[lang]/txn/compose/components/fields/AssetConfigFields/ClawbackAddr.tsx +++ b/src/app/[lang]/txn/compose/components/fields/AssetConfigFields/ClawbackAddr.tsx @@ -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 (<> { + 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 (<> { + 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 (<> { + 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 (<>