Skip to content

Commit

Permalink
Merge pull request #463 from bvotteler/brendon/fix-no-throw-for-non-t…
Browse files Browse the repository at this point in the history
…oken-collateral-vault

fix: do not throw on dashboard for non-token collateral vault
  • Loading branch information
peterslany committed Aug 22, 2022
2 parents ff668d6 + 9ba6443 commit db4e4ea
Showing 1 changed file with 60 additions and 55 deletions.
115 changes: 60 additions & 55 deletions src/pages/Dashboard/sub-pages/Vaults/VaultsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,64 +271,69 @@ const VaultsTable = (): JSX.Element => {
collateralThresholds &&
currentActiveBlockNumber
) {
const rawVaults = filteredVaults.map((vaultExt) => {
const collateral = vaultExt.id.currencies.collateral;
if (collateral.isToken === false) {
throw new Error('Non token collateral is not supported!');
}
const collateralTokenSymbol = collateral.asToken.type as CollateralIdLiteral;

const collateralLiquidationThreshold = collateralThresholds[collateralTokenSymbol].liquidationThreshold;
const collateralSecureThreshold = collateralThresholds[collateralTokenSymbol].secureThreshold;
let btcToCollateralTokenRate: BTCToCollateralTokenRate;
switch (collateralTokenSymbol) {
case RELAY_CHAIN_NATIVE_TOKEN_SYMBOL: {
btcToCollateralTokenRate = btcToRelayChainNativeTokenRate;
break;
const rawVaults = filteredVaults
.filter((vaultExt) => {
if (vaultExt.id.currencies.collateral.isToken) {
return true;
}
case GOVERNANCE_TOKEN_SYMBOL: {
btcToCollateralTokenRate = btcToGovernanceTokenRate;
break;
console.warn("Unsupported non token collateral vault found and removed from vaults list");
return false;
})
.map((vaultExt) => {
const collateral = vaultExt.id.currencies.collateral;
const collateralTokenSymbol = collateral.asToken.type as CollateralIdLiteral;

const collateralLiquidationThreshold = collateralThresholds[collateralTokenSymbol].liquidationThreshold;
const collateralSecureThreshold = collateralThresholds[collateralTokenSymbol].secureThreshold;
let btcToCollateralTokenRate: BTCToCollateralTokenRate;
switch (collateralTokenSymbol) {
case RELAY_CHAIN_NATIVE_TOKEN_SYMBOL: {
btcToCollateralTokenRate = btcToRelayChainNativeTokenRate;
break;
}
case GOVERNANCE_TOKEN_SYMBOL: {
btcToCollateralTokenRate = btcToGovernanceTokenRate;
break;
}
default:
throw new Error('Something went wrong with collateralTokenType!');
}
default:
throw new Error('Something went wrong with collateralTokenType!');
}

const statusLabel = getVaultStatusLabel(
vaultExt,
currentActiveBlockNumber,
collateralLiquidationThreshold,
collateralSecureThreshold,
btcToCollateralTokenRate,
t
);

const vaultCollateral = vaultExt.backingCollateral;
const settledTokens = vaultExt.issuedTokens;
const settledCollateralization = getCollateralization(vaultCollateral, settledTokens, btcToCollateralTokenRate);
const unsettledTokens = vaultExt.toBeIssuedTokens;
const unsettledCollateralization = getCollateralization(
vaultCollateral,
unsettledTokens.add(settledTokens),
btcToCollateralTokenRate
);

return {
[Accessor.VaultId]: vaultExt.id.accountId.toString(),
[Accessor.Collateral]: collateralTokenSymbol,
// TODO: fetch collateral reserved
[Accessor.LockedCollateralTokenAmount]: `${displayMonetaryAmount(vaultCollateral)} ${collateralTokenSymbol}`,
[Accessor.LockedBTCAmount]: settledTokens,
[Accessor.PendingBTCAmount]: displayMonetaryAmount(unsettledTokens),
[Accessor.CollateralizationUI]: (
<CollateralizationCell
settledCollateralization={settledCollateralization}
unsettledCollateralization={unsettledCollateralization}
collateralSecureThreshold={collateralSecureThreshold}
/>
),
[Accessor.Status]: statusLabel
};
const statusLabel = getVaultStatusLabel(
vaultExt,
currentActiveBlockNumber,
collateralLiquidationThreshold,
collateralSecureThreshold,
btcToCollateralTokenRate,
t
);

const vaultCollateral = vaultExt.backingCollateral;
const settledTokens = vaultExt.issuedTokens;
const settledCollateralization = getCollateralization(vaultCollateral, settledTokens, btcToCollateralTokenRate);
const unsettledTokens = vaultExt.toBeIssuedTokens;
const unsettledCollateralization = getCollateralization(
vaultCollateral,
unsettledTokens.add(settledTokens),
btcToCollateralTokenRate
);

return {
[Accessor.VaultId]: vaultExt.id.accountId.toString(),
[Accessor.Collateral]: collateralTokenSymbol,
// TODO: fetch collateral reserved
[Accessor.LockedCollateralTokenAmount]: `${displayMonetaryAmount(vaultCollateral)} ${collateralTokenSymbol}`,
[Accessor.LockedBTCAmount]: settledTokens,
[Accessor.PendingBTCAmount]: displayMonetaryAmount(unsettledTokens),
[Accessor.CollateralizationUI]: (
<CollateralizationCell
settledCollateralization={settledCollateralization}
unsettledCollateralization={unsettledCollateralization}
collateralSecureThreshold={collateralSecureThreshold}
/>
),
[Accessor.Status]: statusLabel
};
});

const sortedVaults = rawVaults.sort((vaultA, vaultB) => {
Expand Down

2 comments on commit db4e4ea

@vercel
Copy link

@vercel vercel bot commented on db4e4ea Aug 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on db4e4ea Aug 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.