Skip to content

Commit

Permalink
add bsc token
Browse files Browse the repository at this point in the history
  • Loading branch information
Thykof committed Jun 5, 2024
1 parent 2ca2c10 commit 8dcf05c
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 98 deletions.
41 changes: 29 additions & 12 deletions pkg/assets/default_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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",
Expand Down Expand Up @@ -149,9 +171,4 @@ func (s *AssetsStore) createFileDefault(path string) error {
"decimals": 18,
"MEXCSymbol": "USD"
}
]`), 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.

5 changes: 4 additions & 1 deletion web-frontend/src/custom/smart-contract/useFTTransfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ function useWriteSmartContract(client?: Client, isMainnet?: boolean) {
/>
</ToastContent>
));
logSmartContractEvents(client, operationId);
logSmartContractEvents(
client as unknown as import('/Users/nathanmassa/dev/Ui-Kit/node_modules/@massalabs/massa-web3/dist/esm/web3/Client').Client,

Check failure on line 210 in web-frontend/src/custom/smart-contract/useFTTransfer.tsx

View workflow job for this annotation

GitHub Actions / lint-web-frontend

This line has a length of 136. Maximum allowed is 120
operationId,
);
} else {
toast.error((t) => (
<ToastContent t={t}>
Expand Down
11 changes: 1 addition & 10 deletions web-frontend/src/pages/Assets/AssetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) => (
<Token
logo={getAssetIcons(
symbolDict[token.symbol as keyof typeof symbolDict],
true,
isMainnet,
32,
)}
logo={getAssetIcons(token.symbol, undefined, true, 32)}
name={token.name}
symbol={token.symbol}
decimals={token.decimals}
Expand Down
13 changes: 3 additions & 10 deletions web-frontend/src/pages/TransferCoins/ReceiveCoins/GenerateLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ import {
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 { 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 @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Asset[]>(
`accounts/${nickname}/assets`,
Expand Down Expand Up @@ -60,12 +57,7 @@ export function AssetSelector(props: AssetSelectorProps) {
</p>
</div>
),
icon: getAssetIcons(
symbolDict[asset.symbol as keyof typeof symbolDict],
true,
isMainnet,
28,
),
icon: getAssetIcons(asset.symbol, undefined, true, 32),
onClick: () => setSelectedAsset(asset),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)}
/>
<div className="flex flex-col gap-4 p-4">
<div className="flex items-center gap-8">
Expand Down
12 changes: 0 additions & 12 deletions web-frontend/src/utils/tokenIcon.ts

This file was deleted.

0 comments on commit 8dcf05c

Please sign in to comment.