✨updated vault deposit toast message (#460)
This commit is contained in:
parent
ccde9dbe1e
commit
5a5d86f17c
@ -20,28 +20,7 @@ import { defaultFee } from 'utils/constants'
|
|||||||
import { formatAmountWithSymbol } from 'utils/formatters'
|
import { formatAmountWithSymbol } from 'utils/formatters'
|
||||||
import getTokenOutFromSwapResponse from 'utils/getTokenOutFromSwapResponse'
|
import getTokenOutFromSwapResponse from 'utils/getTokenOutFromSwapResponse'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
import { getVaultDepositCoinsFromActions } from 'utils/vaults'
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateExecutionMessage(
|
function generateExecutionMessage(
|
||||||
sender: string | undefined = '',
|
sender: string | undefined = '',
|
||||||
@ -61,7 +40,7 @@ export default function createBroadcastSlice(
|
|||||||
set: SetState<Store>,
|
set: SetState<Store>,
|
||||||
get: GetState<Store>,
|
get: GetState<Store>,
|
||||||
): BroadcastSlice {
|
): BroadcastSlice {
|
||||||
const handleResponseMessages = (props: HandleResponse) => {
|
const handleResponseMessages = (props: HandleResponseProps) => {
|
||||||
const { accountId, response, action, lend, changes, target, message } = props
|
const { accountId, response, action, lend, changes, target, message } = props
|
||||||
|
|
||||||
if (response.error || response.result?.response.code !== 0) {
|
if (response.error || response.result?.response.code !== 0) {
|
||||||
@ -95,7 +74,7 @@ export default function createBroadcastSlice(
|
|||||||
switch (action) {
|
switch (action) {
|
||||||
case 'borrow':
|
case 'borrow':
|
||||||
const borrowCoin = changes.debts ? [changes.debts[0].toCoin()] : []
|
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({
|
toast.content.push({
|
||||||
coins: borrowCoin,
|
coins: borrowCoin,
|
||||||
text: target === 'wallet' ? 'Borrowed to wallet' : borrowAction,
|
text: target === 'wallet' ? 'Borrowed to wallet' : borrowAction,
|
||||||
@ -105,7 +84,7 @@ export default function createBroadcastSlice(
|
|||||||
case 'withdraw':
|
case 'withdraw':
|
||||||
toast.content.push({
|
toast.content.push({
|
||||||
coins: changes.deposits?.map((deposit) => deposit.toCoin()) ?? [],
|
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
|
break
|
||||||
|
|
||||||
@ -128,21 +107,15 @@ export default function createBroadcastSlice(
|
|||||||
const repayCoin = changes.deposits ? [changes.deposits[0].toCoin()] : []
|
const repayCoin = changes.deposits ? [changes.deposits[0].toCoin()] : []
|
||||||
toast.content.push({
|
toast.content.push({
|
||||||
coins: repayCoin,
|
coins: repayCoin,
|
||||||
text: 'Repayed',
|
text: 'Repaid',
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'vault':
|
case 'vault':
|
||||||
case 'vaultCreate':
|
case 'vaultCreate':
|
||||||
toast.message =
|
|
||||||
action === 'vaultCreate' ? 'Created a Vault Position' : 'Add to Vault Position'
|
|
||||||
toast.content.push({
|
toast.content.push({
|
||||||
coins: changes.debts?.map((debt) => debt.toCoin()) ?? [],
|
coins: changes.deposits?.map((debt) => debt.toCoin()) ?? [],
|
||||||
text: 'Borrowed for the Vault Position',
|
text: action === 'vaultCreate' ? 'Created a Vault Position' : 'Added to Vault Position',
|
||||||
})
|
|
||||||
toast.content.push({
|
|
||||||
coins: changes.deposits?.map((deposit) => deposit.toCoin()) ?? [],
|
|
||||||
text: 'Withdrew for the Vault Position',
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,11 +411,13 @@ export default function createBroadcastSlice(
|
|||||||
messages: [generateExecutionMessage(get().address, ENV.ADDRESS_CREDIT_MANAGER, msg, [])],
|
messages: [generateExecutionMessage(get().address, ENV.ADDRESS_CREDIT_MANAGER, msg, [])],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const depositedCoins = getVaultDepositCoinsFromActions(options.actions)
|
||||||
|
|
||||||
handleResponseMessages({
|
handleResponseMessages({
|
||||||
response,
|
response,
|
||||||
action: options.isCreate ? 'vaultCreate' : 'vault',
|
action: options.isCreate ? 'vaultCreate' : 'vault',
|
||||||
accountId: options.accountId,
|
accountId: options.accountId,
|
||||||
changes: { deposits: options.deposits, debts: options.borrowings },
|
changes: { deposits: depositedCoins },
|
||||||
})
|
})
|
||||||
|
|
||||||
return !!response.result
|
return !!response.result
|
||||||
|
22
src/types/interfaces/store/broadcast.d.ts
vendored
22
src/types/interfaces/store/broadcast.d.ts
vendored
@ -35,6 +35,28 @@ interface ToastStore {
|
|||||||
recent: ToastSuccess[]
|
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 {
|
interface BroadcastSlice {
|
||||||
borrow: (options: {
|
borrow: (options: {
|
||||||
accountId: string
|
accountId: string
|
||||||
|
11
src/types/interfaces/vaults.d.ts
vendored
11
src/types/interfaces/vaults.d.ts
vendored
@ -1,4 +1,5 @@
|
|||||||
type BigNumber = import('bignumber.js').BigNumber
|
type BigNumber = import('bignumber.js').BigNumber
|
||||||
|
|
||||||
interface VaultMetaData {
|
interface VaultMetaData {
|
||||||
address: string
|
address: string
|
||||||
name: string
|
name: string
|
||||||
@ -50,6 +51,7 @@ interface VaultValuesAndAmounts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type VaultStatus = 'active' | 'unlocking' | 'unlocked'
|
type VaultStatus = 'active' | 'unlocking' | 'unlocked'
|
||||||
|
|
||||||
interface DepositedVault extends Vault, VaultValuesAndAmounts {
|
interface DepositedVault extends Vault, VaultValuesAndAmounts {
|
||||||
status: VaultStatus
|
status: VaultStatus
|
||||||
unlockId?: number
|
unlockId?: number
|
||||||
@ -76,3 +78,12 @@ interface DepositCap {
|
|||||||
used: BigNumber
|
used: BigNumber
|
||||||
max: 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { IS_TESTNET } from 'constants/env'
|
|||||||
import { BN_ZERO } from 'constants/math'
|
import { BN_ZERO } from 'constants/math'
|
||||||
import { TESTNET_VAULTS_META_DATA, VAULTS_META_DATA } from 'constants/vaults'
|
import { TESTNET_VAULTS_META_DATA, VAULTS_META_DATA } from 'constants/vaults'
|
||||||
import { BNCoin } from 'types/classes/BNCoin'
|
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 { getAssetByDenom } from 'utils/assets'
|
||||||
import { VAULT_DEPOSIT_BUFFER } from 'utils/constants'
|
import { VAULT_DEPOSIT_BUFFER } from 'utils/constants'
|
||||||
import { getCoinAmount, getCoinValue } from 'utils/formatters'
|
import { getCoinAmount, getCoinValue } from 'utils/formatters'
|
||||||
@ -186,4 +186,22 @@ function getSwapAction(denomIn: string, denomOut: string, amount: BigNumber, sli
|
|||||||
slippage: slippage.toString(),
|
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,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user