Skip to content

Commit 8a0e4d5

Browse files
committed
refactor: GitHub deployment and useless undefined config
1 parent bc16bc4 commit 8a0e4d5

File tree

13 files changed

+690
-631
lines changed

13 files changed

+690
-631
lines changed

package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"@babel/core": "^7.21.3",
7-
"@chakra-ui/icons": "^2.0.17",
8-
"@chakra-ui/react": "^2.5.2",
9-
"@chakra-ui/styled-system": "^2.6.2",
10-
"@chakra-ui/system": "^2.5.2",
6+
"@babel/core": "^7.21.8",
7+
"@chakra-ui/icons": "^2.0.19",
8+
"@chakra-ui/react": "^2.6.1",
9+
"@chakra-ui/styled-system": "^2.9.0",
10+
"@chakra-ui/system": "^2.5.7",
1111
"@chakra-ui/theme-tools": "^2.0.16",
12-
"@emotion/react": "^11.10.6",
13-
"@emotion/styled": "^11.10.6",
12+
"@emotion/react": "^11.11.0",
13+
"@emotion/styled": "^11.11.0",
1414
"aleph-sdk-ts": "^3.2.0",
15-
"axios": "^1.3.4",
15+
"axios": "^1.4.0",
1616
"boring-avatars": "^1.7.0",
1717
"crypto-js": "^4.1.1",
1818
"eth-crypto": "^2.6.0",
1919
"ethers": "^5.7.2",
20-
"framer-motion": "^10.6.0",
20+
"framer-motion": "^10.12.12",
2121
"git-clone": "^0.2.0",
22-
"joi": "^17.8.4",
22+
"joi": "^17.9.2",
2323
"js-file-download": "^0.4.12",
2424
"next": "^12.3.4",
2525
"next-auth": "4.10.3",
@@ -28,7 +28,7 @@
2828
"react": "^18.2.0",
2929
"react-dom": "^18.2.0",
3030
"react-icons": "^4.8.0",
31-
"typescript": "^4.9.5"
31+
"typescript": "^5.0.4"
3232
},
3333
"scripts": {
3434
"dev": "next dev",
@@ -55,21 +55,21 @@
5555
"@next/eslint-plugin-next": "^12.3.4",
5656
"@types/crypto-js": "^4.1.1",
5757
"@types/git-clone": "^0.2.0",
58-
"@types/node": "^16.18.16",
59-
"@types/react": "^18.0.28",
60-
"@types/react-dom": "^18.0.11",
61-
"@typescript-eslint/eslint-plugin": "^5.55.0",
62-
"@typescript-eslint/parser": "^5.55.0",
58+
"@types/node": "^16.18.31",
59+
"@types/react": "^18.2.6",
60+
"@types/react-dom": "^18.2.4",
61+
"@typescript-eslint/eslint-plugin": "^5.59.6",
62+
"@typescript-eslint/parser": "^5.59.6",
6363
"cypress": "^11.2.0",
6464
"cypress-file-upload": "^5.0.8",
65-
"eslint": "^8.36.0",
65+
"eslint": "^8.40.0",
6666
"eslint-config-airbnb": "^19.0.4",
6767
"eslint-config-airbnb-typescript": "^17.0.0",
68-
"eslint-config-prettier": "^8.7.0",
68+
"eslint-config-prettier": "^8.8.0",
6969
"eslint-plugin-import": "^2.27.5",
7070
"eslint-plugin-jsx-a11y": "^6.7.1",
7171
"eslint-plugin-react": "^7.32.2",
7272
"eslint-plugin-react-hooks": "^4.6.0",
73-
"prettier": "^2.8.4"
73+
"prettier": "^2.8.8"
7474
}
7575
}

pages/api/program/create.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { NextApiRequest, NextApiResponse } from 'next';
33
import { createRouter } from 'next-connect';
44

55
import validate from 'lib/middlewares/validation';
6-
import { compress, programPublish } from 'lib/services/deploy';
7-
import { cleanup, clone, getProgramName } from 'lib/services/git';
6+
import deploy from 'lib/services/deploy';
7+
import { clone, getProgramName } from 'lib/services/git';
88

99
const router = createRouter<NextApiRequest, NextApiResponse>();
1010

