Skip to content

Commit

Permalink
Merge pull request #1090 from near-daos/fix/external-proposal-create-…
Browse files Browse the repository at this point in the history
…update

fix(create proposal external): fix groups and accounts parse, add mis…
  • Loading branch information
karpovdmitryod authored May 18, 2022
2 parents b05459d + 742f00a commit f190289
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
border-radius: 50%;
height: 24px;
margin-right: 8px;
overflow: hidden;
width: 24px;
}
}
Expand Down Expand Up @@ -55,6 +56,7 @@

button {
border: 0;
margin-top: 8px;
overflow: hidden;
}

Expand Down Expand Up @@ -91,8 +93,9 @@
}

.loaderWrapper {
align-items: flex-end;
align-items: center;
display: flex;
margin-top: 24px;
padding: 8px;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const AddBountyContent: FC = () => {
),
}));

const selectedTokenData = tokens[getValues().selectedToken];
const selectedTokenData = tokens[getValues().token];

const onTokenChange = useCallback(
v => {
Expand Down Expand Up @@ -89,7 +89,9 @@ export const AddBountyContent: FC = () => {
label=" "
{...register('token')}
onChange={onTokenChange}
defaultValue={selectedTokenData?.symbol ?? 'NEAR'}
defaultValue={
selectedTokenData?.symbol ?? getValues().token ?? 'NEAR'
}
/>
) : (
<div className={styles.loaderWrapper}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface AddMemberToGroupContentProps {
export const AddMemberToGroupContent: FC<AddMemberToGroupContentProps> = ({
groups,
}) => {
const { register, setValue, watch } = useFormContext();
const { register, setValue, getValues, watch } = useFormContext();
const { t } = useTranslation();

const currentValue = watch('memberName');
Expand All @@ -39,6 +39,7 @@ export const AddMemberToGroupContent: FC<AddMemberToGroupContentProps> = ({
<DropdownSelect
{...register('group')}
onChange={onChange}
defaultValue={getValues().group}
reverseMenu
isBorderless
options={groups.map(group => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const formContextMock = {
setValue: () => 0,
register: () => 0,
watch: () => '',
getValues: () => ({
group: 'Gr1',
}),
};

jest.mock('react-hook-form', () => {
Expand Down Expand Up @@ -45,7 +48,7 @@ describe('AddMemberToGroupContent', () => {
<AddMemberToGroupContent groups={['Gr1', 'Gr2']} />
);

fireEvent.click(getByText('proposalCard.chooseGroup'));
fireEvent.click(getByText('Gr1'));
fireEvent.click(getByText('Gr2'));

jest.runAllTimers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const ChangeLinksContent: FC<ChangeLinksContentProps> = ({ daoId }) => {
<Input
isBorderless
{...register(`links.${index}.url`)}
defaultValue={currentUrl}
onKeyUp={async () => {
await trigger();
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ChangeDaoNameContentProps {
export const RemoveMemberFromGroupContent: FC<ChangeDaoNameContentProps> = ({
groups,
}) => {
const { register, setValue } = useFormContext();
const { register, setValue, getValues } = useFormContext();
const { t } = useTranslation();

return (
Expand All @@ -31,6 +31,7 @@ export const RemoveMemberFromGroupContent: FC<ChangeDaoNameContentProps> = ({
shouldValidate: true,
});
}}
defaultValue={getValues().group}
isBorderless
options={groups.map(group => ({
label: group,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const formContextMock = {
touchedFields: {},
},
register: () => 0,
getValues: () => ({
group: 'GR1',
}),
};

jest.mock('react-hook-form', () => {
Expand Down Expand Up @@ -45,7 +48,7 @@ describe('RemoveMemberFromGroupContent', () => {
<RemoveMemberFromGroupContent groups={['GR1', 'GR2']} />
);

fireEvent.click(getByText('proposalCard.chooseGroup'));
fireEvent.click(getByText('GR1'));
fireEvent.click(getByText('GR2'));

jest.runAllTimers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
border-radius: 50%;
height: 24px;
margin-right: 8px;
overflow: hidden;
width: 24px;
}
}
Expand Down Expand Up @@ -62,6 +63,7 @@

button {
border: 0;
margin-top: 4px;
overflow: hidden;
}

Expand Down Expand Up @@ -115,8 +117,9 @@
}

.loaderWrapper {
align-items: flex-end;
align-items: center;
display: flex;
margin-top: 24px;
padding: 8px;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const TransferContent: FC = () => {
),
}));

const selectedTokenData = tokens[getValues().selectedToken];
const selectedTokenData = tokens[getValues().token];

return (
<div className={styles.root}>
Expand Down Expand Up @@ -98,7 +98,9 @@ export const TransferContent: FC = () => {
shouldDirty: true,
});
}}
defaultValue={selectedTokenData?.symbol ?? 'NEAR'}
defaultValue={
selectedTokenData?.symbol ?? getValues().token ?? 'NEAR'
}
/>
) : (
<div className={styles.loaderWrapper}>
Expand Down
6 changes: 5 additions & 1 deletion astro_2.0/features/CreateProposal/helpers/initialValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ export function getFormInitialValues(
};
}
case ProposalVariant.ProposeChangeDaoLinks: {
const initial = initialValues as { links?: string[] };

const links = initial ? initial?.links?.map(item => ({ url: item })) : [];

return {
details: '',
externalUrl: '',
links: [],
gas: DEFAULT_PROPOSAL_GAS,
...initialValues,
links,
};
}
case ProposalVariant.ProposeCreateToken: {
Expand Down
7 changes: 1 addition & 6 deletions components/inputs/selects/DropdownSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import cn from 'classnames';
import { useSelect } from 'downshift';
import React, { ReactNode, useEffect } from 'react';
import { useTranslation } from 'next-i18next';

import { Icon } from 'components/Icon';

Expand Down Expand Up @@ -75,8 +74,6 @@ export const DropdownSelect = React.forwardRef<
}
}, [defaultValue, options, selectItem, selectedItem]);

const { t } = useTranslation();

return (
<div className={cn(styles.root, className)}>
{label && (
Expand All @@ -96,9 +93,7 @@ export const DropdownSelect = React.forwardRef<
<div className={styles.container}>
<div className={styles.selected}>
{selectedItem?.component ?? (
<div className={styles.placeholder}>
{placeholder || t('proposalCard.chooseGroup')}
</div>
<div className={styles.placeholder}>{placeholder || ''}</div>
)}
</div>
{controlIcon || (
Expand Down
7 changes: 7 additions & 0 deletions pages/api/createProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ export default function handler(
'https://dev.app.astrodao.com/dao/aviarium.sputnikv2.testnet/proposals?action=create_proposal&variant=ProposeCustomFunctionCall&params={"details":"Proposal description here", "methodName": "create", "smartContractAddress": "sputnikv2.testnet", "json":{ "key": "some value" }}',
action: 'create_proposal',
variant: {
ProposeChangeDaoLegalInfo: {
details: '',
externalUrl: '',
legalStatus: '',
legalLink: '',
gas: '',
},
ProposeAddMember: {
details: '',
externalUrl: '',
Expand Down

0 comments on commit f190289

Please sign in to comment.