Skip to content

Commit

Permalink
fix(centrifuge-js): Fix proxies for finance and withdraw (#1793)
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser authored Dec 14, 2023
1 parent 78b95b0 commit b07e2a0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
60 changes: 50 additions & 10 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1523,21 +1523,41 @@ export function getPoolsModule(inst: Centrifuge) {

return inst.getApi().pipe(
switchMap((api) => {
const borrowSubmittable = api.tx.loans.borrow(poolId, loanId, {
let borrowTx = api.tx.loans.borrow(poolId, loanId, {
external: { quantity: quantity.toString(), settlementPrice: price.toString() },
})
if (withdrawTo) {
const { address, location, currency } = withdrawTo
return withdraw([quantity.mul(price).div(Price.fromFloat(1)), currency, address, location], {
batch: true,
}).pipe(
switchMap((withdrawTx) => {
const batchTx = api.tx.utility.batchAll([borrowSubmittable, withdrawTx])
return inst.wrapSignAndSend(api, batchTx, options)
switchMap((_withdrawTx) => {
let withdrawTx = _withdrawTx
const proxies = (options?.proxies || inst.config.proxies)?.map((p) =>
Array.isArray(p) ? p : ([p, undefined] as const)
)
if (proxies) {
// The borrow and withdraw txs need different proxy types
// If a proxy type was passed, replace it with the right one
// Otherwise pass none, as it means the delegatee has the Any proxy type
borrowTx = proxies.reduceRight(
(acc, [delegator, origType]) => api.tx.proxy.proxy(delegator, origType ? 'Borrow' : undefined, acc),
borrowTx
)
withdrawTx = proxies.reduceRight(
(acc, [delegator, origType]) => api.tx.proxy.proxy(delegator, origType ? 'Transfer' : undefined, acc),
withdrawTx
)
}
const batchTx = api.tx.utility.batchAll([borrowTx, withdrawTx])

const opt = { ...options }
delete opt.proxies
return inst.wrapSignAndSend(api, batchTx, opt)
})
)
}
return inst.wrapSignAndSend(api, borrowSubmittable, options)
return inst.wrapSignAndSend(api, borrowTx, options)
})
)
}
Expand All @@ -1550,18 +1570,38 @@ export function getPoolsModule(inst: Centrifuge) {
const amount = amountBN.toString()
return inst.getApi().pipe(
switchMap((api) => {
const submittable = api.tx.loans.borrow(poolId, loanId, { internal: amount })
let borrowTx = api.tx.loans.borrow(poolId, loanId, { internal: amount })

if (withdrawTo) {
const { address, location, currency } = withdrawTo
return withdraw([amountBN, currency, address, location], { batch: true }).pipe(
switchMap((withdrawTx) => {
const batchTx = api.tx.utility.batchAll([submittable, withdrawTx])
return inst.wrapSignAndSend(api, batchTx, options)
switchMap((_withdrawTx) => {
let withdrawTx = _withdrawTx
const proxies = (options?.proxies || inst.config.proxies)?.map((p) =>
Array.isArray(p) ? p : ([p, undefined] as const)
)
if (proxies) {
// The borrow and withdraw txs need different proxy types
// If a proxy type was passed, replace it with the right one
// Otherwise pass none, as it means the delegatee has the Any proxy type
borrowTx = proxies.reduceRight(
(acc, [delegator, origType]) => api.tx.proxy.proxy(delegator, origType ? 'Borrow' : undefined, acc),
borrowTx
)
withdrawTx = proxies.reduceRight(
(acc, [delegator, origType]) => api.tx.proxy.proxy(delegator, origType ? 'Transfer' : undefined, acc),
withdrawTx
)
}
const batchTx = api.tx.utility.batchAll([borrowTx, withdrawTx])

const opt = { ...options }
delete opt.proxies
return inst.wrapSignAndSend(api, batchTx, opt)
})
)
}
return inst.wrapSignAndSend(api, submittable, options)
return inst.wrapSignAndSend(api, borrowTx, options)
})
)
}
Expand Down
6 changes: 3 additions & 3 deletions fabric/src/components/TextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ export const StyledInputBox = styled(Shelf)`
&:has(input:focus)::before,
&:has(select:focus)::before {
box-shadow: 0 0 0 1px ${({ theme }) => theme.colors.accentPrimary};
box-shadow: 0 0 0 1px ${({ theme }) => theme.colors.focus};
}
`

export const StyledInputAction = styled.button`
cursor: pointer;
appearance: none;
border: none;
background: ${(props) => props.theme.colors.backgroundInput};
background: ${(props) => props.theme.colors.backgroundButtonSecondary};
display: flex;
justify-content: center;
align-items: center;
Expand All @@ -99,7 +99,7 @@ export const StyledInputAction = styled.button`
}) => `0 ${input}px ${input}px 0`};
&:focus-visible {
box-shadow: 0 0 0 1px ${(props) => props.theme.colors.accentPrimary};
box-shadow: 0 0 0 1px ${(props) => props.theme.colors.focus};
}
&:disabled {
opacity: 0.4;
Expand Down

0 comments on commit b07e2a0

Please sign in to comment.