updated vault deposit toast message (#460)

This commit is contained in:
Bob van der Helm 2023-09-12 17:42:43 +02:00 committed by GitHub
parent ccde9dbe1e
commit 5a5d86f17c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 37 deletions

View File

@ -20,28 +20,7 @@ import { defaultFee } from 'utils/constants'
import { formatAmountWithSymbol } from 'utils/formatters'
import getTokenOutFromSwapResponse from 'utils/getTokenOutFromSwapResponse'
import { BN } from 'utils/helpers'
interface HandleResponse {
response: BroadcastResult
action:
| 'deposit'
| 'withdraw'
| 'borrow'
| 'repay'
| 'vault'
| 'vaultCreate'
| 'lend'
| 'create'
| 'delete'
| 'claim'
| 'unlock'
| 'swap'
lend?: boolean
accountId?: string
changes?: { debts?: BNCoin[]; deposits?: BNCoin[]; lends?: BNCoin[] }
target?: 'wallet' | 'account'
message?: string
}
import { getVaultDepositCoinsFromActions } from 'utils/vaults'
function generateExecutionMessage(
sender: string | undefined = '',
@ -61,7 +40,7 @@ export default function createBroadcastSlice(
set: SetState<Store>,
get: GetState<Store>,
): BroadcastSlice {
const handleResponseMessages = (props: HandleResponse) => {
const handleResponseMessages = (props: HandleResponseProps) => {
const { accountId, response, action, lend, changes, target, message } = props
if (response.error || response.result?.response.code !== 0) {
@ -95,7 +74,7 @@ export default function createBroadcastSlice(
switch (action) {
case 'borrow':
const borrowCoin = changes.debts ? [changes.debts[0].toCoin()] : []
const borrowAction = lend ? 'Borrowed and lend' : 'Borrowed'
const borrowAction = lend ? 'Borrowed and lent' : 'Borrowed'
toast.content.push({
coins: borrowCoin,
text: target === 'wallet' ? 'Borrowed to wallet' : borrowAction,
@ -105,7 +84,7 @@ export default function createBroadcastSlice(
case 'withdraw':
toast.content.push({
coins: changes.deposits?.map((deposit) => deposit.toCoin()) ?? [],
text: target === 'wallet' ? 'Withdrew to Wallet' : 'Withdrew from lend',
text: target === 'wallet' ? 'Withdrew to Wallet' : 'Reclaimed from lends',
})
break
@ -128,21 +107,15 @@ export default function createBroadcastSlice(
const repayCoin = changes.deposits ? [changes.deposits[0].toCoin()] : []
toast.content.push({
coins: repayCoin,
text: 'Repayed',
text: 'Repaid',
})
break
case 'vault':
case 'vaultCreate':
toast.message =
action === 'vaultCreate' ? 'Created a Vault Position' : 'Add to Vault Position'
toast.content.push({
coins: changes.debts?.map((debt) => debt.toCoin()) ?? [],
text: 'Borrowed for the Vault Position',
})
toast.content.push({
coins: changes.deposits?.map((deposit) => deposit.toCoin()) ?? [],
text: 'Withdrew for the Vault Position',
coins: changes.deposits?.map((debt) => debt.toCoin()) ?? [],
text: action === 'vaultCreate' ? 'Created a Vault Position' : 'Added to Vault Position',
})
}
@ -438,11 +411,13 @@ export default function createBroadcastSlice(
messages: [generateExecutionMessage(get().address, ENV.ADDRESS_CREDIT_MANAGER, msg, [])],
})
const depositedCoins = getVaultDepositCoinsFromActions(options.actions)
handleResponseMessages({
response,
action: options.isCreate ? 'vaultCreate' : 'vault',
accountId: options.accountId,
changes: { deposits: options.deposits, debts: options.borrowings },
changes: { deposits: depositedCoins },
})
return !!response.result

View File

@ -35,6 +35,28 @@ interface ToastStore {
recent: ToastSuccess[]
}
interface HandleResponseProps {
response: BroadcastResult
action:
| 'deposit'
| 'withdraw'
| 'borrow'
| 'repay'
| 'vault'
| 'vaultCreate'
| 'lend'
| 'create'
| 'delete'
| 'claim'
| 'unlock'
| 'swap'
lend?: boolean
accountId?: string
changes?: { debts?: BNCoin[]; deposits?: BNCoin[]; lends?: BNCoin[] }
target?: 'wallet' | 'account'
message?: string
}
interface BroadcastSlice {
borrow: (options: {
accountId: string

View File

@ -1,4 +1,5 @@
type BigNumber = import('bignumber.js').BigNumber
interface VaultMetaData {
address: string
name: string
@ -50,6 +51,7 @@ interface VaultValuesAndAmounts {
}
type VaultStatus = 'active' | 'unlocking' | 'unlocked'
interface DepositedVault extends Vault, VaultValuesAndAmounts {
status: VaultStatus
unlockId?: number
@ -76,3 +78,12 @@ interface DepositCap {
used: BigNumber
max: BigNumber
}
interface ProvideLiquidityAction {
provide_liquidity: {
account_id: string
coins_in: import('../generated/mars-credit-manager/MarsCreditManager.types').ActionCoin[]
lp_token_out: string
minimum_receive: import('../generated/mars-credit-manager/MarsCreditManager.types').Uint128
}
}

View File

@ -3,7 +3,7 @@ import { IS_TESTNET } from 'constants/env'
import { BN_ZERO } from 'constants/math'
import { TESTNET_VAULTS_META_DATA, VAULTS_META_DATA } from 'constants/vaults'
import { BNCoin } from 'types/classes/BNCoin'
import { Action } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
import { Action, Uint128 } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
import { getAssetByDenom } from 'utils/assets'
import { VAULT_DEPOSIT_BUFFER } from 'utils/constants'
import { getCoinAmount, getCoinValue } from 'utils/formatters'
@ -186,4 +186,22 @@ function getSwapAction(denomIn: string, denomOut: string, amount: BigNumber, sli
slippage: slippage.toString(),
},
}
}
}
export function getVaultDepositCoinsFromActions(actions: Action[]) {
const provideLiquidityAction = actions.find((action) =>
Object.keys(action).includes('provide_liquidity'),
) as ProvideLiquidityAction | undefined
if (!provideLiquidityAction) return []
const actionsCoins = provideLiquidityAction.provide_liquidity.coins_in
return actionsCoins.map((actionCoin) => {
return new BNCoin({
denom: actionCoin.denom,
amount: (actionCoin.amount as { exact: Uint128 }).exact,
})
})
}