Skip to content

Commit

Permalink
Refactor: currency utils tokenPrice debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rdig committed Jan 22, 2025
1 parent f1f5b7e commit 21c688d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/utils/currency/tokenPriceByAddress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SupportedCurrencies } from '~gql';
import { Network } from '~types/network.ts';
import debugLogging from '~utils/debug/debugLogging.ts';

import { currencyApiConfig, coinGeckoMappings } from './config.ts';
import {
Expand Down Expand Up @@ -41,8 +42,8 @@ const extractAddressPriceFromResponse = (
mapToAPIFormat(currencies, conversionDenomination)
];
} catch (e) {
console.error(
'Could not get contract price from CoinGecko response. Response shape might have changed.',
debugLogging(
'CoinGecko: Could not get contract price from response. Response shape might have changed.',
e,
);
return 0;
Expand Down Expand Up @@ -89,8 +90,8 @@ export const fetchTokenPriceByAddress = async ({
);
}

console.error(
`Unable to get price for ${contractAddress}. It probably doesn't have a listed exchange value.`,
debugLogging(
`CoinGecko: Unable to get price for ${contractAddress}. It probably doesn't have a listed exchange value.`,
);
return 0;
});
Expand Down
11 changes: 6 additions & 5 deletions src/utils/currency/tokenPriceByName.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SupportedCurrencies } from '~gql';
import debugLogging from '~utils/debug/debugLogging.ts';

import { currencyApiConfig, coinGeckoMappings } from './config.ts';
import {
Expand Down Expand Up @@ -36,8 +37,8 @@ const extractTokenPriceFromResponse = (
mapToAPIFormat(currencies, conversionDenomination)
];
} catch (e) {
console.error(
'Could not get token price from CoinGecko response. Response shape might have changed.',
debugLogging(
'CoinGecko: Could not get token price from response. Response shape might have changed.',
e,
);
return 0;
Expand Down Expand Up @@ -80,14 +81,14 @@ export const fetchTokenPriceByName = async ({
);
}

console.error(
`Unable to get price for ${tokenName}. It probably doesn't have a listed exchange value.`,
debugLogging(
`CoinGecko: Unable to get price for ${tokenName}. It probably doesn't have a listed exchange value.`,
);
return 0;
});
} catch (e) {
if (import.meta.env.DEV) {
console.error(e);
debugLogging(e);
}
return 0;
}
Expand Down
11 changes: 6 additions & 5 deletions src/utils/currency/tokenPriceDataByName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fromUnixTime from 'date-fns/fromUnixTime';

import { SupportedCurrencies } from '~gql';
import debugLogging from '~utils/debug/debugLogging.ts';

import { currencyApiConfig, coinGeckoMappings } from './config.ts';
import {
Expand Down Expand Up @@ -51,8 +52,8 @@ const extractTokenPriceDataFromResponse = (
lastUpdatedAt: fromUnixTime(tokenData.last_updated_at),
};
} catch (e) {
console.error(
'Could not get token price from CoinGecko response. Response shape might have changed.',
debugLogging(
'CoinGecko: Could not get token price from response. Response shape might have changed.',
e,
);
return fallbackResponseData;
Expand Down Expand Up @@ -95,14 +96,14 @@ export const fetchTokenPriceDataByName = async ({
);
}

console.error(
`Unable to get price for ${tokenName}. It probably doesn't have a listed exchange value.`,
debugLogging(
`CoinGecko: Unable to get price for ${tokenName}. It probably doesn't have a listed exchange value.`,
);
return fallbackResponseData;
});
} catch (e) {
if (!import.meta.env.DEV) {
console.error(e);
debugLogging(e);
}
return fallbackResponseData;
}
Expand Down

0 comments on commit 21c688d

Please sign in to comment.