This commit is contained in:
Linkie Link 2023-06-08 10:18:17 +02:00
parent e769b42cf5
commit 3de11356d4
No known key found for this signature in database
GPG Key ID: 5318B0F2564D38EA
11 changed files with 72 additions and 65 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "mars", "name": "mars",
"homepage": "./", "homepage": "./",
"version": "1.4.7", "version": "1.4.8",
"license": "SEE LICENSE IN LICENSE FILE", "license": "SEE LICENSE IN LICENSE FILE",
"private": false, "private": false,
"scripts": { "scripts": {

View File

@ -20,7 +20,7 @@ export const CellAmount = ({ denom, decimals, amount, noBalanceText }: Props) =>
<p className='m'> <p className='m'>
<AnimatedNumber <AnimatedNumber
amount={assetAmount > 0 && assetAmount < 0.01 ? 0.01 : assetAmount} amount={assetAmount > 0 && assetAmount < 0.01 ? 0.01 : assetAmount}
suffix={assetAmount > 0 && assetAmount < 0.01 ? '< ' : false} prefix={assetAmount > 0 && assetAmount < 0.01 ? '< ' : false}
/> />
</p> </p>
{amount === 0 ? ( {amount === 0 ? (

View File

@ -1,36 +1,47 @@
@import 'src/styles/master'; @import 'src/styles/master';
.container { .wrapper {
display: flex; position: relative;
align-items: center;
cursor: pointer;
.checkbox { .checkbox {
appearance: none; display: none;
margin-right: space(3);
&:checked {
& + .label:after {
transform: scale(1);
}
}
}
.label {
display: flex;
align-items: center;
cursor: pointer; cursor: pointer;
@include padding(4, 0, 0, 6);
font: inherit; &:before {
width: 1rem;
height: 1rem;
border: 1.5px solid $alphaWhite40;
border-radius: $borderRadiusXS;
display: grid;
place-content: center;
&::before {
content: ''; content: '';
width: 0.5rem; width: space(3);
height: 0.5rem; height: space(3);
border: 1.5px solid $alphaWhite40;
border-radius: $borderRadiusXS;
position: absolute;
top: space(5);
left: 0;
}
&:after {
content: '';
width: space(2);
height: space(2);
clip-path: polygon(14% 44%, 0% 65%, 40% 95%, 100% 26%, 85% 10%, 38% 62%); clip-path: polygon(14% 44%, 0% 65%, 40% 95%, 100% 26%, 85% 10%, 38% 62%);
transform: scale(0); transform: scale(0);
transform-origin: center center; transform-origin: center center;
transition: 100ms transform ease-in-out; transition: 100ms transform ease-in-out;
box-shadow: inset 1rem 1rem $colorWhite; box-shadow: inset space(3) space(3) $colorWhite;
} position: absolute;
top: space(6);
&:checked::before { left: space(1);
transform: scale(1);
} }
} }
} }

View File

@ -1,4 +1,5 @@
import React, { useState } from 'react' import classNames from 'classnames'
import { useState } from 'react'
import styles from './Checkbox.module.scss' import styles from './Checkbox.module.scss'
@ -6,6 +7,7 @@ interface Props {
text: string text: string
className?: string className?: string
onChecked: (isChecked: boolean) => void onChecked: (isChecked: boolean) => void
name?: string
} }
export const Checkbox = (props: Props) => { export const Checkbox = (props: Props) => {
@ -16,9 +18,17 @@ export const Checkbox = (props: Props) => {
props.onChecked(!isChecked) props.onChecked(!isChecked)
} }
return ( return (
<label className={`${props.className} ${styles.container}`}> <div className={styles.wrapper}>
<input type='checkbox' onChange={handleChange} className={styles.checkbox} /> <input
{props.text} type='checkbox'
</label> onChange={handleChange}
className={styles.checkbox}
name={`${props.name}-checkbox`}
id={props.name}
/>
<label htmlFor={props.name} className={classNames(props.className, styles.label)}>
{props.text}
</label>
</div>
) )
} }

View File

@ -14,20 +14,15 @@
.card { .card {
max-width: min(rem-calc(500), 95vw); max-width: min(rem-calc(500), 95vw);
@include padding(2, 4, 4, 4); @include padding(2, 4, 8, 4);
max-height: 100vh;
overflow-y: auto;
.subtitle { .subtitle {
text-align: center; text-align: center;
@include padding(4, 0, 0, 0); @include padding(4, 0, 0, 0);
} }
.checkbox {
display: grid;
grid-template-columns: auto auto;
align-items: baseline;
@include margin(4, 0);
}
.btn { .btn {
@include margin(6, 0, 0); @include margin(6, 0, 0);
width: 100%; width: 100%;

View File

@ -42,11 +42,13 @@ export const TermsOfService = () => {
className={styles.checkbox} className={styles.checkbox}
onChecked={(isChecked) => setIsFirstAccepted(isChecked)} onChecked={(isChecked) => setIsFirstAccepted(isChecked)}
text={t('common.termsOfService.term1')} text={t('common.termsOfService.term1')}
name='term1'
/> />
<Checkbox <Checkbox
className={styles.checkbox} className={styles.checkbox}
onChecked={(isChecked) => setIsSecondAccepted(isChecked)} onChecked={(isChecked) => setIsSecondAccepted(isChecked)}
text={t('common.termsOfService.term2')} text={t('common.termsOfService.term2')}
name='term2'
/> />
<Button <Button
onClick={onTermsConfirmed} onClick={onTermsConfirmed}

View File

@ -16,7 +16,7 @@ export const Apy = ({ apyData, leverage, borrowRate }: Props) => {
const totalApy = useMemo( const totalApy = useMemo(
() => (apyData.total ?? 0) * leverage - borrowRate ?? 0, () => (apyData.total ?? 0) * leverage - borrowRate ?? 0,
[apyData, leverage], [apyData, leverage, borrowRate],
) )
const leveragedApy = useMemo(() => (apyData.total ?? 0) * leverage, [apyData, leverage]) const leveragedApy = useMemo(() => (apyData.total ?? 0) * leverage, [apyData, leverage])
const performanceFee = apyData.fees && apyData.fees[0].value > 0 ? apyData.fees[0] : null const performanceFee = apyData.fees && apyData.fees[0].value > 0 ? apyData.fees[0] : null

View File

@ -85,7 +85,6 @@ export const Action = ({
const convertToBaseCurrency = useStore((s) => s.convertToBaseCurrency) const convertToBaseCurrency = useStore((s) => s.convertToBaseCurrency)
const findUserDebt = useStore((s) => s.findUserDebt) const findUserDebt = useStore((s) => s.findUserDebt)
const enableAnimations = useStore((s) => s.enableAnimations) const enableAnimations = useStore((s) => s.enableAnimations)
const baseCurrencyDecimals = useStore((s) => s.baseCurrency.decimals)
// ------------------ // ------------------
// LOCAL STATE // LOCAL STATE
@ -135,7 +134,6 @@ export const Action = ({
amount * currentAssetPrice, // amount in display currency amount * currentAssetPrice, // amount in display currency
activeView, activeView,
relevantBalanceKey, relevantBalanceKey,
baseCurrencyDecimals,
), ),
[ [
activeView, activeView,
@ -145,7 +143,6 @@ export const Action = ({
denom, denom,
redBankAssets, redBankAssets,
relevantBalanceKey, relevantBalanceKey,
baseCurrencyDecimals,
], ],
) )
@ -157,7 +154,6 @@ export const Action = ({
0.0, 0.0,
activeView, activeView,
relevantBalanceKey, relevantBalanceKey,
baseCurrencyDecimals,
), ),
relevantBalanceKey, relevantBalanceKey,
) )
@ -231,11 +227,18 @@ export const Action = ({
.shiftedBy(baseCurrency.decimals - (currentAsset?.decimals || 0)) .shiftedBy(baseCurrency.decimals - (currentAsset?.decimals || 0))
.toNumber(), .toNumber(),
) )
}, [denom, availableBalanceBaseCurrency, currentAssetPrice, marketAssetLiquidity]) }, [
denom,
availableBalanceBaseCurrency,
currentAssetPrice,
marketAssetLiquidity,
baseCurrency.decimals,
currentAsset?.decimals,
])
const repayMax = useMemo((): number => { const repayMax = useMemo((): number => {
return Math.min(assetBorrowBalance, walletBalance) return Math.min(assetBorrowBalance, walletBalance)
}, [assetBorrowBalance, walletBalance, denom, baseCurrency.denom]) }, [assetBorrowBalance, walletBalance])
const maxWithdrawableAmount = useMemo((): number => { const maxWithdrawableAmount = useMemo((): number => {
const assetLtvRatio = findByDenom(marketInfo, denom)?.max_loan_to_value || 0 const assetLtvRatio = findByDenom(marketInfo, denom)?.max_loan_to_value || 0
@ -268,6 +271,7 @@ export const Action = ({
totalBorrowBaseCurrencyAmount, totalBorrowBaseCurrencyAmount,
marketInfo, marketInfo,
marketAssetLiquidity, marketAssetLiquidity,
baseCurrency.decimals,
]) ])
const maxUsableAmount = useMemo(() => { const maxUsableAmount = useMemo(() => {

View File

@ -12,7 +12,6 @@ describe('produceUpdatedAssetData', () => {
100, 100,
ViewType.Deposit, ViewType.Deposit,
'borrowBalanceBaseCurrency', 'borrowBalanceBaseCurrency',
6,
) )
expect(assets.length).toBe(1) expect(assets.length).toBe(1)
expect(assets[0]).toEqual({ expect(assets[0]).toEqual({
@ -28,7 +27,6 @@ describe('produceUpdatedAssetData', () => {
100, 100,
ViewType.Deposit, ViewType.Deposit,
'borrowBalanceBaseCurrency', 'borrowBalanceBaseCurrency',
6,
) )
expect(assets.length).toBe(2) expect(assets.length).toBe(2)
expect(assets[1]).toEqual({ expect(assets[1]).toEqual({
@ -44,7 +42,6 @@ describe('produceUpdatedAssetData', () => {
100, 100,
ViewType.Deposit, ViewType.Deposit,
'borrowBalanceBaseCurrency', 'borrowBalanceBaseCurrency',
6,
) )
expect(assets.length).toBe(2) expect(assets.length).toBe(2)
expect(assets[1]).toEqual({ expect(assets[1]).toEqual({
@ -62,7 +59,6 @@ describe('produceUpdatedAssetData', () => {
50, 50,
ViewType.Deposit, ViewType.Deposit,
'depositBalanceBaseCurrency', 'depositBalanceBaseCurrency',
6,
) )
expect(assets.length).toBe(1) expect(assets.length).toBe(1)
expect(assets[0]).toEqual({ expect(assets[0]).toEqual({
@ -78,7 +74,6 @@ describe('produceUpdatedAssetData', () => {
100, 100,
ViewType.Deposit, ViewType.Deposit,
'depositBalanceBaseCurrency', 'depositBalanceBaseCurrency',
6,
) )
expect(assets.length).toBe(1) expect(assets.length).toBe(1)
expect(assets[0]).toEqual({ expect(assets[0]).toEqual({
@ -97,7 +92,6 @@ describe('produceUpdatedAssetData', () => {
50, 50,
ViewType.Borrow, ViewType.Borrow,
'borrowBalanceBaseCurrency', 'borrowBalanceBaseCurrency',
6,
) )
expect(assets.length).toBe(1) expect(assets.length).toBe(1)
expect(assets[0]).toEqual({ expect(assets[0]).toEqual({
@ -113,7 +107,6 @@ describe('produceUpdatedAssetData', () => {
100, 100,
ViewType.Borrow, ViewType.Borrow,
'borrowBalanceBaseCurrency', 'borrowBalanceBaseCurrency',
6,
) )
expect(assets.length).toBe(1) expect(assets.length).toBe(1)
expect(assets[0]).toEqual({ expect(assets[0]).toEqual({
@ -132,7 +125,6 @@ describe('produceUpdatedAssetData', () => {
100, 100,
ViewType.Repay, ViewType.Repay,
'borrowBalanceBaseCurrency', 'borrowBalanceBaseCurrency',
6,
) )
expect(assets.length).toBe(1) expect(assets.length).toBe(1)
expect(assets[0]).toEqual({ expect(assets[0]).toEqual({

View File

@ -1,4 +1,3 @@
import { demagnify } from 'libs/parse'
import { ViewType } from 'types/enums' import { ViewType } from 'types/enums'
export const produceUpdatedAssetData = ( export const produceUpdatedAssetData = (
@ -8,7 +7,6 @@ export const produceUpdatedAssetData = (
updateAmount: number, updateAmount: number,
activeView: ViewType, activeView: ViewType,
key: 'depositBalanceBaseCurrency' | 'borrowBalanceBaseCurrency', key: 'depositBalanceBaseCurrency' | 'borrowBalanceBaseCurrency',
baseCurrencyDecimals: number,
) => { ) => {
const alreadyPresent = assetData.some((asset: RedBankAsset) => asset.denom === denom) const alreadyPresent = assetData.some((asset: RedBankAsset) => asset.denom === denom)
// For first use, when the user has no borrow balance yet and this list will be empty // For first use, when the user has no borrow balance yet and this list will be empty
@ -16,19 +14,15 @@ export const produceUpdatedAssetData = (
const asset = redBankAssets.find((redBankAsset) => redBankAsset.denom === denom) const asset = redBankAssets.find((redBankAsset) => redBankAsset.denom === denom)
if (!asset) return assetData if (!asset) return assetData
const additionalDecimals = asset.decimals - baseCurrencyDecimals
const amountAdjustedForDecimals = demagnify(updateAmount, additionalDecimals)
// We are only interested in display currency balance. The asset will update post tx. // We are only interested in display currency balance. The asset will update post tx.
assetData.push({ assetData.push({
...asset, ...asset,
[key]: amountAdjustedForDecimals, [key]: updateAmount,
}) })
return assetData return assetData
} }
return assetData.map((asset) => { return assetData.map((asset) => {
const additionalDecimals = asset.decimals - baseCurrencyDecimals
const amountAdjustedForDecimals = demagnify(updateAmount, additionalDecimals)
const newAsset = { ...asset } const newAsset = { ...asset }
const assetbaseCurrencyBalance = asset[key] || 0 const assetbaseCurrencyBalance = asset[key] || 0
let updatedAssetbaseCurrencyBalance = asset[key] let updatedAssetbaseCurrencyBalance = asset[key]
@ -37,8 +31,8 @@ export const produceUpdatedAssetData = (
// if we are repaaying or redeeming, we decrease the amount // if we are repaaying or redeeming, we decrease the amount
updatedAssetbaseCurrencyBalance = updatedAssetbaseCurrencyBalance =
activeView === ViewType.Borrow || activeView === ViewType.Deposit activeView === ViewType.Borrow || activeView === ViewType.Deposit
? assetbaseCurrencyBalance + amountAdjustedForDecimals ? assetbaseCurrencyBalance + updateAmount
: assetbaseCurrencyBalance - amountAdjustedForDecimals : assetbaseCurrencyBalance - updateAmount
} }
newAsset[key] = updatedAssetbaseCurrencyBalance newAsset[key] = updatedAssetbaseCurrencyBalance
return newAsset return newAsset

View File

@ -2,7 +2,7 @@ import { Coin } from '@cosmjs/stargate'
import { MARS_SYMBOL } from 'constants/appConstants' import { MARS_SYMBOL } from 'constants/appConstants'
import { SECONDS_IN_YEAR } from 'constants/timeConstants' import { SECONDS_IN_YEAR } from 'constants/timeConstants'
import { findByDenom } from 'functions' import { findByDenom } from 'functions'
import { demagnify, lookupDenomBySymbol } from 'libs/parse' import { lookupDenomBySymbol } from 'libs/parse'
import isEqual from 'lodash.isequal' import isEqual from 'lodash.isequal'
import { RedBankSlice } from 'store/interfaces/redBank.interface' import { RedBankSlice } from 'store/interfaces/redBank.interface'
import { Store } from 'store/interfaces/store.interface' import { Store } from 'store/interfaces/store.interface'
@ -97,19 +97,18 @@ const redBankSlice = (set: NamedSet<Store>, get: GetState<Store>): RedBankSlice
{ denom: asset.denom, amount: depositLiquidity.toString() }, { denom: asset.denom, amount: depositLiquidity.toString() },
) )
const additionalDecimals = asset.decimals - get().baseCurrency.decimals
const redBankAsset: RedBankAsset = { const redBankAsset: RedBankAsset = {
...asset, ...asset,
walletBalance: assetWallet?.amount.toString(), walletBalance: assetWallet?.amount.toString(),
depositBalance: depositBalance.toString(), depositBalance: depositBalance.toString(),
depositBalanceBaseCurrency: convertToBaseCurrency({ depositBalanceBaseCurrency: convertToBaseCurrency({
denom: asset.denom, denom: asset.denom,
amount: demagnify(depositBalance, additionalDecimals).toString(), amount: depositBalance.toString(),
}), }),
borrowBalance: borrowBalance.toString(), borrowBalance: borrowBalance.toString(),
borrowBalanceBaseCurrency: convertToBaseCurrency({ borrowBalanceBaseCurrency: convertToBaseCurrency({
denom: asset.denom, denom: asset.denom,
amount: demagnify(borrowBalance, additionalDecimals).toString(), amount: borrowBalance.toString(),
}), }),
borrowRate: borrowApy * 100 >= 0.01 ? borrowApy * 100 : 0.0, borrowRate: borrowApy * 100 >= 0.01 ? borrowApy * 100 : 0.0,
apy: depositApy * 100 >= 0.01 ? depositApy * 100 : 0.0, apy: depositApy * 100 >= 0.01 ? depositApy * 100 : 0.0,