@huma-finance/widgets 0.0.80-beta.1079 → 0.0.80-beta.1083

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ import { StellarPoolInfo, TrancheType } from '../../../../../huma-shared/src';
2
+ import { StellarPoolState } from '../../../../../huma-web-shared/src';
3
+ import { default as React } from 'react';
4
+ type Props = {
5
+ poolInfo: StellarPoolInfo;
6
+ poolState: StellarPoolState;
7
+ selectedTranche: TrancheType;
8
+ };
9
+ export declare function ChooseAmount({ poolInfo, poolState, selectedTranche, }: Props): React.ReactElement | null;
10
+ export {};
@@ -0,0 +1,8 @@
1
+ import { StellarPoolInfo, TrancheType } from '../../../../../huma-shared/src';
2
+ import { default as React } from 'react';
3
+ type Props = {
4
+ poolInfo: StellarPoolInfo;
5
+ selectedTranche: TrancheType;
6
+ };
7
+ export declare function Transfer({ poolInfo, selectedTranche, }: Props): React.ReactElement | null;
8
+ export {};
@@ -0,0 +1,10 @@
1
+ import { StellarPoolInfo } from '../../../../../huma-shared/src';
2
+ import { default as React } from 'react';
3
+ type Props = {
4
+ poolInfo: StellarPoolInfo;
5
+ handleAction: (options?: {
6
+ isSuccess?: boolean;
7
+ }) => void;
8
+ };
9
+ export declare function Done({ poolInfo, handleAction }: Props): React.ReactElement;
10
+ export {};
@@ -0,0 +1,19 @@
1
+ import { CloseModalOptions, StellarPoolInfo, TrancheType } from '../../../../../huma-shared/src';
2
+ import { StellarPoolState } from '../../../../../huma-web-shared/src';
3
+ import { default as React } from 'react';
4
+ /**
5
+ * Stellar add redemption props – request to withdraw (redeem) shares from a tranche.
6
+ * @property {StellarPoolInfo} poolInfo The metadata of the pool.
7
+ * @property {StellarPoolState} poolState The current state config of the pool.
8
+ * @property {TrancheType} tranche The tranche to redeem from (junior or senior).
9
+ * @property {function((CloseModalOptions|undefined)):void} handleClose Function to close the widget modal.
10
+ * @property {function():void|undefined} handleSuccess Optional callback when redemption request succeeds.
11
+ */
12
+ export interface StellarLendAddRedemptionProps {
13
+ poolInfo: StellarPoolInfo;
14
+ poolState: StellarPoolState;
15
+ tranche: TrancheType;
16
+ handleClose: (options?: CloseModalOptions) => void;
17
+ handleSuccess?: () => void;
18
+ }
19
+ export declare function StellarLendAddRedemption({ poolInfo, poolState, tranche, handleClose, handleSuccess, }: StellarLendAddRedemptionProps): React.ReactElement | null;
@@ -0,0 +1,9 @@
1
+ import { StellarPoolInfo } from '../../../../../huma-shared/src';
2
+ import { default as React } from 'react';
3
+ type Props = {
4
+ poolInfo: StellarPoolInfo;
5
+ withdrawableAmountFormatted: string;
6
+ onConfirm: () => void;
7
+ };
8
+ export declare function Confirm({ poolInfo, withdrawableAmountFormatted, onConfirm, }: Props): React.ReactElement;
9
+ export {};
@@ -0,0 +1,9 @@
1
+ import { StellarPoolInfo, TrancheType } from '../../../../../huma-shared/src';
2
+ import { default as React } from 'react';
3
+ type Props = {
4
+ poolInfo: StellarPoolInfo;
5
+ tranche: TrancheType;
6
+ poolIsClosed: boolean;
7
+ };
8
+ export declare function Transfer({ poolInfo, tranche, poolIsClosed, }: Props): React.ReactElement | null;
9
+ export {};
@@ -0,0 +1,11 @@
1
+ import { StellarPoolInfo } from '../../../../../huma-shared/src';
2
+ import { default as React } from 'react';
3
+ type Props = {
4
+ poolInfo: StellarPoolInfo;
5
+ withdrawAmount?: number;
6
+ handleAction: (options?: {
7
+ isSuccess?: boolean;
8
+ }) => void;
9
+ };
10
+ export declare function Done({ poolInfo, withdrawAmount, handleAction, }: Props): React.ReactElement;
11
+ export {};
@@ -0,0 +1,19 @@
1
+ import { CloseModalOptions, StellarPoolInfo, TrancheType } from '../../../../../huma-shared/src';
2
+ import { StellarPoolState } from '../../../../../huma-web-shared/src';
3
+ import { default as React } from 'react';
4
+ /**
5
+ * Stellar lend pool withdraw props – disburse (pool open) or withdraw after pool closure.
6
+ * @property {StellarPoolInfo} poolInfo The metadata of the pool.
7
+ * @property {StellarPoolState} poolState The current state config of the pool.
8
+ * @property {TrancheType} tranche The tranche to withdraw from (junior or senior).
9
+ * @property {function((CloseModalOptions|undefined)):void} handleClose Function to close the widget modal.
10
+ * @property {function():void|undefined} handleSuccess Optional callback when withdraw succeeds.
11
+ */
12
+ export interface StellarLendWithdrawProps {
13
+ poolInfo: StellarPoolInfo;
14
+ poolState: StellarPoolState;
15
+ tranche: TrancheType;
16
+ handleClose: (options?: CloseModalOptions) => void;
17
+ handleSuccess?: () => void;
18
+ }
19
+ export declare function StellarLendWithdraw({ poolInfo, poolState, tranche, handleClose, handleSuccess, }: StellarLendWithdrawProps): React.ReactElement | null;
@@ -17,7 +17,9 @@ import { SolanaLendCancelRedemptionProps } from './components/Lend/solanaCancelR
17
17
  import { SolanaEnableAutoRedemptionProps } from './components/Lend/solanaEnableAutoRedemption';
