diff --git a/config/defaultCATs.json b/config/defaultCATs.json index c71d733a..350eebe8 100644 --- a/config/defaultCATs.json +++ b/config/defaultCATs.json @@ -2,7 +2,7 @@ "Mainnet": [ { "assetId": "6d95dae356e32a71db5ddcb42224754a02524c615c5fc35f568c2af04774e589", - "code": "USDS", + "code": "USDSC", "iconUrl": "https://image.hashgreen.net/image/uat/1675738259_LtSFI.png" } ], @@ -14,4 +14,4 @@ } ], "Develop": [] -} +} \ No newline at end of file diff --git a/src/api/api.ts b/src/api/api.ts index dc4bc1c2..a349cd5d 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -3,15 +3,11 @@ import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios' import { registerMessageHandler } from 'axios-chrome-messaging-adapter' import { toast } from 'react-toastify' -import { - IMarket, - IResponseData, - ITransaction, - RequestConfig, -} from '~/types/api' +import { IAsset, IResponseData, ITransaction, RequestConfig } from '~/types/api' import { ChainEnum } from '~/types/chia' +import { Asset } from '~/types/entities' import { apiEndpointSets } from '~/utils/constants' -import { getErrorMessage, ToastOption } from '~/utils/errorMessage' +import { getErrorMessage, toastOption } from '~/utils/errorMessage' import { getStorage } from '~/utils/extension/storage' /** -------------------------- Full Node API -------------------------- */ @@ -38,7 +34,7 @@ export async function apiHandler( if (config.isShowToast) { const message = getErrorMessage(resError) toast.error(message, { - ...ToastOption, + ...toastOption, toastId: resError?.response?.data?.code?.toString() ?? 'none', }) } @@ -88,6 +84,15 @@ export const getFeesEstimate = ( /** ----------------------- * --- Jarvan addon API -------------------------- */ +export const callGetCATs = async () => { + const res = await apiHandler>({ + url: + apiEndpointSets[await getStorage('chainId')]?.newJarvan + + '/cats?catType=2&size=0', + }) + return res.data.data?.map((item) => new Asset(item)) +} + export const sendTx = ( params: AxiosRequestConfig, config: RequestConfig = { isShowToast: false } @@ -165,17 +170,6 @@ export const callGetAblyAccessToken = (formData) => data: formData, }) /** -------------------------- Jarvan addon API END -------------------------- */ -/** -------------------------- Zed API -------------------------- */ -export const callGetMarkets = async () => - apiHandler>({ - url: - apiEndpointSets[await getStorage('chainId')]?.zed + - '/markets', - - method: 'get', - }) - -/** -------------------------- Zed API END -------------------------- */ /** -------------------------- Spacescan API -------------------------- */ export const callGetExchangeRate = (assetId: string) => diff --git a/src/components/List.tsx b/src/components/List.tsx index d70aa318..f6c09e58 100644 --- a/src/components/List.tsx +++ b/src/components/List.tsx @@ -1,8 +1,8 @@ // src/SelectedAssetList.tsx -import { ICryptocurrency } from '~/types/api' +import { Asset } from '~/types/entities' interface ISelectedAssetList { - assets: ICryptocurrency[] + assets: Asset[] onRemove: (id: string) => void } @@ -11,13 +11,13 @@ export const SelectedAssetList = ({ assets, onRemove }: ISelectedAssetList) => {
{assets.map((asset) => (
{asset.code} @@ -28,7 +28,7 @@ export const SelectedAssetList = ({ assets, onRemove }: ISelectedAssetList) => { onRemove(asset.asset_id)} + onClick={() => onRemove(asset.assetId)} />
))} diff --git a/src/components/Transaction/AssetDisplay.tsx b/src/components/Transaction/AssetDisplay.tsx index 98dd0650..1af86557 100644 --- a/src/components/Transaction/AssetDisplay.tsx +++ b/src/components/Transaction/AssetDisplay.tsx @@ -30,7 +30,7 @@ const AssetDisplay = ({ const finsAsset = availableAssets?.data?.find( (availableAsset) => - add0x(availableAsset.asset_id) === assetId + add0x(availableAsset.assetId) === assetId ) const name = existAsset?.code || finsAsset?.name @@ -42,7 +42,7 @@ const AssetDisplay = ({ >
diff --git a/src/components/Transaction/Transaction.tsx b/src/components/Transaction/Transaction.tsx index f4ca5c93..63ff7f2b 100644 --- a/src/components/Transaction/Transaction.tsx +++ b/src/components/Transaction/Transaction.tsx @@ -1,5 +1,6 @@ import classNames from 'classnames' import { format } from 'date-fns' +import { toJS } from 'mobx' import { observer } from 'mobx-react-lite' import { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' @@ -56,16 +57,17 @@ const Transaction = ({ assetsStore: { availableAssets, XCH, existedAssets }, } = rootStore const existAsset = existedAssets.find( - (asset) => add0x(asset.assetId) === assetId + (asset) => add0x(asset.assetId) === add0x(assetId) ) const asset = useMemo( () => availableAssets.data.find( - (asset) => add0x(asset.asset_id) === assetId + (asset) => add0x(asset.assetId) === add0x(assetId) ), [assetId, availableAssets.data] ) + console.log('assetId', assetId, toJS(existAsset), toJS(asset)) const isTransfer = txType === ITxType.TX_TYPE_CAT_TRANSFER || diff --git a/src/container/ImportCAT/ImportCAT.tsx b/src/container/ImportCAT/ImportCAT.tsx index 39cdd26d..733c7c54 100644 --- a/src/container/ImportCAT/ImportCAT.tsx +++ b/src/container/ImportCAT/ImportCAT.tsx @@ -10,7 +10,7 @@ import SearchBar from '~/components/SearchBar' import BackLink from '~/layouts/BackLink' import { useClosablePage } from '~/layouts/ClosablePage' import rootStore from '~/store' -import { ICryptocurrency } from '~/types/api' +import { Asset } from '~/types/entities' import { fuseOptions, search } from '~/utils/fuse' import BottomIcon from '~icons/hoogii/bottom.jsx' @@ -23,7 +23,7 @@ function ImportCAT() { const { assetsStore: { existedAssets, availableAssets }, } = rootStore - const [selected, setSelected] = useState([]) + const [selected, setSelected] = useState([]) const [toggleSelectedList, setToggleSelectedList] = useState(false) @@ -34,16 +34,16 @@ function ImportCAT() { const filteredAssets = useMemo( () => - search( + search( keyword, availableAssets.data, - fuseOptions(['asset_id', 'code', 'name']) + fuseOptions(['assetId', 'code', 'name']) ), [keyword, availableAssets.data] ) const handleRemoveSelected = (id: string) => { - const newSelected = selected.filter((item) => item.asset_id !== id) + const newSelected = selected.filter((item) => item.assetId !== id) setSelected(newSelected) @@ -72,11 +72,11 @@ function ImportCAT() { ], }) - selected.forEach(({ asset_id, code, icon_url }) => + selected.forEach(({ assetId, code, icon }) => rootStore.walletStore.db.assets.add({ - assetId: asset_id, + assetId, code, - iconUrl: icon_url, + iconUrl: icon, }) ) } @@ -142,32 +142,32 @@ function ImportCAT() {
{filteredAssets.map((item, index) => ( - e.asset_id === item.asset_id + e.assetId === item.assetId )} disabled={existedAssetIds?.some( - (id) => id === item.asset_id + (id) => id === item.assetId )} onClick={() => { if ( selected.some( (e) => - e.asset_id === - item.asset_id + e.assetId === + item.assetId ) ) { setSelected([ ...selected.filter( (e) => - e.asset_id !== - item.asset_id + e.assetId !== + item.assetId ), ]) } else { diff --git a/src/container/ImportCAT/components/CustomPage.tsx b/src/container/ImportCAT/components/CustomPage.tsx index d7b94403..4aeb65ef 100644 --- a/src/container/ImportCAT/components/CustomPage.tsx +++ b/src/container/ImportCAT/components/CustomPage.tsx @@ -12,7 +12,7 @@ import { sendMeasurement } from '~/api/ga' // import AssetIcon from '~/components/AssetIcon' import ErrorMessage from '~/components/ErrorMessage' import rootStore from '~/store' -import { ICryptocurrency } from '~/types/api' +import { Asset } from '~/types/entities' import { fuseOptions, search } from '~/utils/fuse' interface IForm { @@ -94,10 +94,10 @@ const CustomPage = () => { const searchResults = useMemo(() => { if (!errors.assetId && searchField) { - const result = search( + const result = search( searchField, availableAssets.data, - fuseOptions(['asset_id']) + fuseOptions(['assetId']) ) return result?.[0] @@ -206,7 +206,7 @@ const CustomPage = () => {
{searchResults.code} diff --git a/src/popup/components/spendBundleInfo.tsx b/src/popup/components/spendBundleInfo.tsx index 3a1a3394..94bf9d56 100644 --- a/src/popup/components/spendBundleInfo.tsx +++ b/src/popup/components/spendBundleInfo.tsx @@ -35,7 +35,7 @@ function spendBundleInfo({ request }: IPopupPageProps) { } = rootStore const finsAsset = availableAssets?.data?.find( - (availableAsset) => metadata?.asset_id === availableAsset.asset_id + (availableAsset) => metadata?.asset_id === availableAsset.assetId ) const onGetParseSpendBundle = async (spendBundle) => { try { @@ -78,7 +78,7 @@ function spendBundleInfo({ request }: IPopupPageProps) {
= { + availableAssets: IFetchData = { isFetching: true, data: [], } @@ -52,13 +53,9 @@ class AssetsStore { onBecomeUnobserved(this, 'existedAssets', this.unsubscribeExistedAssets) onBecomeObserved(this, 'availableAssets', async () => { try { - const res = await callGetMarkets() - const markets = res.data.data - const assets = markets.map( - (market) => market[market.info_ccy_name] as ICryptocurrency - ) + const assets = await callGetCATs() runInAction(() => { - this.availableAssets.data = assets + this.availableAssets.data = assets || [] this.availableAssets.isFetching = false }) } catch (error) {} @@ -89,13 +86,13 @@ class AssetsStore { ) } const asset = this.availableAssets.data.find( - (asset) => asset.asset_id === assetId + (asset) => asset.assetId === assetId ) return asset ? { - assetId: asset.asset_id, + assetId: asset.assetId, code: asset.code, - iconUrl: asset.icon_url, + iconUrl: asset.icon, } : asset } diff --git a/src/types/api.ts b/src/types/api.ts index d4a15832..41a92109 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -13,6 +13,13 @@ interface IBase { updated_at: string } +export interface IAsset { + code: string + name: string + icon: string + asset_id: string +} + export interface ICryptocurrency extends IBase { id: string asset_id: string diff --git a/src/types/chia.ts b/src/types/chia.ts index ac18e265..199f4bbb 100644 --- a/src/types/chia.ts +++ b/src/types/chia.ts @@ -15,6 +15,7 @@ export interface IChainSet { } export interface IApiEndpointSet { + newJarvan: string jarvan: string zed: string } diff --git a/src/types/entities.ts b/src/types/entities.ts new file mode 100644 index 00000000..875a4298 --- /dev/null +++ b/src/types/entities.ts @@ -0,0 +1,15 @@ +import { IAsset } from './api' + +export class Asset { + code: string + name: string + icon: string + assetId: string + + constructor(asset: IAsset) { + this.code = asset.code + this.name = asset.name + this.icon = asset.icon + this.assetId = asset.asset_id + } +} diff --git a/src/utils/constants.ts b/src/utils/constants.ts index a8bd9aa9..1f4af672 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -27,14 +27,17 @@ export const apiEndpointSets: { [key in ChainEnum]: IApiEndpointSet } = { [ChainEnum.Mainnet]: { + newJarvan: 'https://jarvan-api.hash.green/api/v1', jarvan: 'https://prod-jarvan.hash.green/api/v1', zed: 'https://hash.green/api/v1', }, [ChainEnum.Testnet]: { + newJarvan: 'https://uat-jarvan-api.hash.green/api/v1', jarvan: 'https://stg-jarvan.hash.green/api/v1', zed: 'https://testnet10.hash.green/api/v1', }, [ChainEnum.Develop]: { + newJarvan: 'https://uat-jarvan-api.hash.green/api/v1', jarvan: 'https://uat-jarvan.hash.green/api/v1', zed: 'https://testnet10.hash.green/api/v1', }, diff --git a/src/utils/errorMessage.ts b/src/utils/errorMessage.ts index 7e513b9a..9bdb72c2 100644 --- a/src/utils/errorMessage.ts +++ b/src/utils/errorMessage.ts @@ -21,7 +21,7 @@ export const getErrorMessage = (error: AxiosError) => { return API_TIME_OUT } -export const ToastOption: ToastOptions = { +export const toastOption: ToastOptions = { autoClose: 2500, hideProgressBar: true, closeOnClick: true,