feat(SC update): added contract types and fixed breaking changes (#409)

This commit is contained in:
Yusuf Seyrek 2023-08-30 11:24:03 +03:00 committed by GitHub
parent 22830289cf
commit 1923b8e7d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 17 deletions

View File

@ -93,7 +93,7 @@ function BorrowModal(props: Props) {
} else { } else {
result = await borrow({ result = await borrow({
accountId: account.id, accountId: account.id,
coin: { denom: asset.denom, amount: amount.toString() }, coin: BNCoin.fromDenomAndBigNumber(asset.denom, amount),
borrowToWallet, borrowToWallet,
}) })
} }

View File

@ -14,7 +14,7 @@ import useToggle from 'hooks/useToggle'
import { useUpdatedAccount } from 'hooks/useUpdatedAccount' import { useUpdatedAccount } from 'hooks/useUpdatedAccount'
import useStore from 'store' import useStore from 'store'
import { BNCoin } from 'types/classes/BNCoin' import { BNCoin } from 'types/classes/BNCoin'
import { cloneAccount, getMergedBalances, removeDepostisAndLends } from 'utils/accounts' import { cloneAccount, getMergedBalances, removeDepositsAndLends } from 'utils/accounts'
import { byDenom } from 'utils/array' import { byDenom } from 'utils/array'
import { getEnabledMarketAssets } from 'utils/assets' import { getEnabledMarketAssets } from 'utils/assets'
@ -34,7 +34,7 @@ export default function WithdrawFromAccount(props: Props) {
const { simulateWithdraw } = useUpdatedAccount(account) const { simulateWithdraw } = useUpdatedAccount(account)
const { computeMaxWithdrawAmount } = useHealthComputer(account) const { computeMaxWithdrawAmount } = useHealthComputer(account)
const accountClone = cloneAccount(account) const accountClone = cloneAccount(account)
const borrowAccount = removeDepostisAndLends(accountClone, currentAsset.denom) const borrowAccount = removeDepositsAndLends(accountClone, currentAsset.denom)
const { computeMaxBorrowAmount } = useHealthComputer(borrowAccount) const { computeMaxBorrowAmount } = useHealthComputer(borrowAccount)
const balances = getMergedBalances(account, getEnabledMarketAssets()) const balances = getMergedBalances(account, getEnabledMarketAssets())
const maxWithdrawAmount = computeMaxWithdrawAmount(currentAsset.denom) const maxWithdrawAmount = computeMaxWithdrawAmount(currentAsset.denom)
@ -65,7 +65,12 @@ export default function WithdrawFromAccount(props: Props) {
async function onConfirm() { async function onConfirm() {
setIsConfirming(true) setIsConfirming(true)
const coins = [BNCoin.fromDenomAndBigNumber(currentAsset.denom, amount)] const coins = [
{
coin: BNCoin.fromDenomAndBigNumber(currentAsset.denom, amount),
isMax: max.isEqualTo(amount),
},
]
const borrow = !debtAmount.isZero() const borrow = !debtAmount.isZero()
? [BNCoin.fromDenomAndBigNumber(currentAsset.denom, debtAmount)] ? [BNCoin.fromDenomAndBigNumber(currentAsset.denom, debtAmount)]
: [] : []

View File

@ -89,9 +89,9 @@ export default function createBroadcastSlice(
return { return {
toast: null, toast: null,
borrow: async (options: { accountId: string; coin: Coin; borrowToWallet: boolean }) => { borrow: async (options: { accountId: string; coin: BNCoin; borrowToWallet: boolean }) => {
const borrowAction: Action = { borrow: options.coin } const borrowAction: Action = { borrow: options.coin.toCoin() }
const withdrawAction: Action = { withdraw: options.coin } const withdrawAction: Action = { withdraw: options.coin.toActionCoin() }
const actions = options.borrowToWallet ? [borrowAction, withdrawAction] : [borrowAction] const actions = options.borrowToWallet ? [borrowAction, withdrawAction] : [borrowAction]
const msg: CreditManagerExecuteMsg = { const msg: CreditManagerExecuteMsg = {
@ -117,7 +117,7 @@ export default function createBroadcastSlice(
handleResponseMessages( handleResponseMessages(
response, response,
`Borrowed ${formatAmountWithSymbol(options.coin)} to ${ `Borrowed ${formatAmountWithSymbol(options.coin.toCoin())} to ${
options.borrowToWallet ? 'Wallet' : `Credit Account ${options.accountId}` options.borrowToWallet ? 'Wallet' : `Credit Account ${options.accountId}`
}`, }`,
) )
@ -324,15 +324,15 @@ export default function createBroadcastSlice(
}, },
withdraw: async (options: { withdraw: async (options: {
accountId: string accountId: string
coins: BNCoin[] coins: Array<{ coin: BNCoin; isMax?: boolean }>
borrow: BNCoin[] borrow: BNCoin[]
reclaims: ActionCoin[] reclaims: ActionCoin[]
}) => { }) => {
const reclaimActions = options.reclaims.map((coin) => ({ const reclaimActions = options.reclaims.map((coin) => ({
reclaim: coin, reclaim: coin,
})) }))
const withdrawActions = options.coins.map((coin) => ({ const withdrawActions = options.coins.map(({ coin, isMax }) => ({
withdraw: coin.toCoin(), withdraw: coin.toActionCoin(isMax),
})) }))
const borrowActions = options.borrow.map((coin) => ({ const borrowActions = options.borrow.map((coin) => ({
borrow: coin.toCoin(), borrow: coin.toCoin(),
@ -350,7 +350,7 @@ export default function createBroadcastSlice(
}) })
const withdrawString = options.coins const withdrawString = options.coins
.map((coin) => formatAmountWithSymbol(coin.toCoin())) .map(({ coin }) => formatAmountWithSymbol(coin.toCoin()))
.join('and ') .join('and ')
handleResponseMessages( handleResponseMessages(
response, response,

View File

@ -62,7 +62,7 @@ export type Action =
deposit: Coin deposit: Coin
} }
| { | {
withdraw: Coin withdraw: ActionCoin
} }
| { | {
borrow: Coin borrow: Coin
@ -176,7 +176,7 @@ export type CallbackMsg =
| { | {
withdraw: { withdraw: {
account_id: string account_id: string
coin: Coin coin: ActionCoin
recipient: Addr recipient: Addr
} }
} }

View File

@ -12,7 +12,11 @@ interface ExecutableTx {
} }
interface BroadcastSlice { interface BroadcastSlice {
borrow: (options: { accountId: string; coin: Coin; borrowToWallet: boolean }) => Promise<boolean> borrow: (options: {
accountId: string
coin: BNCoin
borrowToWallet: boolean
}) => Promise<boolean>
claimRewards: (options: { accountId: string }) => ExecutableTx claimRewards: (options: { accountId: string }) => ExecutableTx
createAccount: () => Promise<string | null> createAccount: () => Promise<string | null>
deleteAccount: (options: { accountId: string; lends: BNCoin[] }) => Promise<boolean> deleteAccount: (options: { accountId: string; lends: BNCoin[] }) => Promise<boolean>
@ -44,7 +48,7 @@ interface BroadcastSlice {
withdrawFromVaults: (options: { accountId: string; vaults: DepositedVault[] }) => Promise<boolean> withdrawFromVaults: (options: { accountId: string; vaults: DepositedVault[] }) => Promise<boolean>
withdraw: (options: { withdraw: (options: {
accountId: string accountId: string
coins: BNCoin[] coins: Array<{ coin: BNCoin; isMax?: boolean }>
borrow: BNCoin[] borrow: BNCoin[]
reclaims: ActionCoin[] reclaims: ActionCoin[]
}) => Promise<boolean> }) => Promise<boolean>

View File

@ -205,7 +205,7 @@ export function cloneAccount(account: Account): Account {
} }
} }
export function removeDepostisAndLends(account: Account, denom: string) { export function removeDepositsAndLends(account: Account, denom: string) {
const deposits = account.deposits.filter((deposit) => deposit.denom !== denom) const deposits = account.deposits.filter((deposit) => deposit.denom !== denom)
const lends = account.lends.filter((lend) => lend.denom !== denom) const lends = account.lends.filter((lend) => lend.denom !== denom)