@huma-finance/widgets 0.0.73-beta.950 → 0.0.73-beta.954
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.
- package/API.md +38 -0
- package/dist/index.js +19689 -19293
- package/dist/src/components/CreditLine/stellarBorrow/1-ChooseAmount.d.ts +8 -0
- package/dist/src/components/CreditLine/stellarBorrow/2-ApproveAllowance.d.ts +7 -0
- package/dist/src/components/CreditLine/stellarBorrow/3-Transfer.d.ts +7 -0
- package/dist/src/components/CreditLine/stellarBorrow/4-Success.d.ts +10 -0
- package/dist/src/components/CreditLine/stellarBorrow/index.d.ts +18 -0
- package/dist/src/index.d.ts +12 -0
- package/package.json +8 -6
- package/src/components/CreditLine/stellarBorrow/1-ChooseAmount.tsx +45 -0
- package/src/components/CreditLine/stellarBorrow/2-ApproveAllowance.tsx +119 -0
- package/src/components/CreditLine/stellarBorrow/3-Transfer.tsx +61 -0
- package/src/components/CreditLine/stellarBorrow/4-Success.tsx +46 -0
- package/src/components/CreditLine/stellarBorrow/index.tsx +100 -0
- package/src/index.tsx +23 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StellarPoolInfo } from '../../../../../huma-shared/src';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
type Props = {
|
|
4
|
+
poolInfo: StellarPoolInfo;
|
|
5
|
+
creditAvailable: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function ChooseAmount({ poolInfo, creditAvailable, }: Props): React.ReactElement | null;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CloseModalOptions, StellarPoolInfo } from '../../../../../huma-shared/src';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
import { StellarPoolState } from '../../../../../huma-web-shared/src';
|
|
4
|
+
type Props = {
|
|
5
|
+
poolInfo: StellarPoolInfo;
|
|
6
|
+
poolState: StellarPoolState;
|
|
7
|
+
handleAction: (options?: CloseModalOptions) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare function Success({ poolInfo, poolState, handleAction, }: Props): React.ReactElement;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CloseModalOptions, StellarPoolInfo } from '../../../../../huma-shared/src';
|
|
2
|
+
import { StellarPoolState } from '../../../../../huma-web-shared/src';
|
|
3
|
+
import { default as React } from 'react';
|
|
4
|
+
/**
|
|
5
|
+
* Stellar pool borrow widget props
|
|
6
|
+
* @typedef {Object} StellarBorrowProps
|
|
7
|
+
* @property {StellarPoolInfo} poolInfo The metadata of the pool.
|
|
8
|
+
* @property {StellarPoolState} poolState The current state config of the pool.
|
|
9
|
+
* @property {function((CloseModalOptions|undefined)):void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
10
|
+
* @property {function():void|undefined} handleSuccess Optional function to notify that the lending pool supply action is successful.
|
|
11
|
+
*/
|
|
12
|
+
export interface StellarBorrowProps {
|
|
13
|
+
poolInfo: StellarPoolInfo;
|
|
14
|
+
poolState: StellarPoolState;
|
|
15
|
+
handleClose: (options?: CloseModalOptions) => void;
|
|
16
|
+
handleSuccess?: () => void;
|
|
17
|
+
}
|
|
18
|
+
export declare function StellarBorrow({ poolInfo, poolState, handleClose, handleSuccess, }: StellarBorrowProps): React.ReactElement | null;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { LendWithdrawProps } from './components/Lend/withdraw';
|
|
|
24
24
|
import { LendWithdrawPropsV2 } from './components/Lend/withdrawV2';
|
|
25
25
|
import { ReceivableBackedCreditLineBorrowPropsV2 } from './components/ReceivableBackedCreditLine/borrow';
|
|
26
26
|
import { ReceivableBackedCreditLinePaymentPropsV2 } from './components/ReceivableBackedCreditLine/payment';
|
|
27
|
+
import { StellarBorrowProps } from './components/CreditLine/stellarBorrow';
|
|
27
28
|
/**
|
|
28
29
|
* Mapping of your JSON-RPC connections indexed by chainId
|
|
29
30
|
* @typedef {Object} JsonRpcConnectionMap
|
|
@@ -371,6 +372,17 @@ type StellarLendSupplyWidgetProps = StellarLendSupplyProps & GenericWidgetProps;
|
|
|
371
372
|
* @param {StellarLendSupplyWidgetProps} props - Widget props
|
|
372
373
|
*/
|
|
373
374
|
export declare function StellarLendSupplyWidget(props: StellarLendSupplyWidgetProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
375
|
+
/**
|
|
376
|
+
* Borrow widget props for Stellar pools
|
|
377
|
+
* @typedef {Object} StellarLendSupplyWidgetProps
|
|
378
|
+
*/
|
|
379
|
+
type StellarBorrowWidgetProps = StellarBorrowProps & GenericWidgetProps;
|
|
380
|
+
/**
|
|
381
|
+
* Borrow widget for Stellar pools
|
|
382
|
+
*
|
|
383
|
+
* @param {StellarBorrowWidgetProps} props - Widget props
|
|
384
|
+
*/
|
|
385
|
+
export declare function StellarBorrowWidget(props: StellarBorrowWidgetProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
374
386
|
/**
|
|
375
387
|
* Lend pool supply widget props for Solana pools
|
|
376
388
|
* @typedef {Object} SolanaEnableAutoRedemptionWidgetProps
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/widgets",
|
|
3
|
-
"version": "0.0.73-beta.
|
|
3
|
+
"version": "0.0.73-beta.954+dbbe72e",
|
|
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.73-beta.
|
|
26
|
-
"@huma-finance/shared": "^0.0.73-beta.
|
|
27
|
-
"@huma-finance/web-shared": "^0.0.73-beta.
|
|
25
|
+
"@huma-finance/sdk": "^0.0.73-beta.954+dbbe72e",
|
|
26
|
+
"@huma-finance/shared": "^0.0.73-beta.954+dbbe72e",
|
|
27
|
+
"@huma-finance/web-shared": "^0.0.73-beta.954+dbbe72e",
|
|
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",
|
|
@@ -159,7 +159,8 @@
|
|
|
159
159
|
"@emotion/react": "^11.5.0",
|
|
160
160
|
"@emotion/styled": "^11.3.0",
|
|
161
161
|
"@ethersproject/providers": "5.7.2",
|
|
162
|
-
"@huma-finance/soroban-
|
|
162
|
+
"@huma-finance/soroban-sep41": "0.0.23",
|
|
163
|
+
"@huma-finance/soroban-tranche-vault": "0.0.23",
|
|
163
164
|
"@mui/icons-material": "^5.3.0",
|
|
164
165
|
"@mui/material": "^5.0.6",
|
|
165
166
|
"@mui/styles": "^5.0.2",
|
|
@@ -170,6 +171,7 @@
|
|
|
170
171
|
"@solana/wallet-adapter-react": "0.15.35",
|
|
171
172
|
"@solana/web3.js": "^1.95.3",
|
|
172
173
|
"@soroban-react/core": "^9.3.0",
|
|
174
|
+
"@stellar/stellar-sdk": "13.0.0",
|
|
173
175
|
"@vitejs/plugin-react": "4.3.4",
|
|
174
176
|
"arweave": "^1.10.0",
|
|
175
177
|
"bs58": "6.0.0",
|
|
@@ -188,5 +190,5 @@
|
|
|
188
190
|
"optionalDependencies": {
|
|
189
191
|
"encoding": "^0.1.13"
|
|
190
192
|
},
|
|
191
|
-
"gitHead": "
|
|
193
|
+
"gitHead": "dbbe72e2b42c554da0f293a33a22a7cd6d9d93ba"
|
|
192
194
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { formatNumber, StellarPoolInfo } from '@huma-finance/shared'
|
|
2
|
+
import React, { useState } from 'react'
|
|
3
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
4
|
+
import { setStep, setSupplyAmount } from '../../../store/widgets.reducers'
|
|
5
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
6
|
+
import { InputAmountModal } from '../../InputAmountModal'
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
poolInfo: StellarPoolInfo
|
|
10
|
+
creditAvailable: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function ChooseAmount({
|
|
14
|
+
poolInfo,
|
|
15
|
+
creditAvailable,
|
|
16
|
+
}: Props): React.ReactElement | null {
|
|
17
|
+
const dispatch = useAppDispatch()
|
|
18
|
+
const { symbol } = poolInfo.underlyingToken
|
|
19
|
+
const [currentAmount, setCurrentAmount] = useState<number | string>(0)
|
|
20
|
+
|
|
21
|
+
const handleChangeAmount = (newAmount: number) => {
|
|
22
|
+
setCurrentAmount(newAmount)
|
|
23
|
+
dispatch(setSupplyAmount(Number(newAmount)))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const handleAction = () => {
|
|
27
|
+
dispatch(setStep(WIDGET_STEP.ApproveAllowance))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<InputAmountModal
|
|
32
|
+
title='Borrow'
|
|
33
|
+
subTitle='Choose Amount'
|
|
34
|
+
tokenSymbol={symbol}
|
|
35
|
+
currentAmount={currentAmount}
|
|
36
|
+
handleChangeAmount={handleChangeAmount}
|
|
37
|
+
maxAmount={creditAvailable}
|
|
38
|
+
maxAmountTitle={`${String(
|
|
39
|
+
formatNumber(creditAvailable),
|
|
40
|
+
)} ${symbol} Available`}
|
|
41
|
+
handleAction={handleAction}
|
|
42
|
+
actionText='BORROW'
|
|
43
|
+
/>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { STELLAR_CHAINS_INFO, StellarPoolInfo } from '@huma-finance/shared'
|
|
2
|
+
import { Box, css, useTheme } from '@mui/material'
|
|
3
|
+
import { Client as Sep41TokenClient } from '@huma-finance/soroban-sep41'
|
|
4
|
+
import React, { useCallback, useContext, useState } from 'react'
|
|
5
|
+
|
|
6
|
+
import { rpc, xdr } from '@stellar/stellar-sdk'
|
|
7
|
+
import {
|
|
8
|
+
fetchStellarPoolSentinel,
|
|
9
|
+
getClientCommonParams,
|
|
10
|
+
StellarConnectionContext,
|
|
11
|
+
} from '@huma-finance/web-shared'
|
|
12
|
+
import { WrapperModal } from '../../WrapperModal'
|
|
13
|
+
import { AutoPaybackImg } from '../../images'
|
|
14
|
+
import { BottomButton } from '../../BottomButton'
|
|
15
|
+
import { StellarTxSendModal } from '../../StellarTxSendModal'
|
|
16
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
17
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
18
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
19
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
20
|
+
|
|
21
|
+
type Props = {
|
|
22
|
+
poolInfo: StellarPoolInfo
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function ApproveAllowance({
|
|
26
|
+
poolInfo,
|
|
27
|
+
}: Props): React.ReactElement | null {
|
|
28
|
+
const dispatch = useAppDispatch()
|
|
29
|
+
const theme = useTheme()
|
|
30
|
+
const { address: stellarAddress } = useContext(StellarConnectionContext)
|
|
31
|
+
const { symbol, decimals } = poolInfo.underlyingToken
|
|
32
|
+
const [tx, setTx] = useState<xdr.Transaction | null>(null)
|
|
33
|
+
const [loadingTx, setLoadingTx] = useState(false)
|
|
34
|
+
|
|
35
|
+
const styles = {
|
|
36
|
+
iconWrapper: css`
|
|
37
|
+
${theme.cssMixins.rowCentered};
|
|
38
|
+
margin-top: ${theme.spacing(6)};
|
|
39
|
+
& > img {
|
|
40
|
+
width: 220px;
|
|
41
|
+
}
|
|
42
|
+
`,
|
|
43
|
+
description: css`
|
|
44
|
+
margin-top: ${theme.spacing(4)};
|
|
45
|
+
font-weight: 400;
|
|
46
|
+
font-size: 16px;
|
|
47
|
+
color: ${theme.palette.text.secondary};
|
|
48
|
+
padding: ${theme.spacing(0, 1)};
|
|
49
|
+
`,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const handleSuccess = useCallback(async () => {
|
|
53
|
+
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
54
|
+
}, [dispatch])
|
|
55
|
+
|
|
56
|
+
const sendIncreaseAllowance = useCallback(async () => {
|
|
57
|
+
if (!stellarAddress) {
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
setLoadingTx(true)
|
|
61
|
+
|
|
62
|
+
const sentinelAddress = await fetchStellarPoolSentinel(
|
|
63
|
+
poolInfo,
|
|
64
|
+
stellarAddress,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
const chainMetadata = STELLAR_CHAINS_INFO[poolInfo.chainId]
|
|
68
|
+
const server = new rpc.Server(chainMetadata.rpc, {
|
|
69
|
+
allowHttp: true,
|
|
70
|
+
})
|
|
71
|
+
const latestLedger = await server.getLatestLedger()
|
|
72
|
+
const advanceLedgerNum = 3_000_000
|
|
73
|
+
|
|
74
|
+
const client = new Sep41TokenClient({
|
|
75
|
+
publicKey: stellarAddress,
|
|
76
|
+
contractId: poolInfo.underlyingToken.address,
|
|
77
|
+
...getClientCommonParams(chainMetadata, stellarAddress),
|
|
78
|
+
})
|
|
79
|
+
const tx = await client.approve({
|
|
80
|
+
from: stellarAddress,
|
|
81
|
+
spender: sentinelAddress,
|
|
82
|
+
amount: BigInt(1_000_000_000) * BigInt(10) ** BigInt(decimals),
|
|
83
|
+
expiration_ledger: latestLedger.sequence + advanceLedgerNum,
|
|
84
|
+
})
|
|
85
|
+
setTx(tx)
|
|
86
|
+
setLoadingTx(false)
|
|
87
|
+
}, [decimals, poolInfo, stellarAddress])
|
|
88
|
+
|
|
89
|
+
if (loadingTx) {
|
|
90
|
+
return (
|
|
91
|
+
<LoadingModal
|
|
92
|
+
title='Generating Approval Transaction'
|
|
93
|
+
description='Loading...'
|
|
94
|
+
/>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!tx) {
|
|
99
|
+
return (
|
|
100
|
+
<WrapperModal
|
|
101
|
+
title='Auto Payback'
|
|
102
|
+
subTitle='Approve token allowance to enable autopayments.'
|
|
103
|
+
>
|
|
104
|
+
<Box css={styles.iconWrapper}>
|
|
105
|
+
<img src={AutoPaybackImg} alt='auto-payback' />
|
|
106
|
+
</Box>
|
|
107
|
+
<Box css={styles.description}>
|
|
108
|
+
This allowance transaction allows our automation to make minimum
|
|
109
|
+
payments automatically on your behalf.
|
|
110
|
+
</Box>
|
|
111
|
+
<BottomButton variant='contained' onClick={sendIncreaseAllowance}>
|
|
112
|
+
APPROVE {symbol} PAYMENTS
|
|
113
|
+
</BottomButton>
|
|
114
|
+
</WrapperModal>
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return <StellarTxSendModal tx={tx} handleSuccess={handleSuccess} />
|
|
119
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
STELLAR_CHAINS_INFO,
|
|
3
|
+
StellarPoolInfo,
|
|
4
|
+
tokenDecimalUtils,
|
|
5
|
+
} from '@huma-finance/shared'
|
|
6
|
+
import AssembledTransaction from '@stellar/stellar-sdk'
|
|
7
|
+
import { Client as PoolCreditClient } from '@huma-finance/soroban-pool-credit'
|
|
8
|
+
import React, { useCallback, useContext, useEffect, useState } from 'react'
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
getClientCommonParams,
|
|
12
|
+
StellarConnectionContext,
|
|
13
|
+
} from '@huma-finance/web-shared'
|
|
14
|
+
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
15
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
16
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
17
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
18
|
+
import { StellarTxSendModal } from '../../StellarTxSendModal'
|
|
19
|
+
|
|
20
|
+
type Props = {
|
|
21
|
+
poolInfo: StellarPoolInfo
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function Transfer({ poolInfo }: Props): React.ReactElement | null {
|
|
25
|
+
const dispatch = useAppDispatch()
|
|
26
|
+
const [tx, setTx] = useState<typeof AssembledTransaction | null>(null)
|
|
27
|
+
const { address: stellarAddress } = useContext(StellarConnectionContext)
|
|
28
|
+
const { supplyAmount } = useAppSelector(selectWidgetState)
|
|
29
|
+
const { decimals } = poolInfo.underlyingToken
|
|
30
|
+
const supplyBigNumber = tokenDecimalUtils.parseUnits(
|
|
31
|
+
String(supplyAmount),
|
|
32
|
+
decimals,
|
|
33
|
+
)
|
|
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 poolClient = new PoolCreditClient({
|
|
47
|
+
publicKey: stellarAddress,
|
|
48
|
+
contractId: poolInfo.poolCredit,
|
|
49
|
+
...getClientCommonParams(chainMetadata, stellarAddress),
|
|
50
|
+
})
|
|
51
|
+
const tx = await poolClient.drawdown({
|
|
52
|
+
borrower: stellarAddress,
|
|
53
|
+
amount: supplyBigNumber,
|
|
54
|
+
})
|
|
55
|
+
setTx(tx)
|
|
56
|
+
}
|
|
57
|
+
getTx()
|
|
58
|
+
}, [poolInfo, stellarAddress, supplyBigNumber])
|
|
59
|
+
|
|
60
|
+
return <StellarTxSendModal tx={tx} handleSuccess={handleSuccess} />
|
|
61
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CloseModalOptions,
|
|
3
|
+
formatNumber,
|
|
4
|
+
StellarPoolInfo,
|
|
5
|
+
timeUtil,
|
|
6
|
+
} from '@huma-finance/shared'
|
|
7
|
+
import React, { useCallback } from 'react'
|
|
8
|
+
import { StellarPoolState } from '@huma-finance/web-shared'
|
|
9
|
+
import { useAppSelector } from '../../../hooks/useRedux'
|
|
10
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
11
|
+
import { StellarTxDoneModal } from '../../StellarTxDoneModal'
|
|
12
|
+
|
|
13
|
+
type Props = {
|
|
14
|
+
poolInfo: StellarPoolInfo
|
|
15
|
+
poolState: StellarPoolState
|
|
16
|
+
handleAction: (options?: CloseModalOptions) => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function Success({
|
|
20
|
+
poolInfo,
|
|
21
|
+
poolState,
|
|
22
|
+
handleAction,
|
|
23
|
+
}: Props): React.ReactElement {
|
|
24
|
+
const { supplyAmount, txHash } = useAppSelector(selectWidgetState)
|
|
25
|
+
const { symbol } = poolInfo.underlyingToken
|
|
26
|
+
const dueDate = timeUtil.timestampToLL(poolState.epochEndTime)
|
|
27
|
+
|
|
28
|
+
const content = [
|
|
29
|
+
`${formatNumber(supplyAmount)} ${symbol} is now in your wallet.`,
|
|
30
|
+
`Note: your payment will be automatically deducted on ${dueDate}.`,
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
const handleUserAction = useCallback(() => {
|
|
34
|
+
handleAction({ isSuccess: true })
|
|
35
|
+
}, [handleAction])
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<StellarTxDoneModal
|
|
39
|
+
chainId={poolInfo.chainId}
|
|
40
|
+
handleAction={handleUserAction}
|
|
41
|
+
content={content}
|
|
42
|
+
txHash={txHash}
|
|
43
|
+
buttonText='DONE'
|
|
44
|
+
/>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { CloseModalOptions, StellarPoolInfo } from '@huma-finance/shared'
|
|
2
|
+
import {
|
|
3
|
+
StellarConnectionContext,
|
|
4
|
+
StellarPoolState,
|
|
5
|
+
useStellarBorrower,
|
|
6
|
+
} from '@huma-finance/web-shared'
|
|
7
|
+
import React, { useContext, useEffect } from 'react'
|
|
8
|
+
import { useDispatch } from 'react-redux'
|
|
9
|
+
|
|
10
|
+
import { useAppSelector } from '../../../hooks/useRedux'
|
|
11
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
12
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
13
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
14
|
+
import { ErrorModal } from '../../ErrorModal'
|
|
15
|
+
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
16
|
+
import { ChooseAmount } from './1-ChooseAmount'
|
|
17
|
+
import { ApproveAllowance } from './2-ApproveAllowance'
|
|
18
|
+
import { Transfer } from './3-Transfer'
|
|
19
|
+
import { Success } from './4-Success'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Stellar pool borrow widget props
|
|
23
|
+
* @typedef {Object} StellarBorrowProps
|
|
24
|
+
* @property {StellarPoolInfo} poolInfo The metadata of the pool.
|
|
25
|
+
* @property {StellarPoolState} poolState The current state config of the pool.
|
|
26
|
+
* @property {function((CloseModalOptions|undefined)):void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
27
|
+
* @property {function():void|undefined} handleSuccess Optional function to notify that the lending pool supply action is successful.
|
|
28
|
+
*/
|
|
29
|
+
export interface StellarBorrowProps {
|
|
30
|
+
poolInfo: StellarPoolInfo
|
|
31
|
+
poolState: StellarPoolState
|
|
32
|
+
handleClose: (options?: CloseModalOptions) => void
|
|
33
|
+
handleSuccess?: () => void
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function StellarBorrow({
|
|
37
|
+
poolInfo,
|
|
38
|
+
poolState,
|
|
39
|
+
handleClose,
|
|
40
|
+
handleSuccess,
|
|
41
|
+
}: StellarBorrowProps): React.ReactElement | null {
|
|
42
|
+
const title = 'Borrow'
|
|
43
|
+
const dispatch = useDispatch()
|
|
44
|
+
const { address: stellarAddress } = useContext(StellarConnectionContext)
|
|
45
|
+
const { creditAvailable, isLoadingStellarBorrower } = useStellarBorrower(
|
|
46
|
+
stellarAddress,
|
|
47
|
+
poolInfo,
|
|
48
|
+
)
|
|
49
|
+
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!step && !isLoadingStellarBorrower) {
|
|
53
|
+
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
54
|
+
}
|
|
55
|
+
}, [dispatch, handleClose, poolInfo, step, isLoadingStellarBorrower])
|
|
56
|
+
|
|
57
|
+
if (isLoadingStellarBorrower) {
|
|
58
|
+
return (
|
|
59
|
+
<WidgetWrapper
|
|
60
|
+
isOpen
|
|
61
|
+
isLoading
|
|
62
|
+
loadingTitle={title}
|
|
63
|
+
handleClose={handleClose}
|
|
64
|
+
handleSuccess={handleSuccess}
|
|
65
|
+
/>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<WidgetWrapper
|
|
71
|
+
isOpen
|
|
72
|
+
loadingTitle={title}
|
|
73
|
+
handleClose={handleClose}
|
|
74
|
+
handleSuccess={handleSuccess}
|
|
75
|
+
>
|
|
76
|
+
{step === WIDGET_STEP.ChooseAmount && (
|
|
77
|
+
<ChooseAmount poolInfo={poolInfo} creditAvailable={creditAvailable} />
|
|
78
|
+
)}
|
|
79
|
+
{step === WIDGET_STEP.ApproveAllowance && (
|
|
80
|
+
<ApproveAllowance poolInfo={poolInfo} />
|
|
81
|
+
)}
|
|
82
|
+
{step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
|
|
83
|
+
{step === WIDGET_STEP.Done && (
|
|
84
|
+
<Success
|
|
85
|
+
poolInfo={poolInfo}
|
|
86
|
+
poolState={poolState}
|
|
87
|
+
handleAction={handleClose}
|
|
88
|
+
/>
|
|
89
|
+
)}
|
|
90
|
+
{step === WIDGET_STEP.Error && (
|
|
91
|
+
<ErrorModal
|
|
92
|
+
title={title}
|
|
93
|
+
errorReason='Sorry there was an error'
|
|
94
|
+
errorMessage={errorMessage}
|
|
95
|
+
handleOk={handleClose}
|
|
96
|
+
/>
|
|
97
|
+
)}
|
|
98
|
+
</WidgetWrapper>
|
|
99
|
+
)
|
|
100
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -101,6 +101,10 @@ import { SuperfluidFactoring } from './components/SuperfluidFactoring'
|
|
|
101
101
|
import { store } from './store'
|
|
102
102
|
import { themeHuma } from './theme'
|
|
103
103
|
import { WCProps } from './utilTypes'
|
|
104
|
+
import {
|
|
105
|
+
StellarBorrow,
|
|
106
|
+
StellarBorrowProps,
|
|
107
|
+
} from './components/CreditLine/stellarBorrow'
|
|
104
108
|
|
|
105
109
|
/**
|
|
106
110
|
* Mapping of your JSON-RPC connections indexed by chainId
|
|
@@ -709,6 +713,25 @@ export function StellarLendSupplyWidget(props: StellarLendSupplyWidgetProps) {
|
|
|
709
713
|
)
|
|
710
714
|
}
|
|
711
715
|
|
|
716
|
+
/**
|
|
717
|
+
* Borrow widget props for Stellar pools
|
|
718
|
+
* @typedef {Object} StellarLendSupplyWidgetProps
|
|
719
|
+
*/
|
|
720
|
+
type StellarBorrowWidgetProps = StellarBorrowProps & GenericWidgetProps
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Borrow widget for Stellar pools
|
|
724
|
+
*
|
|
725
|
+
* @param {StellarBorrowWidgetProps} props - Widget props
|
|
726
|
+
*/
|
|
727
|
+
export function StellarBorrowWidget(props: StellarBorrowWidgetProps) {
|
|
728
|
+
return (
|
|
729
|
+
<GenericWidget {...props}>
|
|
730
|
+
<StellarBorrow {...props} />
|
|
731
|
+
</GenericWidget>
|
|
732
|
+
)
|
|
733
|
+
}
|
|
734
|
+
|
|
712
735
|
/**
|
|
713
736
|
* Lend pool supply widget props for Solana pools
|
|
714
737
|
* @typedef {Object} SolanaEnableAutoRedemptionWidgetProps
|