Skip to content

Commit

Permalink
base64 decode script
Browse files Browse the repository at this point in the history
  • Loading branch information
KorbinianK committed Apr 4, 2024
1 parent edf38dd commit a9878de
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/bridge-ui/src/libs/token/fetchNFTImageUrl.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { decodeBase64ToJson } from 'scripts/utils/decodeBase64ToJson';
import { get } from 'svelte/store';

import { destNetwork } from '$components/Bridge/state';
import { fetchNFTMetadata } from '$libs/token/fetchNFTMetadata';
import { decodeBase64ToJson } from '$libs/util/decodeBase64ToJson';
import { getLogger } from '$libs/util/logger';
import { resolveIPFSUri } from '$libs/util/resolveIPFSUri';
import { addMetadataToCache, isMetadataCached } from '$stores/metadata';
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-ui/src/libs/token/fetchNFTMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import axios, { AxiosError, type AxiosRequestConfig } from 'axios';
import { decodeBase64ToJson } from 'scripts/utils/decodeBase64ToJson';
import { get } from 'svelte/store';

import { destNetwork } from '$components/Bridge/state';
import { ipfsConfig } from '$config';
import { FetchMetadataError, NoMetadataFoundError, WrongChainError } from '$libs/error';
import { decodeBase64ToJson } from '$libs/util/decodeBase64ToJson';
import { getLogger } from '$libs/util/logger';
import { resolveIPFSUri } from '$libs/util/resolveIPFSUri';
import { getMetadataFromCache, isMetadataCached, metadataCache } from '$stores/metadata';
Expand Down
10 changes: 10 additions & 0 deletions packages/bridge-ui/src/libs/util/decodeBase64ToJson.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Buffer } from 'buffer';

export const decodeBase64ToJson = (base64: string) => {
try {
const decodedString = Buffer.from(base64, 'base64').toString('utf-8');
return JSON.parse(decodedString);
} catch (error) {
throw new Error('Failed to decode and parse JSON from base64: ' + (error as Error).message);
}
};

0 comments on commit a9878de

Please sign in to comment.