From cd8ea67704c46137fc2cbfb19dd936bce800e56e Mon Sep 17 00:00:00 2001 From: Amadeo Pellicce Date: Thu, 3 Nov 2022 13:17:29 +0100 Subject: [PATCH] implementing getAssetMaps function --- src/model/AssetMap.ts | 8 +++++--- src/repo/index.ts | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/model/AssetMap.ts b/src/model/AssetMap.ts index 6dbfac1..844ce40 100644 --- a/src/model/AssetMap.ts +++ b/src/model/AssetMap.ts @@ -3,8 +3,10 @@ export class AssetMap extends RepoObject { - from: string; - to: string; + fromAddress: string; + fromNetwork: string; + toAddress: string; + toNetwork: string; type: MapType; deserialise(): string { @@ -14,4 +16,4 @@ } } - export type MapType = 'direct_issuance' | 'bridged' | 'wrapped'; \ No newline at end of file + export type MapType = 'direct_issuance' | 'bridged' | 'wrapped' | 'coinmarketcap'; \ No newline at end of file diff --git a/src/repo/index.ts b/src/repo/index.ts index 43069ec..70750b5 100644 --- a/src/repo/index.ts +++ b/src/repo/index.ts @@ -1,9 +1,11 @@ import { GITHUB_USER_CONTENT_BASE_URL, REPO_CLONE_URL } from '../utils/constants'; -import { getDirectories } from '../utils/filesystem'; +import { getDirectories, readAndParseJson } from '../utils/filesystem'; import { push } from '../utils/git'; import fs from 'fs'; -import { sortObjectKeys } from '../utils'; +import { formatAddress, sortObjectKeys } from '../utils'; +import path from 'path'; +import { AssetMap } from '../model'; export async function pushAssetsRepoModuleChangesAndCreatePullRequests(dir: string) { try { @@ -101,4 +103,17 @@ export async function addIdentifierToAsset(path: string, networkCode: string, ad return { addedIdentifier: true } +} + +export function getAssetMaps(networkCode: string, address: string): AssetMap[] { + const formattedAddress = formatAddress(address); + + const assetMapInfoFile = path.join(getDirPathForTokenlist(networkCode, formattedAddress), 'maps.json'); + + if(!fs.existsSync(assetMapInfoFile)) { + return []; + } + + return readAndParseJson(assetMapInfoFile) + .map(map => new AssetMap(map)); } \ No newline at end of file