-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centrifuge App: Fix write-off policies (#1515)
- Loading branch information
1 parent
d495183
commit 35585ec
Showing
4 changed files
with
174 additions
and
22 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
centrifuge-app/src/pages/IssuerPool/Configuration/PendingLoanChanges.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useCentrifugeTransaction } from '@centrifuge/centrifuge-react' | ||
import { Button, Shelf, Stack, Text } from '@centrifuge/fabric' | ||
import { useLoanChanges, usePoolOrders } from '../../../utils/usePools' | ||
|
||
const POOL_CHANGE_DELAY = 1000 * 60 * 60 * 24 * 7 // Currently hard-coded to 1 week on chain, will probably change to a constant we can query | ||
|
||
// Currently only showing write-off policy changes | ||
export function PendingLoanChanges({ poolId }: { poolId: string }) { | ||
const poolOrders = usePoolOrders(poolId) | ||
const hasLockedRedemptions = (poolOrders?.reduce((acc, cur) => acc + cur.activeRedeem.toFloat(), 0) ?? 0) > 0 | ||
const loanChanges = useLoanChanges(poolId) | ||
const policyChanges = loanChanges?.filter(({ change }) => !!change.loan?.policy?.length) | ||
|
||
const { | ||
execute: executeApply, | ||
isLoading: isApplyLoading, | ||
lastCreatedTransaction, | ||
} = useCentrifugeTransaction('Apply write-off policy', (cent) => cent.pools.applyWriteOffPolicyUpdate) | ||
|
||
return ( | ||
<Stack gap={1}> | ||
{policyChanges?.map((policy) => { | ||
const waitingPeriodDone = new Date(policy.submittedAt).getTime() + POOL_CHANGE_DELAY < Date.now() | ||
|
||
return ( | ||
<Shelf gap={2}> | ||
<Text>Pending policy update</Text> | ||
<Text> | ||
{!waitingPeriodDone | ||
? 'In waiting period' | ||
: hasLockedRedemptions | ||
? 'Blocked by locked redemptions' | ||
: 'Can be applied'} | ||
</Text> | ||
<Button | ||
variant="secondary" | ||
small | ||
onClick={() => executeApply([poolId, policy.hash])} | ||
loading={isApplyLoading && lastCreatedTransaction?.args[1] === policy.hash} | ||
style={{ marginLeft: 'auto' }} | ||
> | ||
Apply | ||
</Button> | ||
</Shelf> | ||
) | ||
})} | ||
</Stack> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters