From aeee61d8c25c1d8e42595443b5ca1d64f195735d Mon Sep 17 00:00:00 2001 From: Amadeo Pellicce Date: Thu, 3 Nov 2022 18:30:15 +0100 Subject: [PATCH] improving add mapping defensiveness --- src/repo/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/repo/index.ts b/src/repo/index.ts index 7851b1a..dd49ab6 100644 --- a/src/repo/index.ts +++ b/src/repo/index.ts @@ -130,7 +130,10 @@ export function addAssetMap(map: AssetMap, repoPath: string = DEFAULT_REPO_DISK_ const assetMaps = readAndParseJson(assetMapInfoFile) .map(map => new AssetMap(map)); - assetMaps.push(map); - fs.writeFileSync(assetMapInfoFile, JSON.stringify(assetMaps, null, 2)); + 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)); + } } \ No newline at end of file