Skip to content

Commit

Permalink
adding safeguard in case maps file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
pellicceama committed Nov 12, 2022
1 parent 85298f3 commit 2ba23ac
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/repo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,18 @@ export function addAssetMap(map: AssetMap, repoPath: string = DEFAULT_REPO_DISK_
const assetDir = path.join(repoPath, getDirPathForTokenlist(map.fromNetwork, map.fromAddress));
const assetMapInfoFile = path.join(assetDir, 'maps.json');

if(fs.existsSync(assetDir) && !fs.existsSync(assetMapInfoFile)) {
fs.writeFileSync(assetMapInfoFile, JSON.stringify([map.deserialise()]), null, 2);
if(!fs.existsSync(assetDir)) {
throw new Error(`Cannot add map to ${assetDir} as it does not exist`)
}

if(!fs.existsSync(assetMapInfoFile)) {
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
Expand Down

0 comments on commit 2ba23ac

Please sign in to comment.