diff --git a/jest.config.cjs b/jest.config.cjs index 64dc4380..e38b7581 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -1,14 +1,19 @@ -const esModules = ['@lukso/lsp-smart-contracts', '@lukso/lsp-factory.js'].join( - '|' -) +const esModules = [ + '@lukso/lsp-smart-contracts', + '@lukso/lsp-factory.js', + '@web3-onboard', + 'nanoid', + '@lukso/web3-onboard-config', + '@tsndr/cloudflare-worker-jwt', +].join('|') module.exports = { transform: { '^.+\\.vue$': '@vue/vue3-jest', - '^.+\\.tsx?$': ['ts-jest', { tsconfig: '/tsconfig.json' }], + '^.+\\.(t|j)sx?$': ['ts-jest', { tsconfig: '/tsconfig.json' }], }, setupFilesAfterEnv: ['/tests/setup-env.ts'], - transformIgnorePatterns: [`/node_modules/(?!${esModules})`], + transformIgnorePatterns: [`/node_modules/(?!(${esModules}))`], testEnvironment: 'jsdom', moduleFileExtensions: ['js', 'ts', 'json', 'vue'], moduleNameMapper: { diff --git a/jest.setup.cjs b/jest.setup.cjs index 5c9b79e9..c385473f 100644 --- a/jest.setup.cjs +++ b/jest.setup.cjs @@ -1,3 +1,6 @@ module.exports = async () => { process.env.TZ = 'UTC' + + global.crypto = require('isomorphic-webcrypto') + console.log(global.crypto) } diff --git a/package.json b/package.json index a5a0a2d8..75f1fbfe 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "@lukso/up-provider": "^0.1.3", "@lukso/web3-onboard-config": "1.1.2", "@pinata/sdk": "^2.1.0", - "@tsndr/cloudflare-worker-jwt": "^2.5.3", "@types/isomorphic-fetch": "^0.0.39", "@walletconnect/ethereum-provider": "2.16.0", "@walletconnect/sign-client": "2.16.0", @@ -41,6 +40,7 @@ "filesize": "10.0.12", "https-browserify": "1.0.0", "isomorphic-fetch": "^3.0.0", + "isomorphic-webcrypto": "^2.3.8", "siwe": "1.1.6", "tslib": "^2.6.2", "vue": "^3.4.21", diff --git a/src/components/endpoints/Assets.vue b/src/components/endpoints/Assets.vue index b400de23..fd8056c0 100644 --- a/src/components/endpoints/Assets.vue +++ b/src/components/endpoints/Assets.vue @@ -9,10 +9,15 @@ import { Lsp4Metadata, Token } from '@/types' import { ContractStandard } from '@/enums' import CustomSelect from '@/components/shared/CustomSelect.vue' import { useLspFactory } from '@/compositions/useLspFactory' -import { addTokenToLocalStore, recalculateAssets } from '@/helpers/tokenUtils' +import { + addTokenToLocalStore, + encodeAssetMetadata, + recalculateAssets, +} from '@/helpers/tokenUtils' import { DeployedERC20Token, useERC20 } from '@/compositions/useErc20' import { LSP8_TOKEN_ID_FORMAT } from '@lukso/lsp-smart-contracts' import { LSP4_TOKEN_TYPES } from '@lukso/lsp4-contracts' +import { uploadAssetData } from '@/utils/uploadAssetData' import { DeployedLSP7DigitalAsset, DeployedLSP8IdentifiableDigitalAsset, @@ -70,6 +75,8 @@ const create = async () => { const erc725AccountAddress = getState('address') isTokenPending.value = true + const assetMetadata = await uploadAssetData(lsp4Metadata.value) + const metadataJsonUrl = encodeAssetMetadata(assetMetadata) try { const { deployLSP7DigitalAsset, deployLSP8IdentifiableDigitalAsset } = useLspFactory() @@ -92,11 +99,7 @@ const create = async () => { tokenType: LSP4_TOKEN_TYPES.TOKEN, isNFT: !!token.value.isNonDivisible, creators: toRaw(creators.value), - digitalAssetMetadata: { - LSP4Metadata: { - ...lsp4Metadata.value, - }, - }, + digitalAssetMetadata: metadataJsonUrl, } console.log(digitalAssetData) deployedAsset = await deployLSP7DigitalAsset(digitalAssetData) @@ -111,11 +114,7 @@ const create = async () => { controllerAddress: erc725AccountAddress, tokenType: LSP4_TOKEN_TYPES.COLLECTION, creators: toRaw(creators.value), - digitalAssetMetadata: { - LSP4Metadata: { - ...lsp4Metadata.value, - }, - }, + digitalAssetMetadata: metadataJsonUrl, tokenIdFormat: tokenIdType.value, } console.log(digitalAssetData) diff --git a/src/components/endpoints/GetNetworkId.vue b/src/components/endpoints/GetNetworkId.vue index ec1cb13d..c115bb51 100644 --- a/src/components/endpoints/GetNetworkId.vue +++ b/src/components/endpoints/GetNetworkId.vue @@ -7,22 +7,22 @@ import { NETWORKS, setNetworkConfig, } from '@/helpers/config' +import { hexToNumber } from 'web3-utils' import { NetworkInfo } from '@/interfaces/network' -import { ref, watch } from 'vue' +import { onMounted, ref, watch } from 'vue' import { numberToHex } from 'web3-utils' const { notification, clearNotification, hasNotification, setNotification } = useNotifications() const web3 = useWeb3Connection() - const defaultNetworkConfig = getSelectedNetworkConfig() -const defaultNetwork: NetworkInfo = { - ...defaultNetworkConfig, -} +// const defaultNetwork: NetworkInfo = { +// ...defaultNetworkConfig, +// } const networkId = ref('') const err = ref('') -const activeNetwork = ref(defaultNetwork) +const activeNetwork = ref(defaultNetworkConfig) watch( () => getSelectedNetworkConfig(), () => { @@ -44,6 +44,7 @@ const getNetworkId = async () => { } const changeNetwork = async () => { + if (!activeNetwork.value) return try { await web3.sendRequest({ method: 'wallet_switchEthereumChain', @@ -63,13 +64,14 @@ const changeNetwork = async () => { } const changeDappNetwork = async () => { + if (!activeNetwork.value) return try { let currentChainId = getSelectedNetworkConfig().chainId if (currentChainId !== activeNetwork.value.chainId) { setNetworkConfig(activeNetwork.value.chainId) currentChainId = getSelectedNetworkConfig().chainId + location.reload() } - location.reload() } catch (error) { console.error(error) setNotification((error as unknown as Error).message, 'danger') @@ -77,6 +79,7 @@ const changeDappNetwork = async () => { } const addNetwork = async () => { + if (!activeNetwork.value) return try { await web3.sendRequest({ method: 'wallet_addEthereumChain', @@ -94,6 +97,17 @@ const addNetwork = async () => { setNotification((addError as unknown as Error).message, 'danger') } } + +onMounted(() => { + const selectedNetworkChainId = getSelectedNetworkConfig() + const networkInfo = networks.find( + (element: NetworkInfo) => + hexToNumber(element.chainId) === selectedNetworkChainId.chainId + ) + if (networkInfo) { + activeNetwork.value = networkInfo + } +})