18
18
  import { SolanaLendSupplyProps } from './components/Lend/solanaSupply';
19
19
  import { SolanaLendWithdrawProps } from './components/Lend/solanaWithdraw';
20
+ import { StellarLendAddRedemptionProps } from './components/Lend/stellarAddRedemption';
20
21
  import { StellarLendSupplyProps } from './components/Lend/stellarSupply';
22
+ import { StellarLendWithdrawProps } from './components/Lend/stellarWithdraw';
21
23
  import { LendSupplyProps } from './components/Lend/supply';
22
24
  import { LendSupplyPropsV2 } from './components/Lend/supplyV2';
23
25
  import { LendWithdrawProps } from './components/Lend/withdraw';
@@ -372,6 +374,28 @@ type StellarLendSupplyWidgetProps = StellarLendSupplyProps & GenericWidgetProps;
372
374
  * @param {StellarLendSupplyWidgetProps} props - Widget props
373
375
  */
374
376
  export declare function StellarLendSupplyWidget(props: StellarLendSupplyWidgetProps): import("@emotion/react/jsx-runtime").JSX.Element;
377
+ /**
378
+ * Lend pool add redemption widget props for Stellar pools
379
+ * @typedef {Object} StellarLendAddRedemptionWidgetProps
380
+ */
381
+ type StellarLendAddRedemptionWidgetProps = StellarLendAddRedemptionProps & GenericWidgetProps;
382
+ /**
383
+ * Lend pool add redemption widget for Stellar pools
384
+ *
385
+ * @param {StellarLendAddRedemptionWidgetProps} props - Widget props
386
+ */
387
+ export declare function StellarLendAddRedemptionWidget(props: StellarLendAddRedemptionWidgetProps): import("@emotion/react/jsx-runtime").JSX.Element;
388
+ /**
389
+ * Lend pool withdraw widget props for Stellar pools
390
+ * @typedef {Object} StellarLendWithdrawWidgetProps
391
+ */
392
+ type StellarLendWithdrawWidgetProps = StellarLendWithdrawProps & GenericWidgetProps;
393
+ /**
394
+ * Lend pool withdraw widget for Stellar pools (disburse when pool open, withdraw_after_pool_closure when closed)
395
+ *
396
+ * @param {StellarLendWithdrawWidgetProps} props - Widget props
397
+ */
398
+ export declare function StellarLendWithdrawWidget(props: StellarLendWithdrawWidgetProps): import("@emotion/react/jsx-runtime").JSX.Element;
375
399
  /**
376
400
  * Borrow widget props for Stellar pools
377
401
  * @typedef {Object} StellarLendSupplyWidgetProps
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huma-finance/widgets",
3
- "version": "0.0.80-beta.1079+8d198fb",
3
+ "version": "0.0.80-beta.1083+3658a09",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -22,9 +22,9 @@
22
22
  "@ethersproject/contracts": "^5.7.0",
23
23
  "@ethersproject/experimental": "^5.7.0",
24
24
  "@ethersproject/units": "^5.6.0",
25
- "@huma-finance/sdk": "^0.0.80-beta.1079+8d198fb",
26
- "@huma-finance/shared": "^0.0.80-beta.1079+8d198fb",
27
- "@huma-finance/web-shared": "^0.0.80-beta.1079+8d198fb",
25
+ "@huma-finance/sdk": "^0.0.80-beta.1083+3658a09",
26
+ "@huma-finance/shared": "^0.0.80-beta.1083+3658a09",
27
+ "@huma-finance/web-shared": "^0.0.80-beta.1083+3658a09",
28
28
  "@mui/x-date-pickers": "^5.0.7",
29
29
  "@notifi-network/notifi-frontend-client": "^1.1.2",
30
30
  "@notifi-network/notifi-react": "^1.1.2",
@@ -190,5 +190,5 @@
190
190
  "optionalDependencies": {
191
191
  "encoding": "^0.1.13"
192
192
  },
193
- "gitHead": "8d198fb139436a4c983f7d5b845ab446445072cd"
193
+ "gitHead": "3658a098a3c2b0d732685d4f0aacb3fbac42028d"
194
194
  }
@@ -0,0 +1,137 @@
1
+ import {
2
+ formatNumber,
3
+ StellarPoolInfo,
4
+ tokenDecimalUtils,
5
+ TrancheType,
6
+ } from '@huma-finance/shared'
7
+ import {
8
+ fetchStellarDepositRecord,
9
+ getStellarSharesFromUnderlyingTokenAmount,
10
+ StellarConnectionContext,
11
+ StellarPoolState,
12
+ } from '@huma-finance/web-shared'
13
+ import React, { useCallback, useContext, useEffect, useState } from 'react'
14
+ import { useAppDispatch } from '../../../hooks/useRedux'
15
+ import {
16
+ setRedeemAmount,
17
+ setRedeemShares,
18
+ setStep,
19
+ } from '../../../store/widgets.reducers'
20
+ import { WIDGET_STEP } from '../../../store/widgets.store'
21
+ import { InputAmountModal } from '../../InputAmountModal'
22
+ import { LoadingModal } from '../../LoadingModal'
23
+
24
+ type Props = {
25
+ poolInfo: StellarPoolInfo
26
+ poolState: StellarPoolState
27
+ selectedTranche: TrancheType
28
+ }
29
+
30
+ export function ChooseAmount({
31
+ poolInfo,
32
+ poolState,
33
+ selectedTranche,
34
+ }: Props): React.ReactElement | null {
35
+ const dispatch = useAppDispatch()
36
+ const { address: stellarAddress } = useContext(StellarConnectionContext)
37
+ const [currentAmount, setCurrentAmount] = useState<number | string>(0)
38
+ const [principal, setPrincipal] = useState<bigint | null>(null)
39
+ const [isLoadingDepositRecord, setIsLoadingDepositRecord] = useState(true)
40
+
41
+ const { symbol, decimals: underlyingDecimals } = poolInfo.underlyingToken
42
+ const { trancheDecimals } = poolInfo
43
+
44
+ const totalAssets = BigInt(
45
+ selectedTranche === 'senior'
46
+ ? poolState.seniorTrancheAssets ?? 0
47
+ : poolState.juniorTrancheAssets ?? 0,
48
+ )
49
+ const totalSupply = BigInt(
50
+ selectedTranche === 'senior'
51
+ ? poolState.seniorTrancheTokenSupply ?? 0
52
+ : poolState.juniorTrancheTokenSupply ?? 0,
53
+ )
54
+
55
+ useEffect(() => {
56
+ let cancelled = false
57
+ async function load() {
58
+ if (!stellarAddress) {
59
+ setIsLoadingDepositRecord(false)
60
+ return
61
+ }
62
+ setIsLoadingDepositRecord(true)
63
+ try {
64
+ const record = await fetchStellarDepositRecord(
65
+ poolInfo,
66
+ selectedTranche,
67
+ stellarAddress,
68
+ )
69
+ if (!cancelled) {
70
+ setPrincipal(record?.principal ?? 0n)
71
+ }
72
+ } finally {
73
+ if (!cancelled) {
74
+ setIsLoadingDepositRecord(false)
75
+ }
76
+ }
77
+ }
78
+ load()
79
+ return () => {
80
+ cancelled = true
81
+ }
82
+ }, [poolInfo, selectedTranche, stellarAddress])
83
+
84
+ const maxUnderlyingFormatted = useCallback(() => {
85
+ if (principal == null) return 0
86
+ return Number(tokenDecimalUtils.formatUnits(principal, underlyingDecimals))
87
+ }, [principal, underlyingDecimals])
88
+
89
+ const handleChangeAmount = useCallback(
90
+ (amount: number) => {
91
+ setCurrentAmount(amount)
92
+ dispatch(setRedeemAmount(amount))
93
+ if (amount <= 0 || totalAssets <= 0n) {
94
+ dispatch(setRedeemShares(0))
95
+ return
96
+ }
97
+ const underlyingRaw = tokenDecimalUtils.parseUnits(
98
+ String(amount),
99
+ underlyingDecimals,
100
+ )
101
+ const sharesRaw = getStellarSharesFromUnderlyingTokenAmount(
102
+ underlyingRaw,
103
+ totalAssets,
104
+ totalSupply,
105
+ )
106
+ const sharesFormatted = Number(
107
+ tokenDecimalUtils.formatUnits(sharesRaw, trancheDecimals),
108
+ )
109
+ dispatch(setRedeemShares(sharesFormatted))
110
+ },
111
+ [dispatch, underlyingDecimals, trancheDecimals, totalAssets, totalSupply],
112
+ )
113
+
114
+ const handleAction = useCallback(() => {
115
+ dispatch(setStep(WIDGET_STEP.Transfer))
116
+ }, [dispatch])
117
+
118
+ if (isLoadingDepositRecord) {
119
+ return <LoadingModal title='Redemption' />
120
+ }
121
+
122
+ const maxUnderlying = maxUnderlyingFormatted()
123
+
124
+ return (
125
+ <InputAmountModal
126
+ title='Redemption'
127
+ subTitle={`Enter amount of ${symbol} to withdraw from the ${selectedTranche} tranche`}
128
+ tokenSymbol={symbol}
129
+ currentAmount={currentAmount}
130
+ handleChangeAmount={handleChangeAmount}
131
+ maxAmount={maxUnderlying}
132
+ maxAmountTitle={`${formatNumber(maxUnderlying)} ${symbol} requestable`}
133
+ handleAction={handleAction}
134
+ actionText='REQUEST'
135
+ />
136
+ )
137
+ }
@@ -0,0 +1,70 @@
1
+ import {
2
+ STELLAR_CHAINS_INFO,
3
+ StellarPoolInfo,
4
+ tokenDecimalUtils,
5
+ TrancheType,
6
+ } from '@huma-finance/shared'
7
+ import { Client as TrancheVaultClient } from '@huma-finance/soroban-tranche-vault'
8
+ import AssembledTransaction from '@stellar/stellar-sdk'
9
+ import React, { useCallback, useContext, useEffect, useState } from 'react'
10
+
11
+ import {
12
+ getClientCommonParams,
13
+ StellarConnectionContext,
14
+ } from '@huma-finance/web-shared'
15
+ import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
16
+ import { setStep } from '../../../store/widgets.reducers'
17
+ import { selectWidgetState } from '../../../store/widgets.selectors'
18
+ import { WIDGET_STEP } from '../../../store/widgets.store'
19
+ import { StellarTxSendModal } from '../../StellarTxSendModal'
20
+
21
+ type Props = {
22
+ poolInfo: StellarPoolInfo
23
+ selectedTranche: TrancheType
24
+ }
25
+
26
+ export function Transfer({
27
+ poolInfo,
28
+ selectedTranche,
29
+ }: Props): React.ReactElement | null {
30
+ const dispatch = useAppDispatch()
31
+ const [tx, setTx] = useState<typeof AssembledTransaction | null>(null)
32
+ const { address: stellarAddress } = useContext(StellarConnectionContext)
33
+ const { redeemShares } = useAppSelector(selectWidgetState)
34
+ const decimals = poolInfo.trancheDecimals
35
+ const sharesBN = tokenDecimalUtils.parseUnits(
36
+ String(redeemShares ?? 0),
37
+ decimals,
38
+ )
39
+
40
+ const handleSuccess = useCallback(async () => {
41
+ dispatch(setStep(WIDGET_STEP.Done))
42
+ }, [dispatch])
43
+
44
+ useEffect(() => {
45
+ async function getTx() {
46
+ if (!stellarAddress || sharesBN <= BigInt(0)) {
47
+ return
48
+ }
49
+
50
+ const chainMetadata = STELLAR_CHAINS_INFO[poolInfo.chainId]
51
+ const trancheVaultClient = new TrancheVaultClient({
52
+ publicKey: stellarAddress,
53
+ contractId:
54
+ selectedTranche === 'senior'
55
+ ? poolInfo.seniorTranche!
56
+ : poolInfo.juniorTranche,
57
+ ...getClientCommonParams(chainMetadata, stellarAddress),
58
+ })
59
+ const assembledTx = await trancheVaultClient.add_redemption_request({
60
+ caller: stellarAddress,
61
+ lender: stellarAddress,
62
+ shares: sharesBN,
63
+ })
64
+ setTx(assembledTx)
65
+ }
66
+ getTx()
67
+ }, [poolInfo, selectedTranche, stellarAddress, sharesBN])
68
+
69
+ return <StellarTxSendModal tx={tx} handleSuccess={handleSuccess} />
70
+ }
@@ -0,0 +1,33 @@
1
+ import { formatNumber, StellarPoolInfo } from '@huma-finance/shared'
2
+ import React, { useCallback } from 'react'
3
+ import { useAppSelector } from '../../../hooks/useRedux'
4
+ import { selectWidgetState } from '../../../store/widgets.selectors'
5
+ import { StellarTxDoneModal } from '../../StellarTxDoneModal'
6
+
7
+ type Props = {
8
+ poolInfo: StellarPoolInfo
9
+ handleAction: (options?: { isSuccess?: boolean }) => void
10
+ }
11
+
12
+ export function Done({ poolInfo, handleAction }: Props): React.ReactElement {
13
+ const { redeemAmount, txHash } = useAppSelector(selectWidgetState)
14
+ const { symbol } = poolInfo.underlyingToken
15
+
16
+ const content = [
17
+ `${formatNumber(redeemAmount ?? 0)} ${symbol} requested for withdrawal`,
18
+ ]
19
+
20
+ const handleUserAction = useCallback(() => {
21
+ handleAction({ isSuccess: true })
22
+ }, [handleAction])
23
+
24
+ return (
25
+ <StellarTxDoneModal
26
+ chainId={poolInfo.chainId}
27
+ handleAction={handleUserAction}
28
+ content={content}
29
+ txHash={txHash}
30
+ buttonText='DONE'
31
+ />
32
+ )
33
+ }
@@ -0,0 +1,88 @@
1
+ import {
2
+ CloseModalOptions,
3
+ StellarPoolInfo,
4
+ TrancheType,
5
+ } from '@huma-finance/shared'
6
+ import {
7
+ StellarConnectionContext,
8
+ StellarPoolState,
9
+ } from '@huma-finance/web-shared'
10
+ import React, { useContext, useEffect } from 'react'
11
+ import { useDispatch } from 'react-redux'
12
+
13
+ import { useAppSelector } from '../../../hooks/useRedux'
14
+ import { setStep } from '../../../store/widgets.reducers'
15
+ import { selectWidgetState } from '../../../store/widgets.selectors'
16
+ import { WIDGET_STEP } from '../../../store/widgets.store'
17
+ import { ErrorModal } from '../../ErrorModal'
18
+ import { WidgetWrapper } from '../../WidgetWrapper'
19
+ import { ChooseAmount } from './1-ChooseAmount'
20
+ import { Transfer } from './2-Transfer'
21
+ import { Done } from './3-Done'
22
+
23
+ /**
24
+ * Stellar add redemption props – request to withdraw (redeem) shares from a tranche.
25
+ * @property {StellarPoolInfo} poolInfo The metadata of the pool.
26
+ * @property {StellarPoolState} poolState The current state config of the pool.
27
+ * @property {TrancheType} tranche The tranche to redeem from (junior or senior).
28
+ * @property {function((CloseModalOptions|undefined)):void} handleClose Function to close the widget modal.
29
+ * @property {function():void|undefined} handleSuccess Optional callback when redemption request succeeds.
30
+ */
31
+ export interface StellarLendAddRedemptionProps {
32
+ poolInfo: StellarPoolInfo
33
+ poolState: StellarPoolState
34
+ tranche: TrancheType
35
+ handleClose: (options?: CloseModalOptions) => void
36
+ handleSuccess?: () => void
37
+ }
38
+
39
+ export function StellarLendAddRedemption({
40
+ poolInfo,
41
+ poolState,
42
+ tranche,
43
+ handleClose,
44
+ handleSuccess,
45
+ }: StellarLendAddRedemptionProps): React.ReactElement | null {
46
+ const dispatch = useDispatch()
47
+ const { address: stellarAddress } = useContext(StellarConnectionContext)
48
+ const { step, errorMessage } = useAppSelector(selectWidgetState)
49
+
50
+ useEffect(() => {
51
+ if (!step && stellarAddress) {
52
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
53
+ }
54
+ }, [dispatch, step, stellarAddress])
55
+
56
+ const title = 'Redemption'
57
+
58
+ return (
59
+ <WidgetWrapper
60
+ isOpen
61
+ loadingTitle={title}
62
+ handleClose={handleClose}
63
+ handleSuccess={handleSuccess}
64
+ >
65
+ {step === WIDGET_STEP.ChooseAmount && (
66
+ <ChooseAmount
67
+ poolInfo={poolInfo}
68
+ poolState={poolState}
69
+ selectedTranche={tranche}
70
+ />
71
+ )}
72
+ {step === WIDGET_STEP.Transfer && (
73
+ <Transfer poolInfo={poolInfo} selectedTranche={tranche} />
74
+ )}
75
+ {step === WIDGET_STEP.Done && (
76
+ <Done poolInfo={poolInfo} handleAction={handleClose} />
77
+ )}
78
+ {step === WIDGET_STEP.Error && (
79
+ <ErrorModal
80
+ title={title}
81
+ errorReason='Sorry there was an error'
82
+ errorMessage={errorMessage}
83
+ handleOk={handleClose}
84
+ />
85
+ )}
86
+ </WidgetWrapper>
87
+ )
88
+ }
@@ -0,0 +1,60 @@
1
+ import { StellarPoolInfo } from '@huma-finance/shared'
2
+ import { Box, css, useTheme } from '@mui/material'
3
+ import React from 'react'
4
+ import { BottomButton } from '../../BottomButton'
5
+ import { WrapperModal } from '../../WrapperModal'
6
+
7
+ type Props = {
8
+ poolInfo: StellarPoolInfo
9
+ withdrawableAmountFormatted: string
10
+ onConfirm: () => void
11
+ }
12
+
13
+ export function Confirm({
14
+ poolInfo,
15
+ withdrawableAmountFormatted,
16
+ onConfirm,
17
+ }: Props): React.ReactElement {
18
+ const theme = useTheme()
19
+ const { symbol } = poolInfo.underlyingToken
20
+
21
+ const styles = {
22
+ itemWrapper: css`
23
+ margin-top: ${theme.spacing(9)};
24
+ color: ${theme.palette.text.primary};
25
+ font-weight: 400;
26
+ font-size: 16px;
27
+ line-height: 175%;
28
+ letter-spacing: 0.15px;
29
+ `,
30
+ item: css`
31
+ display: flex;
32
+ justify-content: space-between;
33
+ align-items: center;
34
+ margin-bottom: ${theme.spacing(3)};
35
+ `,
36
+ itemValue: css`
37
+ font-size: 20px;
38
+ font-weight: 700;
39
+ `,
40
+ }
41
+
42
+ return (
43
+ <WrapperModal
44
+ title={`Withdraw ${symbol}`}
45
+ subTitle='Withdraw all the available amount'
46
+ >
47
+ <Box css={styles.itemWrapper}>
48
+ <Box css={styles.item}>
49
+ <Box fontWeight={700}>Available to withdraw</Box>
50
+ <Box css={styles.itemValue}>
51
+ {withdrawableAmountFormatted} {symbol}
52
+ </Box>
53
+ </Box>
54
+ </Box>
55
+ <BottomButton variant='contained' onClick={onConfirm}>
56
+ WITHDRAW
57
+ </BottomButton>
58
+ </WrapperModal>
59
+ )
60
+ }
@@ -0,0 +1,67 @@
1
+ import {
2
+ STELLAR_CHAINS_INFO,
3
+ StellarPoolInfo,
4
+ TrancheType,
5
+ } from '@huma-finance/shared'
6
+ import { Client as TrancheVaultClient } from '@huma-finance/soroban-tranche-vault'
7
+ import React, { useCallback, useContext, useEffect, useState } from 'react'
8
+
9
+ import {
10
+ getClientCommonParams,
11
+ StellarConnectionContext,
12
+ } from '@huma-finance/web-shared'
13
+ import { useAppDispatch } from '../../../hooks/useRedux'
14
+ import { setStep } from '../../../store/widgets.reducers'
15
+ import { WIDGET_STEP } from '../../../store/widgets.store'
16
+ import { StellarTxSendModal } from '../../StellarTxSendModal'
17
+
18
+ type Props = {
19
+ poolInfo: StellarPoolInfo
20
+ tranche: TrancheType
21
+ poolIsClosed: boolean
22
+ }
23
+
24
+ export function Transfer({
25
+ poolInfo,
26
+ tranche,
27
+ poolIsClosed,
28
+ }: Props): React.ReactElement | null {
29
+ const dispatch = useAppDispatch()
30
+ const { address: stellarAddress } = useContext(StellarConnectionContext)
31
+ const [tx, setTx] = useState<Awaited<
32
+ ReturnType<TrancheVaultClient['disburse']>
33
+ > | null>(null)
34
+
35
+ const handleSuccess = useCallback(async () => {
36
+ dispatch(setStep(WIDGET_STEP.Done))
37
+ }, [dispatch])
38
+
39
+ useEffect(() => {
40
+ async function getTx() {
41
+ if (!stellarAddress) {
42
+ return
43
+ }
44
+
45
+ const chainMetadata = STELLAR_CHAINS_INFO[poolInfo.chainId]
46
+ const contractId =
47
+ tranche === 'senior' ? poolInfo.seniorTranche! : poolInfo.juniorTranche
48
+ const trancheVaultClient = new TrancheVaultClient({
49
+ publicKey: stellarAddress,
50
+ contractId,
51
+ ...getClientCommonParams(chainMetadata, stellarAddress),
52
+ })
53
+
54
+ const assembledTx = poolIsClosed
55
+ ? await trancheVaultClient.withdraw_after_pool_closure({
56
+ lender: stellarAddress,
57
+ })
58
+ : await trancheVaultClient.disburse({
59
+ lender: stellarAddress,
60
+ })
61
+ setTx(assembledTx)
62
+ }
63
+ getTx()
64
+ }, [poolInfo, tranche, poolIsClosed, stellarAddress])
65
+
66
+ return <StellarTxSendModal tx={tx} handleSuccess={handleSuccess} />
67
+ }
@@ -0,0 +1,38 @@
1
+ import { formatNumber, StellarPoolInfo } from '@huma-finance/shared'
2
+ import React, { useCallback } from 'react'
3
+ import { useAppSelector } from '../../../hooks/useRedux'
4
+ import { selectWidgetState } from '../../../store/widgets.selectors'
5
+ import { StellarTxDoneModal } from '../../StellarTxDoneModal'
6
+
7
+ type Props = {
8
+ poolInfo: StellarPoolInfo
9
+ withdrawAmount?: number
10
+ handleAction: (options?: { isSuccess?: boolean }) => void
11
+ }
12
+
13
+ export function Done({
14
+ poolInfo,
15
+ withdrawAmount,
16
+ handleAction,
17
+ }: Props): React.ReactElement {
18
+ const { txHash } = useAppSelector(selectWidgetState)
19
+ const { symbol } = poolInfo.underlyingToken
20
+
21
+ const content = [
22
+ `${formatNumber(withdrawAmount ?? 0)} ${symbol} withdrawn to your wallet`,
23
+ ]
24
+
25
+ const handleUserAction = useCallback(() => {
26
+ handleAction({ isSuccess: true })
27
+ }, [handleAction])
28
+
29
+ return (
30
+ <StellarTxDoneModal
31
+ chainId={poolInfo.chainId}
32
+ handleAction={handleUserAction}
33
+ content={content}
34
+ txHash={txHash}
35
+ buttonText='DONE'
36
+ />
37
+ )
38
+ }