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 {
result = await borrow({
accountId: account.id,
coin: { denom: asset.denom, amount: amount.toString() },
coin: BNCoin.fromDenomAndBigNumber(asset.denom, amount),
borrowToWallet,
})
}

View File

@ -14,7 +14,7 @@ import useToggle from 'hooks/useToggle'
import { useUpdatedAccount } from 'hooks/useUpdatedAccount'
import useStore from 'store'
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 { getEnabledMarketAssets } from 'utils/assets'
@ -34,7 +34,7 @@ export default function WithdrawFromAccount(props: Props) {
const { simulateWithdraw } = useUpdatedAccount(account)
const { computeMaxWithdrawAmount } = useHealthComputer(account)
const accountClone = cloneAccount(account)
const borrowAccount = removeDepostisAndLends(accountClone, currentAsset.denom)
const borrowAccount = removeDepositsAndLends(accountClone, currentAsset.denom)
const { computeMaxBorrowAmount } = useHealthComputer(borrowAccount)
const balances = getMergedBalances(account, getEnabledMarketAssets())
const maxWithdrawAmount = computeMaxWithdrawAmount(currentAsset.denom)
@ -65,7 +65,12 @@ export default function WithdrawFromAccount(props: Props) {
async function onConfirm() {
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()
? [BNCoin.fromDenomAndBigNumber(currentAsset.denom, debtAmount)]
: []

View File

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

View File

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

View File

@ -12,7 +12,11 @@ interface ExecutableTx {
}
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
createAccount: () => Promise<string | null>
deleteAccount: (options: { accountId: string; lends: BNCoin[] }) => Promise<boolean>
@ -44,7 +48,7 @@ interface BroadcastSlice {
withdrawFromVaults: (options: { accountId: string; vaults: DepositedVault[] }) => Promise<boolean>
withdraw: (options: {
accountId: string
coins: BNCoin[]
coins: Array<{ coin: BNCoin; isMax?: boolean }>
borrow: BNCoin[]
reclaims: ActionCoin[]
}) => 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 lends = account.lends.filter((lend) => lend.denom !== denom)