Skip to content

Commit

Permalink
tweaking construction and deserialisation map functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pellicceama committed Nov 12, 2022
1 parent 2386a77 commit 85298f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/model/AssetMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

export class AssetMap extends RepoObject {

fromAddress: string;
fromAddress?: string;
fromNetwork: string;
toAddress: string;
toAddress?: string;
toNetwork: string;
type: MapType;

Expand Down
11 changes: 8 additions & 3 deletions src/repo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,22 @@ export function addAssetMap(map: AssetMap, repoPath: string = DEFAULT_REPO_DISK_
const assetMapInfoFile = path.join(assetDir, 'maps.json');

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

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


const existingMap = assetMaps.find(_map => _map.fromAddress === map.fromAddress && _map.fromNetwork === map.fromNetwork && _map.toAddress === map.toAddress && _map.toNetwork === map.toNetwork);
const existingMap = assetMaps.find(
_map => _map.fromAddress === map.fromAddress
&& _map.fromNetwork === map.fromNetwork
&& _map.toAddress === map.toAddress
&& _map.toNetwork === map.toNetwork);

if(!existingMap) {
assetMaps.push(map);
fs.writeFileSync(assetMapInfoFile, JSON.stringify(assetMaps, null, 2));
fs.writeFileSync(assetMapInfoFile, JSON.stringify(assetMaps.map(m => m.deserialise()), null, 2));
}
}

0 comments on commit 85298f3

Please sign in to comment.