Skip to content

Commit

Permalink
Merge pull request #1106 from mars-protocol/develop
Browse files Browse the repository at this point in the history
v2.6.11
  • Loading branch information
linkielink authored Sep 5, 2024
2 parents 3fabe8c + ccb35fb commit 3986833
Show file tree
Hide file tree
Showing 8 changed files with 488 additions and 444 deletions.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"dependencies": {
"@cosmjs/cosmwasm-stargate": "^0.32.4",
"@delphi-labs/shuttle-react": "^3.29.0",
"@keplr-wallet/cosmos": "^0.12.123",
"@keplr-wallet/cosmos": "^0.12.125",
"@tailwindcss/container-queries": "^0.1.1",
"@tanstack/react-table": "^8.20.5",
"@tippyjs/react": "^4.2.6",
"axios": "^1.7.5",
"axios": "^1.7.7",
"bignumber.js": "^9.1.2",
"classnames": "^2.5.1",
"debounce-promise": "^3.1.2",
Expand All @@ -35,7 +35,7 @@
"lodash.throttle": "^4.1.1",
"mobx": "^6.13.1",
"moment": "^2.30.1",
"next": "^14.2.6",
"next": "^14.2.7",
"react": "18.3.1",
"react-device-detect": "^2.2.3",
"react-dom": "^18.3.1",
Expand All @@ -59,31 +59,31 @@
"@types/debounce-promise": "^3.1.9",
"@types/lodash.debounce": "^4.0.9",
"@types/lodash.throttle": "^4.1.9",
"@types/node": "^22.5.0",
"@types/react": "18.3.4",
"@types/node": "^22.5.3",
"@types/react": "18.3.5",
"@types/react-dom": "18.3.0",
"@types/react-helmet": "^6.1.11",
"@typescript-eslint/eslint-plugin": "^8.2.0",
"@typescript-eslint/parser": "^8.2.0",
"@typescript-eslint/eslint-plugin": "^8.4.0",
"@typescript-eslint/parser": "^8.4.0",
"autoprefixer": "^10.4.20",
"dotenv": "^16.4.5",
"dotenv-cli": "^7.4.2",
"eslint": "^9.9.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-functional": "^7.0.2",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react": "^7.35.2",
"eslint-plugin-react-hooks": "^4.6.2",
"husky": "^9.1.5",
"identity-obj-proxy": "^3.0.0",
"lint-staged": "^15.2.9",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.6",
"shelljs": "^0.8.5",
"tailwindcss": "^3.4.10",
"typescript": "^5.5.4",
"typescript-eslint": "^8.2.0"
"typescript-eslint": "^8.4.0"
},
"engines": {
"npm": "please-use-yarn",
Expand Down
5 changes: 3 additions & 2 deletions src/api/campaign/getCampaignApys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { convertAprToApy } from 'utils/parsers'

function processApyData(aprOrApy: number, isApr: boolean, isPercent: boolean): number {
if (!isApr && isPercent) return aprOrApy
const apy = isApr ? convertAprToApy(aprOrApy, 365) : aprOrApy
return isPercent ? apy : apy * 100
const percentApr = isPercent ? aprOrApy : aprOrApy * 100
const apy = isApr ? convertAprToApy(percentApr, 365) : percentApr
return apy
}

export default async function getCampaignApys(
Expand Down
55 changes: 42 additions & 13 deletions src/components/Modals/AssetsSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ interface Props {
nonCollateralTableAssets?: Asset[]
}

export default function AssetsSelect({
onChangeSelected,
selectedDenoms,
isBorrow,
assets,
nonCollateralTableAssets,
}: Props) {
export default function AssetsSelect(props: Props) {
const { onChangeSelected, isBorrow, assets, nonCollateralTableAssets, selectedDenoms } = props
const columns = useAssetSelectColumns(isBorrow)
const markets = useMarkets()
const whitelistedAssets = useWhitelistedAssets()
Expand Down Expand Up @@ -69,15 +64,41 @@ export default function AssetsSelect({
return { whitelistedData, nonCollateralData }
}, [assets, nonCollateralTableAssets, whitelistedAssets, balances, createTableData])

const [whitelistedSelected, setWhitelistedSelected] = useState<RowSelectionState>({})
const [nonCollateralSelected, setNonCollateralSelected] = useState<RowSelectionState>({})
const [initialSelected, initialNonCollateralSelected] = useMemo(() => {
const selectionState = (
selectedDenoms: string[],
tableData: AssetTableRow[],
): RowSelectionState => {
const selectionState = {} as RowSelectionState
tableData.forEach((row, index) => {
selectionState[index.toString()] = !!selectedDenoms.includes(row.asset.denom)
})
return selectionState
}

return [
selectionState(
selectedDenoms,
isAssetTableRowArray(tableData) ? tableData : tableData.whitelistedData,
),
selectionState(
selectedDenoms,
isAssetTableRowArray(tableData) ? [] : tableData.nonCollateralData,
),
]
}, [selectedDenoms, tableData])

const [whitelistedSelected, setWhitelistedSelected] = useState<RowSelectionState>(initialSelected)
const [nonCollateralSelected, setNonCollateralSelected] = useState<RowSelectionState>(
initialNonCollateralSelected,
)

useEffect(() => {
let newSelectedDenoms: string[]

if (Array.isArray(tableData)) {
newSelectedDenoms = assets
.filter((asset, index) =>
.filter((asset) =>
tableData.some((row, idx) => row.asset.denom === asset.denom && whitelistedSelected[idx]),
)
.map((asset) => asset.denom)
Expand Down Expand Up @@ -145,7 +166,7 @@ export default function AssetsSelect({
titleComponent={
<Text
size='xs'
className='p-4 font-semibold bg-black/20 text-white/60 border-b border-white/10'
className='p-4 font-semibold border-b bg-black/20 text-white/60 border-white/10'
>
Assets that can be used as collateral
</Text>
Expand All @@ -154,7 +175,7 @@ export default function AssetsSelect({
)}

{nonCollateralTableAssets.length === 0 && assets.length === 0 && (
<Callout type={CalloutType.INFO} className='mt-4 mx-4 text-white/60'>
<Callout type={CalloutType.INFO} className='mx-4 mt-4 text-white/60'>
No assets that match your search.
</Callout>
)}
Expand All @@ -179,7 +200,7 @@ export default function AssetsSelect({
titleComponent={
<Text
size='xs'
className='p-4 font-semibold bg-black/20 text-white/60 border-t border-b border-white/10'
className='p-4 font-semibold border-t border-b bg-black/20 text-white/60 border-white/10'
>
Non whitelisted assets, cannot be used as collateral
</Text>
Expand All @@ -189,3 +210,11 @@ export default function AssetsSelect({
</>
)
}

function isAssetTableRowArray(
tableData:
| AssetTableRow[]
| { whitelistedData: AssetTableRow[]; nonCollateralData: AssetTableRow[] },
): tableData is AssetTableRow[] {
return !('whitelistedData' in tableData)
}
6 changes: 4 additions & 2 deletions src/components/account/AccountFund/AccountFundRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ export default function AccountFundRow(props: Props) {
/>
{asset.campaigns.length > 0 &&
asset.campaigns.map((campaign, index) => (
<div className='flex justify-center w-full p-2 mt-4 border rounded border-white/20'>
<div
className='flex justify-center w-full p-2 mt-4 border rounded border-white/20'
key={index}
>
<AssetCampaignCopy
campaign={campaign}
asset={asset}
size='sm'
amount={props.amount}
withLogo
className='justify-center'
key={index}
/>
</div>
))}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/campaign.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { byDenom } from './array'
import { formatValue, getCoinValue } from './formatters'
import { byDenom } from 'utils/array'
import { formatValue, getCoinValue } from 'utils/formatters'

export function getDailyAccountPoints(
account: Account,
Expand Down
9 changes: 4 additions & 5 deletions src/utils/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ export function isNumber(value: unknown) {
return typeof value === 'number'
}

export const convertAprToApy = (apr: number, numberOfCompoundingPeriods: number): number => {
return ((1 + apr / 100 / numberOfCompoundingPeriods) ** numberOfCompoundingPeriods - 1) * 100
export const convertAprToApy = (apr: number, compoundFrequency: number): number => {
return ((1 + (apr * 0.01) / compoundFrequency) ** compoundFrequency - 1) * 100
}

export const convertApyToApr = (apy: number, numberOfCompoundingPeriods: number): number => {
const periodicRate = (1 + apy / 100) ** (1 / numberOfCompoundingPeriods) - 1
return periodicRate * numberOfCompoundingPeriods * 100
export const convertApyToApr = (apy: number, compoundFrequency: number): number => {
return (((apy / 100 + 1) ** (1 / compoundFrequency) - 1) * compoundFrequency) / 0.01
}

export const combineBNCoins = (coins: BNCoin[]): BNCoin[] => {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export function resolveMarketResponse(
return {
asset,
apy: {
borrow: convertAprToApy(Number(marketResponse.borrow_rate), 365) * 100,
deposit: convertAprToApy(Number(marketResponse.liquidity_rate), 365) * 100,
borrow: convertAprToApy(Number(marketResponse.borrow_rate) * 100, 365),
deposit: convertAprToApy(Number(marketResponse.liquidity_rate) * 100, 365),
},
debt: marketResponse.debt ?? BN_ZERO,
deposits: marketResponse.deposits ?? BN_ZERO,
Expand Down
Loading

0 comments on commit 3986833

Please sign in to comment.