Skip to content

Commit

Permalink
Merge branch 'master' into gc-apps
Browse files Browse the repository at this point in the history
  • Loading branch information
nohaapav committed Mar 12, 2024
2 parents e25e282 + a545666 commit b6f6d4d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 16 deletions.
18 changes: 13 additions & 5 deletions src/api/accountBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import { useQuery } from "@tanstack/react-query"
import { QUERY_KEYS } from "utils/queryKeys"
import { ApiPromise } from "@polkadot/api"
import { Maybe, undefinedNoop } from "utils/helpers"
import { u32 } from "@polkadot/types"
import { u32, u128 } from "@polkadot/types"
import { PalletBalancesAccountData } from "@polkadot/types/lookup"
import { BN } from "@polkadot/util"
interface PalletBalancesAccountDataCustom extends PalletBalancesAccountData {
frozen: u128
}

export const useAccountBalances = (id: Maybe<AccountId32 | string>) => {
const api = useApiPromise()
Expand Down Expand Up @@ -65,10 +69,14 @@ const getTokenAccountBalancesList =
const [, assetId] = pairs[idx]

if (assetId.toString() === NATIVE_ASSET_ID) {
let {data} = natives[nativeIdx]
const frozen = data.feeFrozen ? data.feeFrozen.add(
data.miscFrozen,
) : data.frozen
//@ts-ignore
let { data }: { data: PalletBalancesAccountDataCustom } =
natives[nativeIdx]

const frozen = data.feeFrozen
? data.feeFrozen.add(data.miscFrozen)
: data.frozen

values.push({
free: data.free,
reserved: data.reserved,
Expand Down
14 changes: 11 additions & 3 deletions src/api/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ export const getTokenBalance =
(api: ApiPromise, account: AccountId32 | string, id: string | u32) =>
async () => {
if (id.toString() === NATIVE_ASSET_ID) {
const res = await api.query.system.account(account)
const res = (await api.query.system.account(account)) as any
const freeBalance = new BigNumber(res.data.free.toHex())
const miscFrozenBalance = new BigNumber(res.data.miscFrozen ? res.data.miscFrozen.toHex() : res.data.frozen.toHex())
const feeFrozenBalance = new BigNumber(res.data.feeFrozen ? res.data.feeFrozen.toHex() : res.data.frozen.toHex())
const miscFrozenBalance = new BigNumber(
res.data.miscFrozen
? res.data.miscFrozen.toHex()
: res.data.frozen.toHex(),
)
const feeFrozenBalance = new BigNumber(
res.data.feeFrozen
? res.data.feeFrozen.toHex()
: res.data.frozen.toHex(),
)
const reservedBalance = new BigNumber(res.data.reserved.toHex())

const balance = new BigNumber(
Expand Down
2 changes: 1 addition & 1 deletion src/api/farms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export const getGlobalFarm = (api: ApiPromise, id: u32) => async () => {
}

export interface FarmIds {
poolId: AccountId32
poolId: AccountId32 | string
globalFarmId: u32
yieldFarmId: u32
}
2 changes: 1 addition & 1 deletion src/i18n/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
"fund.modal.crypto.buy": "Use cross-chain",
"fund.button": "Fund wallet",
"depeg.modal.title": "Important Notice",
"depeg.modal.desx": "Tether have dropped support for native USDT on Kusama - herefore USDT pools are currently not priced at $1",
"depeg.modal.desx": "Tether have dropped support for native USDT on Kusama - thefore USDT pools are currently not priced at $1",
"depeg.modal.desx.crossChain": "Cross chain transfers in Kusama are temporarily suspended, please do not try to send tokens",
"depeg.modal.icon": "More info"
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export const MyPositionsList = ({ pool, onClose }: Props) => {
onClose={onClose}
/>
))
}, [depositNftList, pool])
}, [depositNftList, onClose, pool])
return <div sx={{ flex: "column", gap: 8 }}>{positionsList}</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,16 @@ const getNativeBalances = (
const dp = BN_10.pow(decimals)
const free = balance.free.toBigNumber()
const reservedBN = balance.reserved.toBigNumber()
const feeFrozen = balance.feeFrozen ? balance.feeFrozen.toBigNumber() : balance.frozen.toBigNumber()
const miscFrozen = balance.miscFrozen ? balance.miscFrozen.toBigNumber() : balance.frozen.toBigNumber()

const feeFrozen = balance.feeFrozen
? balance.feeFrozen.toBigNumber()
: //@ts-ignore
balance.frozen.toBigNumber()

const miscFrozen = balance.miscFrozen
? balance.miscFrozen.toBigNumber()
: //@ts-ignore
balance.frozen.toBigNumber()

const total = free.plus(reservedBN).div(dp)
const totalUSD = total.times(spotPrice)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/farms/apr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const useAPR = (poolId: AccountId32 | string) => {
// all of the APR calculations are using only half of the position -
// this is correct in terms of inputs but for the user,
// they are not depositing only half of the position, they are depositing 2 assets
apr = globalFarm.id.toString() === '5'? BN_0: apr.div(2)
apr = globalFarm.id.toString() === "5" ? BN_0 : apr.div(2)
const minApr = apr.times(loyaltyFactor)

// max distribution of rewards
Expand Down
6 changes: 4 additions & 2 deletions src/utils/farms/positions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ export const useTotalInPositions = () => {
({ position: { yieldFarmId, globalFarmId }, poolId }) => ({
yieldFarmId: yieldFarmId,
globalFarmId: globalFarmId,
poolId,
poolId: poolId.toString(),
}),
) ?? [],
)
const shareTokens = usePoolShareTokens(
deposits.data?.deposits?.map(({ deposit }) => deposit.ammPoolId) ?? [],
deposits.data?.deposits?.map(({ deposit }) =>
deposit.ammPoolId.toString(),
) ?? [],
)
const totalIssuances = useTotalIssuances(
shareTokens.map((st) => st.data?.token),
Expand Down

0 comments on commit b6f6d4d

Please sign in to comment.