Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature fix other asset balance by wallet #112

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
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
Next Next commit
tmp/test
  • Loading branch information
BenoistP committed Dec 23, 2024
commit 4c57c2996584adcfc63e579a174fe58d553ba3b1
2 changes: 2 additions & 0 deletions src/components/assetsView/views/AssetTable.tsx
Original file line number Diff line number Diff line change
@@ -97,6 +97,8 @@ const AssetTableRow: FC<{ value: UserRealtoken }> = (props) => {
? useFullyRentedAPR(props.value as UserRealtoken)
: null

console.debug('props.value', props.value)

return (
<Table.Tr>
<Table.Td style={{ minWidth: '150px' }}>
17 changes: 17 additions & 0 deletions src/hooks/useRWA.ts
Original file line number Diff line number Diff line change
@@ -113,6 +113,23 @@ const getRWA = async (
timezone_type: 3,
timezone: 'UTC',
},
balance: {
gnosis: {
amount: 0,
value : 0,
},
ethereum: {
amount: 0,
value : 0,
},
rmm: {
amount: 0,
value : 0,
},
levinSwap: {
amount: 0,
value : 0,
},
}
}

7 changes: 7 additions & 0 deletions src/store/features/wallets/walletsSelector.ts
Original file line number Diff line number Diff line change
@@ -55,6 +55,13 @@ export interface OtherRealtoken {
imageLink: string[]
isRmmAvailable: boolean
unitPriceCost: number
balance: Record<
WalletType,
{
amount: number
value: number
}
>
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
10 changes: 10 additions & 0 deletions src/utils/blockchain/consts/otherTokens.ts
Original file line number Diff line number Diff line change
@@ -33,6 +33,12 @@ const WXDAItokenDecimals = 18

const HoneySwapFactory_Address = '0xA818b4F111Ccac7AA31D0BCc0806d64F2E0737D7'

const CHAIN_ID_GNOSIS_XDAI = 100
const CHAIN_ID_ETHEREUM = 1

const CHAIN_NAME_GNOSIS_XDAI = 'gnosis'
const CHAIN_NAME_ETHEREUM = 'ethereum'

export {
RWA_ContractAddress,
REG_ContractAddress,
@@ -54,4 +60,8 @@ export {
RWA_asset_ID,
REG_asset_ID,
REGVotingPower_asset_ID,
CHAIN_ID_GNOSIS_XDAI,
CHAIN_ID_ETHEREUM,
CHAIN_NAME_GNOSIS_XDAI,
CHAIN_NAME_ETHEREUM,
}
27 changes: 27 additions & 0 deletions src/utils/blockchain/erc20Infos.ts
Original file line number Diff line number Diff line change
@@ -2,15 +2,31 @@ import { Contract, JsonRpcProvider } from 'ethers'

import { getErc20AbiBalanceOfOnly } from 'src/utils/blockchain/ERC20'

import {
CHAIN_ID_ETHEREUM,
CHAIN_ID_GNOSIS_XDAI,
CHAIN_NAME_ETHEREUM,
CHAIN_NAME_GNOSIS_XDAI,
} from './consts/otherTokens'
import { batchCallOneContractOneFunctionMultipleParams } from './contract'

const getChainName = (chainId: number) => {
switch (chainId) {
case CHAIN_ID_ETHEREUM:
return CHAIN_NAME_ETHEREUM
case CHAIN_ID_GNOSIS_XDAI:
return CHAIN_NAME_GNOSIS_XDAI
}
}

const getAddressesBalances = async (
contractAddress: string,
addressList: string[],
providers: JsonRpcProvider[],
consoleWarnOnError = false,
) => {
let totalAmount = 0
const balancesByProvider: Record<string, number> = {}
try {
if (!contractAddress) {
consoleWarnOnError && console.error('Invalid contract address')
@@ -44,6 +60,17 @@ const getAddressesBalances = async (

const balancesArray = await Promise.all(balancesPromises.flat())
const balances = balancesArray.flat()
// Providers
providers.forEach((provider: JsonRpcProvider) => {
console.log('provider', provider?._network?.chainId)
const chainId = Number(provider?._network?.chainId)

balancesByProvider[(getChainName(chainId), 0)] = 0
})
console.log('addressList?.length', addressList?.length)
console.log('balancesArray?.length', balancesArray?.length)
console.log('(flat) balances?.length', balances?.length)

// Sum all valid balances
balances.forEach((balance: object | null | undefined) => {
try {