From 6b12a26ee9d920c7a27b41a883d1fcebc86651cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuzhan?= <145108492+AltayDev@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:18:06 +0300 Subject: [PATCH 1/6] Purrfect Universe (#953) * Update default_assets.go - PUR Token is added * Update default_assets.go --- pkg/assets/default_assets.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/assets/default_assets.go b/pkg/assets/default_assets.go index 52e436b7a..35f15d7d4 100644 --- a/pkg/assets/default_assets.go +++ b/pkg/assets/default_assets.go @@ -118,6 +118,13 @@ func (s *AssetsStore) createFileDefault(path string) error { "symbol": "WETH.e", "decimals": 18, "MEXCSymbol": "ETHUSDT" + }, + { + "address": "AS133eqPPaPttJ6hJnk3sfoG5cjFFqBDi1VGxdo2wzWkq8AfZnan", + "name": "Purrfect Universe", + "symbol": "PUR", + "decimals": 18, + "MEXCSymbol": "" } ]`), permissionUrwGrOr); err != nil { return err From 7b5ef84ad6b8c0928fe02842f3ee9151ea179a84 Mon Sep 17 00:00:00 2001 From: Nathan Seva <thykof@protonmail.ch> Date: Fri, 7 Jun 2024 09:22:06 -0500 Subject: [PATCH 2/6] fix go tests --- internal/handler/wallet/get_all_assets_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/handler/wallet/get_all_assets_test.go b/internal/handler/wallet/get_all_assets_test.go index 76e40ad69..c86e80639 100644 --- a/internal/handler/wallet/get_all_assets_test.go +++ b/internal/handler/wallet/get_all_assets_test.go @@ -23,7 +23,7 @@ func TestGetAllAssetsHandler(t *testing.T) { assetsWithBalance := getAssets(t, api, nickname) // Assert that assetsWithBalance contains the expected data - assert.Len(t, assetsWithBalance, 8, "the assets list should have 8 items") + assert.Len(t, assetsWithBalance, 9, "the assets list should have 9 items") assert.Equal(t, "1000000", assetsWithBalance[0].Balance) assert.Equal(t, "Massa", assetsWithBalance[0].AssetInfo.Name) From e35cd70cf68f0db88542673b36dced89a6d17924 Mon Sep 17 00:00:00 2001 From: Nathan Seva <thykof@protonmail.ch> Date: Wed, 5 Jun 2024 12:03:06 -0500 Subject: [PATCH 3/6] front: update FT icons --- wails-frontend/package-lock.json | 34 +++++++++---------- web-frontend/package-lock.json | 34 +++++++++---------- web-frontend/src/pages/Assets/AssetsList.tsx | 14 ++------ .../ReceiveCoins/GenerateLink.tsx | 18 ++-------- .../TransferCoins/SendCoins/AssetSelector.tsx | 18 ++-------- .../SendCoins/SendConfirmation.tsx | 13 ++----- web-frontend/src/utils/tokenIcon.ts | 15 +++----- 7 files changed, 48 insertions(+), 98 deletions(-) diff --git a/wails-frontend/package-lock.json b/wails-frontend/package-lock.json index 561ff47de..f2ba2b281 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.20240605165214", + "resolved": "https://registry.npmjs.org/@massalabs/react-ui-kit/-/react-ui-kit-0.0.5-dev.20240605165214.tgz", + "integrity": "sha512-WCxW6+DiegpOWzXZPfOKOM5qk6n72LdW5VbLoftJnVo5kVwK2xTLaOw3YrQZ6mfSxOVRpBq/+/hNlqQ9r7Br8A==", "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..3e48a9984 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.20240605165214", + "resolved": "https://registry.npmjs.org/@massalabs/react-ui-kit/-/react-ui-kit-0.0.5-dev.20240605165214.tgz", + "integrity": "sha512-WCxW6+DiegpOWzXZPfOKOM5qk6n72LdW5VbLoftJnVo5kVwK2xTLaOw3YrQZ6mfSxOVRpBq/+/hNlqQ9r7Br8A==", "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/pages/Assets/AssetsList.tsx b/web-frontend/src/pages/Assets/AssetsList.tsx index 499a3448b..d67d1ccea 100644 --- a/web-frontend/src/pages/Assets/AssetsList.tsx +++ b/web-frontend/src/pages/Assets/AssetsList.tsx @@ -1,12 +1,11 @@ import { useState } from 'react'; -import { Token, getAssetIcons } from '@massalabs/react-ui-kit'; +import { Token } 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'; +import { tokenIcon } from '@/utils/tokenIcon'; interface AssetsListProps { assets: Asset[] | undefined; @@ -23,20 +22,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) => ( <Token - logo={getAssetIcons( - symbolDict[token.symbol as keyof typeof symbolDict], - true, - isMainnet, - 32, - )} + logo={tokenIcon(token.symbol, 32)} name={token.name} symbol={token.symbol} decimals={token.decimals} diff --git a/web-frontend/src/pages/TransferCoins/ReceiveCoins/GenerateLink.tsx b/web-frontend/src/pages/TransferCoins/ReceiveCoins/GenerateLink.tsx index 2aea6f89d..814de723b 100644 --- a/web-frontend/src/pages/TransferCoins/ReceiveCoins/GenerateLink.tsx +++ b/web-frontend/src/pages/TransferCoins/ReceiveCoins/GenerateLink.tsx @@ -8,18 +8,16 @@ import { PopupModalHeader, Clipboard, formatAmount, - getAssetIcons, Selector, Identicon, } from '@massalabs/react-ui-kit'; -import { useFTTransfer } from '@/custom/smart-contract/useFTTransfer'; import Intl from '@/i18n/i18n'; import { AccountObject } from '@/models/AccountModel'; import { Asset } from '@/models/AssetModel'; import { AssetSelector } from '@/pages/TransferCoins/SendCoins/AssetSelector'; import { parseForm } from '@/utils/'; -import { symbolDict } from '@/utils/tokenIcon'; +import { tokenIcon } from '@/utils/tokenIcon'; import { SendInputsErrors } from '@/validation/sendInputs'; interface MoneyForm { @@ -37,8 +35,6 @@ interface GenerateLinkProps { function GenerateLink(props: GenerateLinkProps) { const { account, presetURL, setURL, setModal } = props; - const { isMainnet } = useFTTransfer(); - const [amount, setAmount] = useState<string>(''); const [link, setLink] = useState(''); const [error, setError] = useState<SendInputsErrors | null>(null); @@ -121,17 +117,7 @@ function GenerateLink(props: GenerateLinkProps) { preIcon={<Identicon username={account.nickname} />} content={account.nickname} amount={formattedBalance} - posIcon={ - getAssetIcons( - symbolDict[ - selectedAsset?.symbol as keyof typeof symbolDict - ], - true, - isMainnet, - 24, - 'mr-3', - ) as JSX.Element - } + posIcon={tokenIcon(selectedAsset?.symbol || '', 24)} variant="secondary" /> </div> diff --git a/web-frontend/src/pages/TransferCoins/SendCoins/AssetSelector.tsx b/web-frontend/src/pages/TransferCoins/SendCoins/AssetSelector.tsx index 420c93916..6089b0e2b 100644 --- a/web-frontend/src/pages/TransferCoins/SendCoins/AssetSelector.tsx +++ b/web-frontend/src/pages/TransferCoins/SendCoins/AssetSelector.tsx @@ -1,18 +1,12 @@ import { useEffect } from 'react'; -import { - Dropdown, - formatAmount, - getAssetIcons, - IOption, -} from '@massalabs/react-ui-kit'; +import { Dropdown, formatAmount, IOption } from '@massalabs/react-ui-kit'; 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'; +import { tokenIcon } from '@/utils/tokenIcon'; interface AssetSelectorProps { selectedAsset: Asset | undefined; @@ -23,7 +17,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<Asset[]>( `accounts/${nickname}/assets`, @@ -60,12 +53,7 @@ export function AssetSelector(props: AssetSelectorProps) { </p> </div> ), - icon: getAssetIcons( - symbolDict[asset.symbol as keyof typeof symbolDict], - true, - isMainnet, - 28, - ), + icon: tokenIcon(asset.symbol, 28), 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..9df388684 100644 --- a/web-frontend/src/pages/TransferCoins/SendCoins/SendConfirmation.tsx +++ b/web-frontend/src/pages/TransferCoins/SendCoins/SendConfirmation.tsx @@ -3,7 +3,6 @@ import { Button, Tooltip, formatFTAmount, - getAssetIcons, parseAmount, Clipboard, Mns, @@ -14,8 +13,7 @@ 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'; +import { tokenIcon } 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={tokenIcon(symbol, 28)} /> <div className="flex flex-col gap-4 p-4"> <div className="flex items-center gap-8"> diff --git a/web-frontend/src/utils/tokenIcon.ts b/web-frontend/src/utils/tokenIcon.ts index fe12e370a..68b5be27e 100644 --- a/web-frontend/src/utils/tokenIcon.ts +++ b/web-frontend/src/utils/tokenIcon.ts @@ -1,12 +1,5 @@ -import { MAS } from '@/const/assets/assets'; +import { getAssetIcons } from '@massalabs/react-ui-kit'; -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', -}; +export function tokenIcon(symbol: string, size: number) { + return getAssetIcons(symbol, undefined, false, size) as JSX.Element; +} From 45ba3c78cfdd78b3322ac00ad78707d55e69f4c6 Mon Sep 17 00:00:00 2001 From: Nathan Seva <thykof@protonmail.ch> Date: Fri, 7 Jun 2024 09:23:34 -0500 Subject: [PATCH 4/6] update ui kit with PUR svg logo --- web-frontend/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web-frontend/package-lock.json b/web-frontend/package-lock.json index 3e48a9984..731a03432 100644 --- a/web-frontend/package-lock.json +++ b/web-frontend/package-lock.json @@ -3353,9 +3353,9 @@ } }, "node_modules/@massalabs/react-ui-kit": { - "version": "0.0.5-dev.20240605165214", - "resolved": "https://registry.npmjs.org/@massalabs/react-ui-kit/-/react-ui-kit-0.0.5-dev.20240605165214.tgz", - "integrity": "sha512-WCxW6+DiegpOWzXZPfOKOM5qk6n72LdW5VbLoftJnVo5kVwK2xTLaOw3YrQZ6mfSxOVRpBq/+/hNlqQ9r7Br8A==", + "version": "0.0.5-dev.20240607130255", + "resolved": "https://registry.npmjs.org/@massalabs/react-ui-kit/-/react-ui-kit-0.0.5-dev.20240607130255.tgz", + "integrity": "sha512-LTF8r5EZ2Jj2SB98E0MkoD1vTDnyVji4tPGGGXe+43nyR47YreFJ9pLvrmvWkGexXdJc+Sp1DQMK3/3u9DjLvw==", "dependencies": { "@headlessui/react": "^1.7.15", "copy-to-clipboard": "^3.3.3", From e83b2637eb6be04cb7bfadf0732e94113403c535 Mon Sep 17 00:00:00 2001 From: Nathan Seva <thykof@protonmail.ch> Date: Wed, 5 Jun 2024 11:51:50 -0500 Subject: [PATCH 5/6] default assets: overwrite --- pkg/assets/default_assets.go | 41 ++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/pkg/assets/default_assets.go b/pkg/assets/default_assets.go index 35f15d7d4..46b47be7c 100644 --- a/pkg/assets/default_assets.go +++ b/pkg/assets/default_assets.go @@ -53,13 +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. @@ -69,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", @@ -119,16 +143,11 @@ func (s *AssetsStore) createFileDefault(path string) error { "decimals": 18, "MEXCSymbol": "ETHUSDT" }, - { + { "address": "AS133eqPPaPttJ6hJnk3sfoG5cjFFqBDi1VGxdo2wzWkq8AfZnan", "name": "Purrfect Universe", "symbol": "PUR", "decimals": 18, "MEXCSymbol": "" } -]`), permissionUrwGrOr); err != nil { - return err - } - - return nil -} +]` From 2e096ca132af3de0111ff76e4f0699152c65d1a6 Mon Sep 17 00:00:00 2001 From: Nathan Seva <thykof@protonmail.ch> Date: Wed, 5 Jun 2024 16:02:01 -0500 Subject: [PATCH 6/6] improve sort of assets --- internal/handler/wallet/get_all_assets.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/internal/handler/wallet/get_all_assets.go b/internal/handler/wallet/get_all_assets.go index 47895934d..8b7e00504 100644 --- a/internal/handler/wallet/get_all_assets.go +++ b/internal/handler/wallet/get_all_assets.go @@ -52,7 +52,6 @@ func (g *getAllAssets) Handle(params operations.GetAllAssetsParams) middleware.R assetsWithBalance = append(assetsWithBalance, userAssetData...) - // sort AssetsWithBalance by name sort.Slice(assetsWithBalance, func(i, j int) bool { if assetsWithBalance[i].AssetInfo.Symbol == "MAS" { return true @@ -60,13 +59,21 @@ func (g *getAllAssets) Handle(params operations.GetAllAssetsParams) middleware.R if assetsWithBalance[j].AssetInfo.Symbol == "MAS" { return false } - if assetsWithBalance[i].DollarValue == nil { - return false + + valueI := assetsWithBalance[i].DollarValue + valueJ := assetsWithBalance[j].DollarValue + + if (valueI == nil || *valueI == 0) && (valueJ == nil || *valueJ == 0) { + return assetsWithBalance[i].AssetInfo.Symbol < assetsWithBalance[j].AssetInfo.Symbol } - if assetsWithBalance[j].DollarValue == nil { + if valueI == nil || *valueI == 0 { return false } - return *assetsWithBalance[i].DollarValue > *assetsWithBalance[j].DollarValue + if valueJ == nil || *valueJ == 0 { + return true + } + + return *valueI > *valueJ }) // Return the list of assets with balance