Skip to content

Commit

Permalink
Add pur token (#959)
Browse files Browse the repository at this point in the history
* Purrfect Universe (#953)

* Update default_assets.go

- PUR Token is added

* Update default_assets.go

* fix go tests

* front: update FT icons

* update ui kit with PUR svg logo

* default assets: overwrite

* improve sort of assets

---------

Co-authored-by: Oğuzhan <[email protected]>
  • Loading branch information
Thykof and AltayDev authored Jun 7, 2024
1 parent 6bbbff6 commit 66f1167
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 114 deletions.
17 changes: 12 additions & 5 deletions internal/handler/wallet/get_all_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,28 @@ 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
}
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
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/wallet/get_all_assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
46 changes: 36 additions & 10 deletions pkg/assets/default_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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",
Expand Down Expand Up @@ -118,10 +142,12 @@ 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
}

return nil
}
]`
34 changes: 17 additions & 17 deletions wails-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions web-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions web-frontend/src/pages/Assets/AssetsList.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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}
Expand Down
18 changes: 2 additions & 16 deletions web-frontend/src/pages/TransferCoins/ReceiveCoins/GenerateLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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>
Expand Down
18 changes: 3 additions & 15 deletions web-frontend/src/pages/TransferCoins/SendCoins/AssetSelector.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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`,
Expand Down Expand Up @@ -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),
};
});
Expand Down
Loading

0 comments on commit 66f1167

Please sign in to comment.