Skip to content

Commit

Permalink
add hardcode token adding possibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridel1e committed Dec 31, 2023
1 parent ba01eb1 commit 9a074e1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@
]
},
"engines": {
"node": "^19"
"node": "^20"
}
}
3 changes: 3 additions & 0 deletions src/applicationConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DateTime } from 'luxon';

import { Dictionary } from './common/utils/Dictionary';
import { isProductionEnv } from './common/utils/env';
import { DefaultTokenListItem } from './network/cardano/api/common/defaultTokenList.ts';

const isProductionHost = 'app.spectrum.fi' === location.host;

Expand All @@ -23,6 +24,7 @@ interface NetworkConfig {
readonly defaultTokenListUrl: string;
readonly lbspWhitelistUrl: string;
readonly isCreatePoolAvailable: boolean;
readonly additionalTokenList?: DefaultTokenListItem[];
}

interface CardanoUpdate {
Expand Down Expand Up @@ -91,6 +93,7 @@ export const applicationConfig: ApplicationConfig = {
isCreatePoolAvailable: false,
},
cardano: {
additionalTokenList: [],
defaultTokenListUrl: 'https://spectrum.fi/cardano-token-list.json',
lbspWhitelistUrl: 'https://spectrum.fi/lbsp_whitelist.json',
metadataUrl: 'https://spectrum.fi/logos/cardano',
Expand Down
12 changes: 8 additions & 4 deletions src/common/services/DefaultTokenList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ export interface DefaultTokenList<T> {
export const getDefaultTokenList = <T>(
url: string,
getHash: (item: T) => string,
additionalTokens: T[] = [],
): Observable<DefaultTokenList<T>> =>
from(axios.get(url)).pipe(
map((res) => res.data),
map((data: DefaultTokenList<T>) => ({
...data,
tokensMap: data.tokens.reduce<Map<string, T>>((map, item) => {
map.set(getHash(item), item);
tokens: data.tokens.concat(additionalTokens),
tokensMap: data.tokens
.concat(additionalTokens)
.reduce<Map<string, T>>((map, item) => {
map.set(getHash(item), item);

return map;
}, new Map()),
return map;
}, new Map()),
})),
publishReplay(1),
refCount(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ const defaultTokenListItemToAssetInfo = (
name: dtli?.name || ac.name,
ticker: dtli?.ticker || ac.name,
decimals: dtli?.decimals || 0,
icon: dtli?.subject
? `${applicationConfig.networksSettings.cardano.metadataUrl}/${dtli?.subject}.png`
: '',
icon:
dtli?._logo || dtli?.subject
? `${applicationConfig.networksSettings.cardano.metadataUrl}/${dtli?.subject}.png`
: '',
url: dtli?.url || undefined,
data: ac,
};
Expand Down
2 changes: 2 additions & 0 deletions src/network/cardano/api/common/defaultTokenList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export interface DefaultTokenListItem {
readonly name: string;
readonly ticker: string;
readonly decimals: number;
readonly _logo?: string;
}

export const defaultTokenList$ = getDefaultTokenList<DefaultTokenListItem>(
applicationConfig.networksSettings.cardano.defaultTokenListUrl,
(item) => {
return item.subject;
},
applicationConfig.networksSettings.cardano.additionalTokenList,
);

0 comments on commit 9a074e1

Please sign in to comment.