Skip to content

Commit

Permalink
implementing getAssetMaps function
Browse files Browse the repository at this point in the history
  • Loading branch information
pellicceama committed Nov 3, 2022
1 parent bd1671a commit cd8ea67
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/model/AssetMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -14,4 +16,4 @@
}
}

export type MapType = 'direct_issuance' | 'bridged' | 'wrapped';
export type MapType = 'direct_issuance' | 'bridged' | 'wrapped' | 'coinmarketcap';
19 changes: 17 additions & 2 deletions src/repo/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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));
}

0 comments on commit cd8ea67

Please sign in to comment.