Skip to content

Commit

Permalink
Merge pull request #1087 from near-daos/fix/merge-latest-upgrade-changes
Browse files Browse the repository at this point in the history
Fix/merge latest upgrade changes
  • Loading branch information
karpovdmitryod authored May 18, 2022
2 parents b45fac8 + a62a43d commit 7c58f04
Show file tree
Hide file tree
Showing 33 changed files with 454 additions and 158 deletions.
3 changes: 1 addition & 2 deletions .github/env.qa
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

DEPLOYMENT_NAMESPACE=astro-ui-qa
NEAR_ENV=mainnet
K8S_INGRESS_HOST=qa.app.astrodao.com
API_URL=https://api.qa.app.astrodao.com
NEAR_ENV=mainnet
APP_DOMAIN=qa.app.astrodao.com
NEAR_CONTRACT_NAME=daofactory.near

6 changes: 3 additions & 3 deletions astro_2.0/components/DaoWarning/DaoWarning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ interface DaoWarningProps {
content: ReactNode;
control?: ReactNode;
className?: string;
icon?: IconName;
iconClassName?: string;
statusClassName?: string;
rootClassName?: string;
statusClassName?: string;
iconClassName?: string;
icon?: IconName;
}

export const DaoWarning: FC<DaoWarningProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ import { Button } from 'components/button/Button';

import { GA_EVENTS, sendGAEvent } from 'utils/ga';
import { DAOFormValues } from 'astro_2.0/features/CreateDao/components/types';
import { DEFAULT_VOTE_GAS } from 'services/sputnik/constants';
import {
DEFAULT_UPGRADE_DAO_VOTE_GAS,
DEFAULT_VOTE_GAS,
} from 'services/sputnik/constants';
import { gasValidation } from 'astro_2.0/features/CreateProposal/helpers';
import { useCountdown } from 'hooks/useCountdown';
import { LoadingIndicator } from 'astro_2.0/components/LoadingIndicator';
import { ProposalControlPanel } from './components/ProposalControlPanel';

// import { NOTIFICATION_TYPES, showNotification } from 'features/notifications';

import styles from './ProposalCard.module.scss';

