diff --git a/package.json b/package.json index 094c16006..732e6d987 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "echarts": "4.9.0", "history": "5.3.0", "i18next": "20.6.1", - "js-base64": "^3.7.5", "jsbi": "3.2.5", "lint-staged": "^13.2.3", "lodash.debounce": "4.0.8", diff --git a/src/pages/Address/AddressAssetComp.tsx b/src/pages/Address/AddressAssetComp.tsx index bd2f347e6..c54d004f2 100644 --- a/src/pages/Address/AddressAssetComp.tsx +++ b/src/pages/Address/AddressAssetComp.tsx @@ -1,14 +1,12 @@ import { useTranslation } from 'react-i18next' import { ReactEventHandler, useEffect, useState } from 'react' -import { Base64 } from 'js-base64' -import { hexToBytes } from '@nervosnetwork/ckb-sdk-utils' import axios, { AxiosResponse } from 'axios' import { AddressUDTItemPanel } from './styled' import { CoTA, OmigaInscription, MNFT, NRC721, SUDT, Spore } from '../../models/Address' import SUDTTokenIcon from '../../assets/sudt_token.png' import { parseUDTAmount } from '../../utils/number' import { parseSporeCellData } from '../../utils/spore' -import { handleNftImgError, patchMibaoImg } from '../../utils/util' +import { handleNftImgError, hexToBase64, patchMibaoImg } from '../../utils/util' import { sliceNftName } from '../../utils/string' export const AddressAssetComp = ({ @@ -69,7 +67,7 @@ export const AddressSporeComp = ({ account }: { account: Spore }) => { if (udtIconFile) { const sporeData = parseSporeCellData(udtIconFile) if (sporeData.content.slice(0, 5) === 'image') { - const base64Data = Base64.fromUint8Array(hexToBytes(`0x${sporeData.content}`)) + const base64Data = hexToBase64(sporeData.content) setIcon(`data:${sporeData.contentType};base64,${base64Data}`) } } diff --git a/src/pages/NftCollectionInfo/NftCollectionInventory/index.tsx b/src/pages/NftCollectionInfo/NftCollectionInventory/index.tsx index f5cea5db3..0e11e375c 100644 --- a/src/pages/NftCollectionInfo/NftCollectionInventory/index.tsx +++ b/src/pages/NftCollectionInfo/NftCollectionInventory/index.tsx @@ -1,14 +1,12 @@ import { Link } from 'react-router-dom' import { useQuery } from '@tanstack/react-query' -import { Base64 } from 'js-base64' -import { hexToBytes } from '@nervosnetwork/ckb-sdk-utils' import { useTranslation } from 'react-i18next' import { parseSporeCellData } from '../../../utils/spore' import { ReactComponent as Cover } from '../../../assets/nft_cover.svg' import styles from './styles.module.scss' import { getPrimaryColor } from '../../../constants/common' import { explorerService } from '../../../services/ExplorerService' -import { handleNftImgError, patchMibaoImg } from '../../../utils/util' +import { handleNftImgError, hexToBase64, patchMibaoImg } from '../../../utils/util' import type { NFTItem } from '../../../services/ExplorerService/fetcher' const primaryColor = getPrimaryColor() @@ -47,7 +45,7 @@ const NftCollectionInventory: React.FC<{ if (standard === 'spore' && cell && cell.data) { const sporeData = parseSporeCellData(cell.data) if (sporeData.contentType.slice(0, 5) === 'image') { - const base64data = Base64.fromUint8Array(hexToBytes(`0x${sporeData.content}`)) + const base64data = hexToBase64(sporeData.content) return ( { if (standard === 'spore' && cell && cell.data) { const sporeData = parseSporeCellData(cell.data) if (sporeData.contentType.slice(0, 5) === 'image') { - const base64data = Base64.fromUint8Array(hexToBytes(`0x${sporeData.content}`)) + const base64data = hexToBase64(sporeData.content) return ( { + const str = hexstring + .match(/\w{2}/g) + ?.map(function (a) { + return String.fromCharCode(parseInt(a, 16)) + }) + .join('') + if (!str) return '' + return btoa(str) +} + export default { copyElementValue, shannonToCkb, @@ -364,4 +375,5 @@ export default { deprecatedAddrToNewAddr, handleRedirectFromAggron, assertIsHashType, + hexToBase64, } diff --git a/yarn.lock b/yarn.lock index f6494c2ba..71222bf17 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12154,11 +12154,6 @@ jest@^27.4.3: import-local "^3.0.2" jest-cli "^27.5.1" -js-base64@^3.7.5: - version "3.7.6" - resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.6.tgz#6ccb5d761b48381fd819f9ce04998866dbcbbc99" - integrity sha512-NPrWuHFxFUknr1KqJRDgUQPexQF0uIJWjeT+2KjEePhitQxQEx5EJBG1lVn5/hc8aLycTpXrDOgPQ6Zq+EDiTA== - js-sdsl@^4.1.4: version "4.2.0" resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.2.0.tgz#278e98b7bea589b8baaf048c20aeb19eb7ad09d0"