Skip to content

Commit

Permalink
fixing issue in addIdentifierToAsset
Browse files Browse the repository at this point in the history
  • Loading branch information
pellicceama committed Nov 2, 2022
1 parent e8d4208 commit 9fad9f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/repo/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import test from "ava";
import { getDirPathForTokenlist } from ".";

test("getDirPathForTokenlist calculates the correct directory", async (t) => {
const network = 'ethereum';
const address = '0x';

t.deepEqual(getDirPathForTokenlist(network, address), `/networks/ethereum/assets/${network}-tokenlist/${address}`);
});
10 changes: 6 additions & 4 deletions src/repo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getDirectories } from '../utils/filesystem';
import { push } from '../utils/git';
import fs from 'fs';
import { sortObjectKeys } from '../utils';
import path from 'path';

export async function pushAssetsRepoModuleChangesAndCreatePullRequests(dir: string) {
try {
Expand Down Expand Up @@ -65,14 +66,14 @@ export function getGithubHostedFileUrl (dir: string, fileName: string) {
}

export function getDirPathForNetworkCode (network: string) {
return `/networks/${network}`;
return path.join('networks', network);
}

export function getDirPathForTokenlist (network: string, address?: string) {
return getDirPathForNetworkCode(network) + `/assets/${network}-tokenlist` + (address ? `/${address}` : '');
return path.join(getDirPathForNetworkCode(network),'assets',`${network}-tokenlist`, (address ? `/${address}` : ''));
}

export async function addIdentifierToAsset(path: string, networkCode: string, address: string, identifierKey: string, identifierValue: string | number): Promise<{addedIdentifier: boolean}> {
export async function addIdentifierToAsset(dir: string, networkCode: string, address: string, identifierKey: string, identifierValue: string | number): Promise<{addedIdentifier: boolean}> {

const ALLOWED_IDENTIFIER_KEYS_FOR_ASSETS = [
'coinmarketcap'
Expand All @@ -82,9 +83,10 @@ export async function addIdentifierToAsset(path: string, networkCode: string, ad
throw new Error('Identifier key ' + identifierKey + ' is not allowed for assets');
}

const assetInfoFilePath = path + getDirPathForTokenlist(networkCode, address);
const assetInfoFilePath = path.join(dir, getDirPathForTokenlist(networkCode, address), 'info.json');

if(!fs.existsSync(assetInfoFilePath)) {
console.error('addIdentifierToAsset Cannot find asset info file for asset ' + address + ' in directory ' + dir);
return { addedIdentifier: false };
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/tcrs/kleros-tcr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export async function checkIfAssetInKlerosTCR(address: string): Promise<TcrCheck
}
}

// console.log('checkIfAssetInKlerosTCR Token', JSON.stringify(token));
return {
inTcr: token.status === 'Registered',
resolutionTxHash: token.requests[0].resolutionTx
Expand Down

0 comments on commit 9fad9f9

Please sign in to comment.