Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apps/web/src/store/collateral/filterCollateralTokens.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import assert from 'node:assert/strict';
import test from 'node:test';

import { filterCollateralTokensByDebtLimit } from './filterCollateralTokens';

test('only returns collateral tokens with a zero debt limit', () => {
const collateralTokens = {
sICX: 'cx-sicx',
BTCB: 'cx-btcb',
NEW: 'cx-new',
};

assert.deepEqual(filterCollateralTokensByDebtLimit(collateralTokens, [0, 0, 100]), {
sICX: 'cx-sicx',
BTCB: 'cx-btcb',
});
});
15 changes: 15 additions & 0 deletions apps/web/src/store/collateral/filterCollateralTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function filterCollateralTokensByDebtLimit(
collateralTokens: Record<string, string>,
debtLimits: number[],
): Record<string, string> {
return Object.keys(collateralTokens).reduce(
(supportedTokens, symbol, index) => {
if (debtLimits[index] === 0) {
supportedTokens[symbol] = collateralTokens[symbol];
}

return supportedTokens;
},
{} as Record<string, string>,
);
}
11 changes: 2 additions & 9 deletions apps/web/src/store/collateral/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { XChainId } from '@balancednetwork/xwagmi';
import { useXTransactionStore } from '@balancednetwork/xwagmi';
import { bnJs } from '@balancednetwork/xwagmi';
import { AppState } from '../index';
import { filterCollateralTokensByDebtLimit } from './filterCollateralTokens';
import {
Field,
adjust,
Expand Down Expand Up @@ -399,15 +400,7 @@ export function useSupportedCollateralTokens(): UseQueryResult<{ [key in string]

const debtCeilings = debtCeilingsData.map(ceiling => (ceiling === null ? 1 : parseInt(formatUnits(ceiling))));

const supportedTokens = {};
Object.keys(data).forEach((symbol, index) => {
//temporarily allow BTCB with 0 debt ceiling
if (debtCeilings[index] > 0 || symbol === 'BTCB') {
supportedTokens[symbol] = data[symbol];
}
});

return supportedTokens;
return filterCollateralTokensByDebtLimit(data, debtCeilings);
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/xwagmi/src/constants/xTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const xTokenMap: { [key in XChainId]: XToken[] } = {
56,
'0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c',
18,
'BTCB',
'BTC',
'Binance-Peg BTCB Token',
'BTC1',
),
Expand Down