export interface ProposalCardProps {
Expand Down Expand Up @@ -69,6 +71,7 @@ export interface ProposalCardProps {
updatedAt?: string | null;
toggleInfoPanel?: () => void;
commentsCount: number;
optionalPostVoteAction?: () => Promise<void>;
permissions: {
canApprove: boolean;
canReject: boolean;
Expand Down Expand Up @@ -177,6 +180,7 @@ export const ProposalCard: React.FC<ProposalCardProps> = ({
updatedAt,
toggleInfoPanel,
commentsCount,
optionalPostVoteAction,
}) => {
const { accountId, nearService } = useWalletContext();
const { t } = useTranslation();
Expand All @@ -185,7 +189,7 @@ export const ProposalCard: React.FC<ProposalCardProps> = ({
const [{ loading: voteLoading }, voteClickHandler] = useAsyncFn(
async (vote: VoteAction, gas?: string | number) => {
try {
await nearService?.vote(daoId, proposalId, vote, gas);
const res = await nearService?.vote(daoId, proposalId, vote, gas);

sendGAEvent({
name: GA_EVENTS.ACT_PROPOSAL,
Expand All @@ -197,6 +201,20 @@ export const ProposalCard: React.FC<ProposalCardProps> = ({
},
});

// One of the usages - in upgrade dao wizard to auto update steps
if (optionalPostVoteAction) {
if (res && res[0]) {
const successReceipt =
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
res[0]?.transaction_outcome?.outcome?.status?.SuccessReceiptId;

if (successReceipt) {
await optionalPostVoteAction();
}
}
}

await router.reload();
} catch (e) {
// todo - handle errors
Expand Down Expand Up @@ -260,8 +278,9 @@ export const ProposalCard: React.FC<ProposalCardProps> = ({
defaultValues: {
gas:
variant === ProposalVariant.ProposeGetUpgradeCode ||
variant === ProposalVariant.ProposeRemoveUpgradeCode
? 230
variant === ProposalVariant.ProposeRemoveUpgradeCode ||
variant === ProposalVariant.ProposeUpgradeSelf
? DEFAULT_UPGRADE_DAO_VOTE_GAS
: DEFAULT_VOTE_GAS,
},
resolver: yupResolver(schema),
Expand Down Expand Up @@ -432,6 +451,7 @@ export const ProposalCard: React.FC<ProposalCardProps> = ({
<FormProvider {...methods}>
<ProposalControlPanel
status={status}
variant={variant}
onLike={(data, e) => {
e?.stopPropagation();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import cn from 'classnames';
import React, { FC } from 'react';
import { ProposalStatus, ProposalVotingPermissions } from 'types/proposal';
import {
ProposalStatus,
ProposalVariant,
ProposalVotingPermissions,
} from 'types/proposal';
import { SubmitHandler, useFormContext } from 'react-hook-form';
import { kFormatter } from 'utils/format';
import { TgasInput } from 'astro_2.0/components/TgasInput';
Expand All @@ -25,6 +29,7 @@ interface ProposalControlPanelProps {
status?: ProposalStatus;
toggleInfoPanel?: React.MouseEventHandler<HTMLButtonElement>;
commentsCount: number;
variant: ProposalVariant;
}

export const ProposalControlPanel: FC<ProposalControlPanelProps> = ({
Expand All @@ -41,6 +46,7 @@ export const ProposalControlPanel: FC<ProposalControlPanelProps> = ({
disableControls,
toggleInfoPanel,
commentsCount,
variant,
}) => {
const { handleSubmit } = useFormContext();
const { canApprove, canReject } = permissions;
Expand All @@ -52,12 +58,17 @@ export const ProposalControlPanel: FC<ProposalControlPanelProps> = ({

const showTGas = !(voted || (!canApprove && !canReject) || disableControls);

const readOnlyGas =
variant === ProposalVariant.ProposeRemoveUpgradeCode ||
variant === ProposalVariant.ProposeUpgradeSelf ||
variant === ProposalVariant.ProposeGetUpgradeCode;

return (
<form
onSubmit={handleSubmit(onLike)}
className={cn(styles.root, className)}
>
{showTGas && <TgasInput />}
{showTGas && <TgasInput readOnly={readOnlyGas} />}
<ProposalControlButton
icon={liked ? 'votingYesChecked' : yesIconName}
voted={voted}
Expand Down
2 changes: 1 addition & 1 deletion astro_2.0/components/TgasInput/TgasInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export const TgasInput: FC<TgasInputProps> = ({
type="number"
min={MIN_GAS}
step={1}
readOnly={readOnly}
defaultValue={defaultValue}
max={MAX_GAS}
isBorderless
size="block"
disabled={readOnly}
data-testid="gas-input"
placeholder={`${DEFAULT_PROPOSAL_GAS}`}
{...register('gas')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function DaoSubmitForm(): JSX.Element {
labelClassName={styles.label}
>
<div>
<strong>5.4</strong> NEAR
<strong>6</strong> NEAR
</div>
</FieldWrapper>
<InputWrapper fieldName="gas" label="TGas">
Expand Down
2 changes: 1 addition & 1 deletion astro_2.0/features/CreateDao/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function getNewDaoParams(
bond: '0.1',
votePeriod: '168',
gracePeriod: '24',
amountToTransfer: '5.4',
amountToTransfer: '6',
displayName: data.info.displayName,
policy: {
...getDetailedRolesVotingPolicy(
Expand Down
7 changes: 7 additions & 0 deletions astro_2.0/features/CreateProposal/CreateProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { GA_EVENTS, sendGAEvent } from 'utils/ga';

import { getFormInitialValues } from 'astro_2.0/features/CreateProposal/helpers/initialValues';
import { getNewProposalObject } from 'astro_2.0/features/CreateProposal/helpers/newProposalObject';
import { getNonEditableGasValue } from 'astro_2.0/features/CreateProposal/helpers/proposalVariantsHelpers';
import {
getFormContentNode,
getValidationSchema,
Expand Down Expand Up @@ -276,6 +277,11 @@ export const CreateProposal: FC<CreateProposalProps> = ({

const contentNode = getFormContentNode(selectedProposalVariant, dao);

const nonEditableGas = getNonEditableGasValue(
selectedProposalVariant,
methods.getValues()
);

return (
<FormProvider {...methods}>
<div className={cn(styles.root, className)} ref={formRef}>
Expand Down Expand Up @@ -323,6 +329,7 @@ export const CreateProposal: FC<CreateProposalProps> = ({
}
infoPanelNode={
<TransactionDetailsWidget
gas={nonEditableGas}
onSubmit={onSubmit}
buttonLabel={t('propose')}
bond={{ value: dao.policy.proposalBond }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ export const CreateProposalCard: React.FC<CreateProposalCardProps> = ({
}
case ProposalVariant.ProposeGetUpgradeCode: {
return (
<InfoBlockWidget label="Upgrade" value="Get latest binary code" />
<InfoBlockWidget label="Upgrade" value="Get Code From Factory" />
);
}
case ProposalVariant.ProposeUpgradeSelf: {
return <InfoBlockWidget label="Upgrade" value="Upgrade dao" />;
return <InfoBlockWidget label="Upgrade" value="Upgrade DAO" />;
}
case ProposalVariant.ProposeRemoveUpgradeCode: {
return <InfoBlockWidget label="Upgrade" value="Remove binary" />;
return (
<InfoBlockWidget label="Upgrade" value="Recover Storage Costs" />
);
}
case ProposalVariant.ProposeDoneBounty: {
return (
Expand Down
17 changes: 10 additions & 7 deletions astro_2.0/features/CreateProposal/helpers/initialValues.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* istanbul ignore file */

import { ProposalVariant } from 'types/proposal';
import { DEFAULT_PROPOSAL_GAS } from 'services/sputnik/constants';
import {
DEFAULT_PROPOSAL_GAS,
DEFAULT_UPGRADE_DAO_PROPOSALS_GAS,
} from 'services/sputnik/constants';

export function getFormInitialValues(
selectedProposalType: ProposalVariant,
Expand All @@ -11,25 +14,25 @@ export function getFormInitialValues(
switch (selectedProposalType) {
case ProposalVariant.ProposeGetUpgradeCode: {
return {
details: 'Get latest binary for DAO upgrade',
details: `Upgrading your DAO requires you to retrieve the new code you want your DAO to run. This proposal is to get a copy of the upgrade code. The code comes from the Sputnik DAO Factory, the same place your DAO came from when you created it.`,
externalUrl: '',
gas: DEFAULT_PROPOSAL_GAS,
gas: DEFAULT_UPGRADE_DAO_PROPOSALS_GAS,
versionHash: initialValues?.versionHash,
};
}
case ProposalVariant.ProposeUpgradeSelf: {
return {
details: 'Upgrade DAO',
details: `Now that your DAO has a copy of the code it wants to run, it's time to propose that the DAO "Upgrades Itself." This proposal will switch the DAO from running its old code to the code you retrieved in step 1.`,
externalUrl: '',
gas: DEFAULT_PROPOSAL_GAS,
gas: DEFAULT_UPGRADE_DAO_PROPOSALS_GAS,
versionHash: initialValues?.versionHash,
};
}
case ProposalVariant.ProposeRemoveUpgradeCode: {
return {
details: 'Remove binary used for DAO upgrade',
details: `Your DAO is now running the latest code! This proposal is to delete the upgrade code which you retrieved from the factory. Deleting that code saves NEAR for your DAO. It's safe to delete that code because smart contracts always store a copy of the code they're running.`,
externalUrl: '',
gas: DEFAULT_PROPOSAL_GAS,
gas: DEFAULT_UPGRADE_DAO_PROPOSALS_GAS,
versionHash: initialValues?.versionHash,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ProposalVariant } from 'types/proposal';

export function getNonEditableGasValue(
variant: ProposalVariant,
values: Record<string, unknown>
): { label: string; value: string } | undefined {
switch (variant) {
case ProposalVariant.ProposeUpgradeSelf:
case ProposalVariant.ProposeGetUpgradeCode:
case ProposalVariant.ProposeRemoveUpgradeCode: {
return {
label: 'Gas',
value: values.gas as string,
};
}
default: {
return undefined;
}
}
}
8 changes: 8 additions & 0 deletions astro_2.0/features/CreateProposal/helpers/rootHelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,14 @@ export function getValidationSchema(
});
}

case ProposalVariant.ProposeUpgradeSelf:
case ProposalVariant.ProposeGetUpgradeCode:
case ProposalVariant.ProposeRemoveUpgradeCode: {
return yup.object().shape({
details: yup.string().required('Required'),
});
}

case ProposalVariant.ProposeDoneBounty:
default: {
return yup.object().shape({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
margin-top: 32px;
}

.warning {
margin-bottom: 24px;
}

.title {
@extend %title3;
margin-bottom: 4px;
Expand All @@ -161,27 +165,3 @@
.text {
@extend %caption1;
}

.upgradeDaoButton {
align-items: center;
background: var(--color-white);
border-radius: 4px;
box-shadow: 0 4px 25px rgba(0, 0, 0, 0.15);
display: flex;
font-size: 13px;
opacity: 0.8;
position: absolute;
right: 24px;
text-transform: capitalize;
top: 24px;
transition: opacity 0.1s ease-out;

&:hover {
opacity: 0.9;
}
}

.upgradeIcon {
margin-right: 4px;
width: 24px;
}
Loading

0 comments on commit 7c58f04

Please sign in to comment.