@@ -16,12 +16,8 @@ const postSchema = Joi.object({
1616

1717
router.post(validate({ body: postSchema }), async (req, res) => {
1818
const { repository, entrypoint } = req.body;
19-
let itemHash = '';
20-
await clone(repository).then(async (path: string) => {
21-
const fileName: string = await compress(path);
22-
itemHash = await programPublish(fileName, entrypoint);
23-
await cleanup(path);
24-
});
19+
const path = await clone(repository);
20+
const itemHash = await deploy(path, entrypoint);
2521
return res.status(200).json({ name: getProgramName(repository), item_hash: itemHash, entrypoint });
2622
});
2723

src/components/account/ConfigCard.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ const ConfigCard = (): JSX.Element => {
3636
try {
3737
const config1 = await user.contact.updateConfig(key, value);
3838
setConfig({
39-
...user.config!,
39+
...user.config,
4040
[key]: {
41-
...user.config![key],
41+
...user.config[key],
4242
value,
4343
},
4444
});
@@ -74,18 +74,18 @@ const ConfigCard = (): JSX.Element => {
7474
</Text>
7575
</HStack>
7676

77-
{Object.keys(user?.config ?? []).map((key) => {
78-
if (user.config![key].type === 'select')
77+
{Object.keys(user.config).map((key) => {
78+
if (user.config[key].type === 'select')
7979
return (
8080
<ConfigSelect key={`${key}-select`} option={key} isLoading={isLoading} onClick={changeConfig} />
8181
);
8282
return (
8383
<HStack key={`${key}-input`} spacing="32px">
8484
<Text color={textColor}>
8585
<Box as="span" fontWeight="500">
86-
{`${user.config![key].name}:`}
86+
{`${user.config[key].name}:`}
8787
</Box>{' '}
88-
{user?.config![key].value ?? ''}
88+
{user.config[key].value}
8989
</Text>
9090
<Button
9191
variant="secondary"

src/components/contact/AddContact.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const AddContact = (): JSX.Element => {
3030
files: [],
3131
folders: [],
3232
config: undefined,
33-
programs: []
33+
programs: [],
3434
});
3535

3636
toast({ title: add.message, status: add.success ? 'success' : 'error' });

src/components/dashboardPage/ProgramOptions.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ import { IPCProgram } from 'types/types';
2020
import { useConfigContext } from 'contexts/config';
2121

2222
import DeployProgram from 'components/computing/programs/DeployProgram';
23+
import DeleteProgram from 'components/programs/DeleteProgram';
2324
import GoToWebsiteProgram from 'components/programs/GoToWebsiteProgram';
2425
import RenameProgram from 'components/programs/RenameProgram';
25-
import DeleteProgram from 'components/programs/DeleteProgram';
2626

27-
const ProgramOptionsContent = ({ program }: { program: IPCProgram }): JSX.Element => (
27+
const ProgramOptionsContent = ({ program }: { program: IPCProgram }) => (
2828
<>
2929
<GoToWebsiteProgram program={program} />
3030
<DeployProgram selectedProgram={program} />
31-
<RenameProgram program={program}/>
32-
<DeleteProgram program={program}/>
31+
<RenameProgram program={program} />
32+
<DeleteProgram program={program} />
3333
</>
3434
);
3535

@@ -43,7 +43,7 @@ const ProgramOptionsPopover = ({
4343
clickPosition: { x: number; y: number };
4444
popoverOpeningToggle: boolean;
4545
popoverOpeningHandler: () => void;
46-
}): JSX.Element => {
46+
}) => {
4747
const { config } = useConfigContext();
4848
const { isOpen, onOpen, onClose } = useDisclosure();
4949

@@ -88,7 +88,7 @@ const ProgramOptionsDrawer = ({
8888
program: IPCProgram;
8989
isOpen: boolean;
9090
onClose: () => void;
91-
}): JSX.Element => (
91+
}) => (
9292
<Drawer isOpen={isOpen} onClose={onClose} placement="bottom">
9393
<DrawerOverlay />
9494
<DrawerContent borderRadius="16px 16px 0px 0px">

src/components/navigation/SideBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const SideBar = (): JSX.Element => {
6767
p="32px"
6868
spacing="64px"
6969
bg={bgColor}
70-
borderRight={{ base: '', lg: `1px solid ${colorMode === 'light' ? colors.gray['100'] : colors.gray['100']}` }}
70+
borderRight={{ base: '', lg: `1px solid ${colors.gray['100']}` }}
7171
>
7272
<VStack w="100%" px="16px" spacing="32px">
7373
<VStack w="100%" spacing="16px">

src/components/programs/DeleteProgram.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ const DeleteProgram = ({ program }: DeleteProgramProps): JSX.Element => {
3333
const textColor = useColorModeValue(textColorMode.light, textColorMode.dark);
3434
const { colorMode } = useColorMode();
3535

36-
const deleteActualProgram = async () => {
37-
setIsLoading(true);
38-
const update = await user.computing.deleteProgram(program.hash);
39-
if (update.success)
40-
setPrograms(programs.filter((f) => f.hash !== program.hash));
41-
setIsLoading(false);
42-
onClose();
43-
}
36+
const deleteActualProgram = async () => {
37+
setIsLoading(true);
38+
const update = await user.computing.deleteProgram(program.hash);
39+
if (update.success) setPrograms(programs.filter((f) => f.hash !== program.hash));
40+
setIsLoading(false);
41+
onClose();
42+
};
4443

4544
return (
4645
<HStack

src/components/programs/RenameProgram.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {
2-
HStack,
32
FormControl,
43
FormLabel,
5-
Input,
6-
useDisclosure,
4+
HStack,
75
Icon,
6+
Input,
87
Text,
98
useBreakpointValue,
109
useColorMode,
11-
useColorModeValue
10+
useColorModeValue,
11+
useDisclosure,
1212
} from '@chakra-ui/react';
1313

1414
import { BsPencil } from 'react-icons/bs';
@@ -17,20 +17,19 @@ import type { IPCProgram } from 'types/types';
1717

1818
import { textColorMode } from 'config/colorMode';
1919

20-
import Modal from 'components/Modal';
2120
import Button from 'components/Button';
21+
import Modal from 'components/Modal';
2222

2323
import { ChangeEvent, useState } from 'react';
2424

25-
26-
import { useUserContext } from 'contexts/user';
2725
import { useDriveContext } from 'contexts/drive';
26+
import { useUserContext } from 'contexts/user';
2827

2928
type RenameProgramProps = {
3029
program: IPCProgram;
3130
};
3231

33-
const RenameProgram = ({ program }: RenameProgramProps): JSX.Element => {
32+
const RenameProgram = ({ program }: RenameProgramProps) => {
3433
const isDrawer = useBreakpointValue({ base: true, sm: false }) || false;
3534
const { isOpen, onOpen, onClose } = useDisclosure();
3635
const textColor = useColorModeValue(textColorMode.light, textColorMode.dark);
@@ -39,7 +38,7 @@ const RenameProgram = ({ program }: RenameProgramProps): JSX.Element => {
3938
const [isLoading, setIsLoading] = useState(false);
4039

4140
const { user } = useUserContext();
42-
const {programs, setPrograms} = useDriveContext();
41+
const { programs, setPrograms } = useDriveContext();
4342

4443
const updateProgramName = async () => {
4544
setIsLoading(true);
@@ -124,6 +123,6 @@ const RenameProgram = ({ program }: RenameProgramProps): JSX.Element => {
124123
</Modal>
125124
</HStack>
126125
);
127-
}
126+
};
128127

129128
export default RenameProgram;

src/lib/contact.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,13 @@ class Contact {
517517
public async updateConfig(key: string, value: string): Promise<ResponseType> {
518518
try {
519519
const contact = this.contacts.find((c) => c.address === this.account.address);
520-
if (contact) {
521-
if (!contact.config![key]) {
520+
if (contact?.config) {
521+
if (!contact.config[key]) {
522522
return { success: false, message: 'Invalid config key' };
523523
}
524-
contact.config![key].value = value;
524+
contact.config[key].value = value;
525525
await this.publishAggregate();
526-
return { success: true, message: `${contact.config![key].name} changed` };
526+
return { success: true, message: `${contact.config[key].name} changed` };
527527
}
528528
return { success: false, message: 'Failed to find account' };
529529
} catch (err) {

src/lib/services/deploy.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import fs from 'node:fs';
66
import child_process from 'child_process';
77

88
import { ALEPH_CHANNEL } from 'config/constants';
9+
import { cleanup } from './git';
910

10-
async function compress(path: string): Promise<string> {
11+
const compress = (path: string) => {
1112
child_process.execSync(`zip -r ${path} *`, { cwd: path });
1213
return `${path}.zip`;
13-
}
14+
};
1415

15-
async function programPublish(path: string, entrypoint: string): Promise<string> {
16+
const programPublish = async (path: string, entrypoint: string) => {
1617
const programHashPublishProgram = await program.publish({
1718
channel: ALEPH_CHANNEL,
1819
account: ethereum.NewAccount().account,
@@ -21,6 +22,13 @@ async function programPublish(path: string, entrypoint: string): Promise<string>
2122
entrypoint,
2223
});
2324
return programHashPublishProgram.item_hash;
24-
}
25+
};
2526

26-
export { compress, programPublish };
27+
const deploy = async (path: string, entrypoint: string) => {
28+
const fileName: string = compress(path);
29+
const itemHash = await programPublish(fileName, entrypoint);
30+
await cleanup(path);
31+
return itemHash;
32+
};
33+
34+
export default deploy;

0 commit comments

Comments
 (0)