Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.sortImports": "explicit"
},
"cSpell.words": ["sovryn"]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { keepPreviousData, useQuery } from '@tanstack/react-query';

import dayjs from 'dayjs';

Expand All @@ -12,7 +12,6 @@ import { useAccount } from '../../../../../../hooks/useAccount';
import { useBlockNumber } from '../../../../../../hooks/useBlockNumber';
import { useLoadContract } from '../../../../../../hooks/useLoadContract';
import { queryRate } from '../../../../../../utils/calls';
import { useGetActiveLoansQuery } from '../../../../../../utils/graphql/rsk/generated';
import { decimalic } from '../../../../../../utils/math';
import {
calculateApr,
Expand All @@ -30,35 +29,19 @@ const unsafeOnly = false;

export const useGetOpenLoans = () => {
const { account } = useAccount();
const { value: blockNumber } = useBlockNumber();
const [processedBlock, setProcessedBlock] = useState<number | undefined>();
const blockNumber = useBlockNumber();
Comment thread
creed-victor marked this conversation as resolved.
Outdated
const contract = useLoadContract('protocol', 'protocol', RSK_CHAIN_ID);
const [loadingLoans, setLoadingLoans] = useState(false);
const [loanItemsSmartContract, setLoanItemsSmartContract] = useState<
LoanItem[]
>([]);

const {
data,
loading: loadingSubgraph,
refetch,
} = useGetActiveLoansQuery({
variables: { user: account },
});

const loading = useMemo(
() => loadingLoans || loadingSubgraph,
[loadingLoans, loadingSubgraph],
);

const getUserLoans = useCallback(async () => {
if (!account || !contract) {
setLoadingLoans(false);
return;
}

try {
setLoadingLoans(true);
data: loanItemsSmartContract,
isPending,
error,
} = useQuery({
queryKey: ['userLoans', { account, blockNumber }],
queryFn: async () => {
if (!account || !contract) {
return [];
}
const loans = await contract.getUserLoans(
account,
start,
Expand All @@ -69,7 +52,7 @@ export const useGetOpenLoans = () => {
);

if (!loans) {
return;
return [];
}

const rates = await mapRates(loans);
Expand Down Expand Up @@ -125,29 +108,17 @@ export const useGetOpenLoans = () => {
.filter(Boolean)
.filter(item => isSupportedPool(item.debtAsset, item.collateralAsset));

setLoanItemsSmartContract(result);
setProcessedBlock(blockNumber);
} catch (error) {
console.error(`Error while fetching loans: ${error}`);
} finally {
setLoadingLoans(false);
}
}, [account, blockNumber, contract]);

useEffect(() => {
if (blockNumber !== processedBlock) {
refetch();
getUserLoans();
}
}, [blockNumber, getUserLoans, processedBlock, refetch]);

if (!data?.loans || !contract || !loanItemsSmartContract) {
return { data: [], loading };
}
return result as LoanItem[];
},
enabled: !!account && !!contract,
placeholderData: keepPreviousData,
throwOnError: true,
Comment thread
creed-victor marked this conversation as resolved.
Outdated
});

return {
data: loanItemsSmartContract,
loading,
data: loanItemsSmartContract ?? [],
loading: isPending,
error,
};
};

Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/src/constants/infrastructure/bsc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Environments } from '../../types/global';

const rpc = {
[Environments.Mainnet]: 'wss://bsc.sovryn.app/mainnet/websocket',
[Environments.Testnet]: 'wss://bsc.sovryn.app/testnet/websocket',
[Environments.Mainnet]: 'https://bsc.sovryn.app/mainnet',
[Environments.Testnet]: 'https://bsc.sovryn.app/testnet',
};

export const BSC = {
Expand Down
14 changes: 11 additions & 3 deletions apps/frontend/src/utils/LendingPoolDictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class LendingPoolDictionary {
COMMON_SYMBOLS.DLLR,
new LendingPool(
COMMON_SYMBOLS.DLLR,
[COMMON_SYMBOLS.BTC, 'BPRO', COMMON_SYMBOLS.SOV],
[COMMON_SYMBOLS.BTC, 'BPRO', COMMON_SYMBOLS.SOV, COMMON_SYMBOLS.BOS],
false,
false,
),
Expand All @@ -22,6 +22,7 @@ export class LendingPoolDictionary {
COMMON_SYMBOLS.SOV,
'BPRO',
COMMON_SYMBOLS.DOC,
COMMON_SYMBOLS.BOS,
],
false,
false,
Expand All @@ -31,7 +32,7 @@ export class LendingPoolDictionary {
COMMON_SYMBOLS.XUSD,
new LendingPool(
COMMON_SYMBOLS.XUSD,
[COMMON_SYMBOLS.BTC, 'BPRO', COMMON_SYMBOLS.SOV],
[COMMON_SYMBOLS.BTC, 'BPRO', COMMON_SYMBOLS.SOV, COMMON_SYMBOLS.BOS],
true,
false,
),
Expand All @@ -40,7 +41,13 @@ export class LendingPoolDictionary {
COMMON_SYMBOLS.DOC,
new LendingPool(
COMMON_SYMBOLS.DOC,
[COMMON_SYMBOLS.BTC, COMMON_SYMBOLS.XUSD, 'BPRO', COMMON_SYMBOLS.SOV],
[
COMMON_SYMBOLS.BTC,
COMMON_SYMBOLS.XUSD,
'BPRO',
COMMON_SYMBOLS.SOV,
COMMON_SYMBOLS.BOS,
],
false,
false,
),
Expand All @@ -59,6 +66,7 @@ export class LendingPoolDictionary {
COMMON_SYMBOLS.XUSD,
COMMON_SYMBOLS.DOC,
COMMON_SYMBOLS.SOV,
COMMON_SYMBOLS.BOS,
],
false,
false,
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/utils/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const COMMON_SYMBOLS = {
ETH: 'ETH',
WBTC_OLD: 'WBTC.OLD',
USDT: 'USDT',
BOS: 'BOS',
};

export const compareAssets = (asset1?: string | null, asset2?: string | null) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/contracts/assets/rsk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const rsk: Array<AssetDetails> = [
},
{
symbol: 'BOS',
address: '0x3E3006896458F0ACfE79b57A1A0fe067B3a1ce6f',
address: '0x3e3006896458f0acfe79b57a1a0fe067b3a1ce6f',
name: 'BitcoinOS Token',
decimals: 18,
getIcon: async () => (await import('./icons/rsk/bos')).default,
Expand Down
7 changes: 7 additions & 0 deletions packages/contracts/src/contracts/assets/rskTestnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,11 @@ export const rskTestnet: Array<AssetDetails> = [
decimals: 18,
getIcon: async () => (await import('./icons/rsk/powa')).default,
},
{
symbol: 'BOS',
address: '0x0000000000000000000000000000000000000000',
Comment thread
creed-victor marked this conversation as resolved.
Outdated
name: 'BitcoinOS Token',
decimals: 18,
getIcon: async () => (await import('./icons/rsk/bos')).default,
},
];