Skip to content

Commit

Permalink
resolve kevin comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sepehr2github committed May 15, 2024
1 parent 66e16d1 commit 8e2c77b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/services/ipfs/ipfsService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {resolveIpfsCid} from '@aragon/sdk-client-common';
import {IPinDataProps} from './ipfsService.api';
import {pinataJSONAPI, pinataFileAPI} from 'utils/constants';
import {pinataJSONAPI, pinataFileAPI, DataType} from 'utils/constants';

class IpfsService {
constructor(
Expand All @@ -25,7 +25,7 @@ class IpfsService {
const {processedData, type} = await this.processData(data);
let res;

if (type === 'file') {
if (type === DataType.File) {
res = await fetch(pinataFileAPI, {
method: 'POST',
headers: {
Expand Down Expand Up @@ -56,22 +56,22 @@ class IpfsService {
data: IPinDataProps
): Promise<{
processedData: string | Uint8Array | FormData;
type: 'file' | 'json';
type: DataType;
}> => {
let processedData: string | Uint8Array | FormData;
let type: 'file' | 'json';
let type: DataType;

if (data instanceof Blob) {
const formData = new FormData();
formData.append('file', data);
formData.append(DataType.File, data);
processedData = formData;
type = 'file';
type = DataType.File;
} else if (typeof data !== 'string') {
processedData = new Uint8Array(data);
type = 'json';
type = DataType.JSON;
} else {
processedData = data;
type = 'json';
type = DataType.JSON;
}

return {processedData, type};
Expand Down
5 changes: 5 additions & 0 deletions src/utils/constants/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export type NavLinkData = {
icon: IconType;
};

export const enum DataType {
File = 'file',
JSON = 'json',
}

export const NAV_LINKS_DATA: NavLinkData[] = [
{
label: i18n.t('navLinks.dashboard'),
Expand Down

0 comments on commit 8e2c77b

Please sign in to comment.