Skip to content

Commit

Permalink
adding addAssetMap function and tweaking AssetMap constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
pellicceama committed Nov 3, 2022
1 parent ec99731 commit 86f0f34
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/model/AssetMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
toNetwork: string;
type: MapType;

constructor({ fromAddress, fromNetwork, toAddress, toNetwork, type }: AssetMap) {
super({});
this.fromAddress = fromAddress;
this.fromNetwork = fromNetwork;
this.toAddress = toAddress;
this.toNetwork = toNetwork;
this.type = type;
}

deserialise(): string {
let parsed = JSON.parse(JSON.stringify(this));
parsed = sortObjectKeys(parsed);
Expand Down
18 changes: 17 additions & 1 deletion src/repo/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { GITHUB_USER_CONTENT_BASE_URL, REPO_CLONE_URL } from '../utils/constants';
import { DEFAULT_REPO_DISK_LOCATION, GITHUB_USER_CONTENT_BASE_URL, REPO_CLONE_URL } from '../utils/constants';
import { getDirectories, readAndParseJson } from '../utils/filesystem';
import { push } from '../utils/git';
import fs from 'fs';
Expand Down Expand Up @@ -116,4 +116,20 @@ export function getAssetMaps(networkCode: string, address: string): AssetMap[] {

return readAndParseJson(assetMapInfoFile)
.map(map => new AssetMap(map));
}

export function addAssetMap(map: AssetMap, repoPath: string = DEFAULT_REPO_DISK_LOCATION) {
const assetMapInfoFile = path.join(repoPath, getDirPathForTokenlist(map.fromNetwork, map.fromAddress), 'maps.json');

if(!fs.existsSync(assetMapInfoFile)) {
fs.writeFileSync(assetMapInfoFile, JSON.stringify([map], null, 2));
return;
}

const assetMaps = readAndParseJson(assetMapInfoFile)
.map(map => new AssetMap(map));

assetMaps.push(map);

fs.writeFileSync(assetMapInfoFile, JSON.stringify(assetMaps, null, 2));
}

0 comments on commit 86f0f34

Please sign in to comment.