diff --git a/pkg/assets/default_assets.go b/pkg/assets/default_assets.go index b8743ee9b..9f433de79 100644 --- a/pkg/assets/default_assets.go +++ b/pkg/assets/default_assets.go @@ -53,15 +53,30 @@ func (s *AssetsStore) InitDefault() error { return err } - if _, err := os.Stat(defaultAssetsJSONPath); os.IsNotExist(err) { - if err := s.createFileDefault(defaultAssetsJSONPath); err != nil { + // if the file does not exist, create the default assets JSON file + _, err = os.Stat(defaultAssetsJSONPath) + if os.IsNotExist(err) { + // Create the default assets JSON file + return s.createFileDefault(defaultAssetsJSONPath) + } + + // if the file exists, read the content and compare it with the default assets + if err == nil { + // read the content of the default assets JSON file + content, err := os.ReadFile(defaultAssetsJSONPath) + if err != nil { return err } - } - + // if the content is different, overwrite the default assets JSON file + if string(content) != assetsJSON { + if err := s.createFileDefault(defaultAssetsJSONPath); err != nil { + return err + } + } + } - return nil + return err } // getDefaultJSONPath returns the path to the default assets JSON file. @@ -71,7 +86,14 @@ func getDefaultJSONPath(assetsJSONDir string) (string, error) { // createFileDefault creates the default assets JSON file with the default assets. func (s *AssetsStore) createFileDefault(path string) error { - if err := os.WriteFile(path, []byte(`[ + if err := os.WriteFile(path, []byte(assetsJSON), permissionUrwGrOr); err != nil { + return err + } + + return nil +} + +const assetsJSON = `[ { "address": "AS12k8viVmqPtRuXzCm6rKXjLgpQWqbuMjc37YHhB452KSUUb9FgL", "name": "Sepolia USDC", @@ -149,9 +171,4 @@ func (s *AssetsStore) createFileDefault(path string) error { "decimals": 18, "MEXCSymbol": "USD" } -]`), permissionUrwGrOr); err != nil { - return err - } - - return nil -} +]` diff --git a/wails-frontend/package-lock.json b/wails-frontend/package-lock.json index 561ff47de..2ce75be7f 100644 --- a/wails-frontend/package-lock.json +++ b/wails-frontend/package-lock.json @@ -1957,12 +1957,12 @@ } }, "node_modules/@massalabs/massa-web3": { - "version": "4.0.2-dev.20240410152026", - "resolved": "https://registry.npmjs.org/@massalabs/massa-web3/-/massa-web3-4.0.2-dev.20240410152026.tgz", - "integrity": "sha512-SGsXbxICvdwOnRThh2MSswvzA/k5OfrlJSujZBgNA2CoATXGBar11YcDEIgVttHRRqQSJG39EQcMOs3eRC0irA==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/@massalabs/massa-web3/-/massa-web3-4.0.3.tgz", + "integrity": "sha512-W1TtxMrTiqLfUgvIqO641M/2do6Z2Kvvq44JYhiUbteXI5S+VvCJ+HaRtIZ23r9k2wTSlSikE6j6U5bkKDMABA==", "dependencies": { "@massalabs/wallet-provider": "^2.0.0", - "@massalabs/web3-utils": "^1.4.9", + "@massalabs/web3-utils": "^1.4.11", "@noble/ed25519": "^1.7.3", "@noble/hashes": "^1.2.0", "@types/ws": "^8.5.4", @@ -2022,14 +2022,13 @@ } }, "node_modules/@massalabs/react-ui-kit": { - "version": "0.0.5-dev.20240517003813", - "resolved": "https://registry.npmjs.org/@massalabs/react-ui-kit/-/react-ui-kit-0.0.5-dev.20240517003813.tgz", - "integrity": "sha512-i0KfrxIBsF6qe4z4nTjAu/qrsFsut1/Bv3XIdPUsgpDvhG9hAONg2gIEbHbjDm3sNa66Bn+/NnEVzf4EUr33Sg==", + "version": "0.0.5-dev.20240531154425", + "resolved": "https://registry.npmjs.org/@massalabs/react-ui-kit/-/react-ui-kit-0.0.5-dev.20240531154425.tgz", + "integrity": "sha512-SGvMCN88fmcrz2ZprYtNGs2QrDqOU3kgFoduU9zcZc2GwnNslxKW2U8qC7X3ee0HaRs68RQZ3fy/NcjYQ/xs9Q==", "dependencies": { "@headlessui/react": "^1.7.15", "copy-to-clipboard": "^3.3.3", "currency.js": "^2.0.4", - "dot-object": "^2.1.5", "minidenticons": "^4.2.1", "react": "^18.2.0", "react-currency-input-field": "^3.6.11", @@ -2043,8 +2042,10 @@ "zustand": "^4.5.2" }, "peerDependencies": { - "@massalabs/massa-web3": "^4.0.2-dev", - "@massalabs/wallet-provider": "^2.0.1-dev" + "@massalabs/massa-web3": "^4.0.3-dev", + "@massalabs/wallet-provider": "^2.0.1-dev", + "@types/dot-object": "^2.1.6", + "dot-object": "^2.1.5" } }, "node_modules/@massalabs/react-ui-kit/node_modules/abitype": { @@ -2129,9 +2130,9 @@ } }, "node_modules/@massalabs/web3-utils": { - "version": "1.4.9", - "resolved": "https://registry.npmjs.org/@massalabs/web3-utils/-/web3-utils-1.4.9.tgz", - "integrity": "sha512-8G91gs6HqpPpR860QDUOzugr81WJTGkBgXQS1gq/oXqt16fPkw2xlsq4c2CFHDjRF9/ftE/JaybiNZ4ilcbEyg==", + "version": "1.4.11", + "resolved": "https://registry.npmjs.org/@massalabs/web3-utils/-/web3-utils-1.4.11.tgz", + "integrity": "sha512-9iUoSc9OZxrvx8UbDor934z0cetenEU3PlDqTa9Hsh3EuZJ9jalcEU8Q9Z+hjLn2S9Ojmqu2ldcOAxVzYeNCbw==", "dependencies": { "bignumber.js": "^9.1.2", "buffer": "^6.0.3", @@ -3008,10 +3009,9 @@ } }, "node_modules/@types/dot-object": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/@types/dot-object/-/dot-object-2.1.2.tgz", - "integrity": "sha512-mARrpJofLNe6yhlukeBcznBe8ssZo5ZJ/CJWc3JKmG9L9151s0OHK+mealnkqSgO6cSn1219vND2wgL67Cuqiw==", - "dev": true + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/@types/dot-object/-/dot-object-2.1.6.tgz", + "integrity": "sha512-G1e4SNPOuO72ZXv7wz/W2x29CzQtpxko3G9hBiHqGg/AvFIKoArCs2nbc/WPXnnUkO+1dmvX9WQCyj5gIlAzZg==" }, "node_modules/@types/estree": { "version": "1.0.1", diff --git a/web-frontend/package-lock.json b/web-frontend/package-lock.json index e6e77d2c3..869a0c0f8 100644 --- a/web-frontend/package-lock.json +++ b/web-frontend/package-lock.json @@ -3280,12 +3280,12 @@ } }, "node_modules/@massalabs/massa-web3": { - "version": "4.0.2-dev.20240410152026", - "resolved": "https://registry.npmjs.org/@massalabs/massa-web3/-/massa-web3-4.0.2-dev.20240410152026.tgz", - "integrity": "sha512-SGsXbxICvdwOnRThh2MSswvzA/k5OfrlJSujZBgNA2CoATXGBar11YcDEIgVttHRRqQSJG39EQcMOs3eRC0irA==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/@massalabs/massa-web3/-/massa-web3-4.0.3.tgz", + "integrity": "sha512-W1TtxMrTiqLfUgvIqO641M/2do6Z2Kvvq44JYhiUbteXI5S+VvCJ+HaRtIZ23r9k2wTSlSikE6j6U5bkKDMABA==", "dependencies": { "@massalabs/wallet-provider": "^2.0.0", - "@massalabs/web3-utils": "^1.4.9", + "@massalabs/web3-utils": "^1.4.11", "@noble/ed25519": "^1.7.3", "@noble/hashes": "^1.2.0", "@types/ws": "^8.5.4", @@ -3353,14 +3353,13 @@ } }, "node_modules/@massalabs/react-ui-kit": { - "version": "0.0.5-dev.20240522140200", - "resolved": "https://registry.npmjs.org/@massalabs/react-ui-kit/-/react-ui-kit-0.0.5-dev.20240522140200.tgz", - "integrity": "sha512-NQF2P4nOMiWxzHhxkxb8hbIGjcG3xiXLlvTSFSAICWBvRl6BI3q69jrazjD33de6bwHF3C6B3/xUyoKFDvPV1A==", + "version": "0.0.5-dev.20240531154425", + "resolved": "https://registry.npmjs.org/@massalabs/react-ui-kit/-/react-ui-kit-0.0.5-dev.20240531154425.tgz", + "integrity": "sha512-SGvMCN88fmcrz2ZprYtNGs2QrDqOU3kgFoduU9zcZc2GwnNslxKW2U8qC7X3ee0HaRs68RQZ3fy/NcjYQ/xs9Q==", "dependencies": { "@headlessui/react": "^1.7.15", "copy-to-clipboard": "^3.3.3", "currency.js": "^2.0.4", - "dot-object": "^2.1.5", "minidenticons": "^4.2.1", "react": "^18.2.0", "react-currency-input-field": "^3.6.11", @@ -3374,8 +3373,10 @@ "zustand": "^4.5.2" }, "peerDependencies": { - "@massalabs/massa-web3": "^4.0.2-dev", - "@massalabs/wallet-provider": "^2.0.1-dev" + "@massalabs/massa-web3": "^4.0.3-dev", + "@massalabs/wallet-provider": "^2.0.1-dev", + "@types/dot-object": "^2.1.6", + "dot-object": "^2.1.5" } }, "node_modules/@massalabs/wallet-provider": { @@ -3406,9 +3407,9 @@ } }, "node_modules/@massalabs/web3-utils": { - "version": "1.4.9", - "resolved": "https://registry.npmjs.org/@massalabs/web3-utils/-/web3-utils-1.4.9.tgz", - "integrity": "sha512-8G91gs6HqpPpR860QDUOzugr81WJTGkBgXQS1gq/oXqt16fPkw2xlsq4c2CFHDjRF9/ftE/JaybiNZ4ilcbEyg==", + "version": "1.4.11", + "resolved": "https://registry.npmjs.org/@massalabs/web3-utils/-/web3-utils-1.4.11.tgz", + "integrity": "sha512-9iUoSc9OZxrvx8UbDor934z0cetenEU3PlDqTa9Hsh3EuZJ9jalcEU8Q9Z+hjLn2S9Ojmqu2ldcOAxVzYeNCbw==", "dependencies": { "bignumber.js": "^9.1.2", "buffer": "^6.0.3", @@ -4053,10 +4054,9 @@ } }, "node_modules/@types/dot-object": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/@types/dot-object/-/dot-object-2.1.2.tgz", - "integrity": "sha512-mARrpJofLNe6yhlukeBcznBe8ssZo5ZJ/CJWc3JKmG9L9151s0OHK+mealnkqSgO6cSn1219vND2wgL67Cuqiw==", - "dev": true + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/@types/dot-object/-/dot-object-2.1.6.tgz", + "integrity": "sha512-G1e4SNPOuO72ZXv7wz/W2x29CzQtpxko3G9hBiHqGg/AvFIKoArCs2nbc/WPXnnUkO+1dmvX9WQCyj5gIlAzZg==" }, "node_modules/@types/eslint": { "version": "8.37.0", diff --git a/web-frontend/src/custom/smart-contract/useFTTransfer.tsx b/web-frontend/src/custom/smart-contract/useFTTransfer.tsx index 555bf44c1..a39dde7da 100644 --- a/web-frontend/src/custom/smart-contract/useFTTransfer.tsx +++ b/web-frontend/src/custom/smart-contract/useFTTransfer.tsx @@ -206,7 +206,10 @@ function useWriteSmartContract(client?: Client, isMainnet?: boolean) { /> )); - logSmartContractEvents(client, operationId); + logSmartContractEvents( + client as unknown as import('/Users/nathanmassa/dev/Ui-Kit/node_modules/@massalabs/massa-web3/dist/esm/web3/Client').Client, + operationId, + ); } else { toast.error((t) => ( diff --git a/web-frontend/src/pages/Assets/AssetsList.tsx b/web-frontend/src/pages/Assets/AssetsList.tsx index 499a3448b..9f6a2df60 100644 --- a/web-frontend/src/pages/Assets/AssetsList.tsx +++ b/web-frontend/src/pages/Assets/AssetsList.tsx @@ -2,11 +2,9 @@ import { useState } from 'react'; import { Token, getAssetIcons } from '@massalabs/react-ui-kit'; -import { useFTTransfer } from '@/custom/smart-contract/useFTTransfer'; import Intl from '@/i18n/i18n'; import { Asset } from '@/models/AssetModel'; import { DeleteAssetModal } from '@/pages/Assets/DeleteAssets'; -import { symbolDict } from '@/utils/tokenIcon'; interface AssetsListProps { assets: Asset[] | undefined; @@ -23,20 +21,13 @@ export function AssetsList(props: AssetsListProps) { setModal(true); } - const { isMainnet } = useFTTransfer(); - return ( <> {assets ?.filter((a) => a.balance !== undefined && a.balance !== '') .map((token: Asset, index: number) => ( (''); const [link, setLink] = useState(''); const [error, setError] = useState(null); @@ -123,13 +119,10 @@ function GenerateLink(props: GenerateLinkProps) { amount={formattedBalance} posIcon={ getAssetIcons( - symbolDict[ - selectedAsset?.symbol as keyof typeof symbolDict - ], + selectedAsset?.symbol || '', + undefined, true, - isMainnet, - 24, - 'mr-3', + 32, ) as JSX.Element } variant="secondary" diff --git a/web-frontend/src/pages/TransferCoins/SendCoins/AssetSelector.tsx b/web-frontend/src/pages/TransferCoins/SendCoins/AssetSelector.tsx index 420c93916..e7b45b919 100644 --- a/web-frontend/src/pages/TransferCoins/SendCoins/AssetSelector.tsx +++ b/web-frontend/src/pages/TransferCoins/SendCoins/AssetSelector.tsx @@ -9,10 +9,8 @@ import { import { useParams } from 'react-router-dom'; import { useResource } from '@/custom/api'; -import { useFTTransfer } from '@/custom/smart-contract/useFTTransfer'; import Intl from '@/i18n/i18n'; import { Asset } from '@/models/AssetModel'; -import { symbolDict } from '@/utils/tokenIcon'; interface AssetSelectorProps { selectedAsset: Asset | undefined; @@ -23,7 +21,6 @@ interface AssetSelectorProps { export function AssetSelector(props: AssetSelectorProps) { const { selectedAsset, setSelectedAsset, selectSymbol } = props; const { nickname } = useParams(); - const { isMainnet } = useFTTransfer(); const { data: assets, isLoading: isAssetsLoading } = useResource( `accounts/${nickname}/assets`, @@ -60,12 +57,7 @@ export function AssetSelector(props: AssetSelectorProps) {

), - icon: getAssetIcons( - symbolDict[asset.symbol as keyof typeof symbolDict], - true, - isMainnet, - 28, - ), + icon: getAssetIcons(asset.symbol, undefined, true, 32), onClick: () => setSelectedAsset(asset), }; }); diff --git a/web-frontend/src/pages/TransferCoins/SendCoins/SendConfirmation.tsx b/web-frontend/src/pages/TransferCoins/SendCoins/SendConfirmation.tsx index 66ea14804..1fb017230 100644 --- a/web-frontend/src/pages/TransferCoins/SendCoins/SendConfirmation.tsx +++ b/web-frontend/src/pages/TransferCoins/SendCoins/SendConfirmation.tsx @@ -14,8 +14,6 @@ import { FiChevronLeft } from 'react-icons/fi'; import { PRESET_HIGH, PRESET_LOW, PRESET_STANDARD } from './Advanced'; import Intl from '@/i18n/i18n'; import { Asset } from '@/models/AssetModel'; -import { useMassaWeb3Store } from '@/store/store'; -import { symbolDict } from '@/utils/tokenIcon'; export interface SendConfirmationData { amount: string; @@ -33,7 +31,6 @@ interface SendConfirmationProps { export function SendConfirmation(props: SendConfirmationProps) { const { data, handleConfirm, isLoading } = props; - const { isMainnet } = useMassaWeb3Store(); const { amount, asset, fees, recipientAddress, recipientDomainName } = data; const { symbol, decimals } = asset; @@ -106,13 +103,7 @@ export function SendConfirmation(props: SendConfirmationProps) { customClass="p-0 bg-transparent" amount={formattedAmount} symbol={symbol} - icon={getAssetIcons( - symbolDict[symbol as keyof typeof symbolDict], - true, - isMainnet, - 32, - 'mr-3', - )} + icon={getAssetIcons(symbol, undefined, true, 32)} />
diff --git a/web-frontend/src/utils/tokenIcon.ts b/web-frontend/src/utils/tokenIcon.ts deleted file mode 100644 index fe12e370a..000000000 --- a/web-frontend/src/utils/tokenIcon.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { MAS } from '@/const/assets/assets'; - -export const symbolDict = { - MAS: MAS, - WMAS: 'WMAS', - 'WETH.e': 'WETH', - 'WETH.s': 'WETH', - 'USDC.e': 'USDC', - 'USDC.s': 'USDC', - 'DAI.e': 'DAI', - 'tDAI.s': 'DAI', -};