@huma-finance/widgets 0.0.62-beta.622 → 0.0.62-beta.627
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 +34 -26
- package/dist/cjs/index.cjs +430 -155
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +25 -9
- package/dist/index.js +433 -159
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +1 -0
- package/src/components/CreditLine/solanaBorrow/1-ChooseAmount.tsx +2 -21
- package/src/components/CreditLine/solanaBorrow/2-Transfer.tsx +159 -0
- package/src/components/CreditLine/solanaBorrow/3-Done.tsx +38 -0
- package/src/components/CreditLine/solanaBorrow/index.tsx +19 -25
- package/src/components/CreditLine/solanaPayment/1-ChooseAmount.tsx +75 -0
- package/src/components/CreditLine/solanaPayment/2-Transfer.tsx +92 -0
- package/src/components/CreditLine/solanaPayment/3-Done.tsx +59 -0
- package/src/components/CreditLine/solanaPayment/index.tsx +83 -0
- package/src/components/InputAmountModal.tsx +1 -0
- package/src/index.tsx +23 -8
- package/src/components/CreditLine/solanaBorrow/2-ApproveAllowance.tsx +0 -89
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { SolanaPoolInfo } from '@huma-finance/shared'
|
|
2
|
+
import { useBorrowerAccounts } from '@huma-finance/web-shared'
|
|
3
|
+
import React, { useEffect } from 'react'
|
|
4
|
+
import { useDispatch } from 'react-redux'
|
|
5
|
+
|
|
6
|
+
import { useAppSelector } from '../../../hooks/useRedux'
|
|
7
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
8
|
+
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
9
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
10
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
11
|
+
import { ErrorModal } from '../../ErrorModal'
|
|
12
|
+
import { ChooseAmount } from './1-ChooseAmount'
|
|
13
|
+
import { Transfer } from './2-Transfer'
|
|
14
|
+
import { Done } from './3-Done'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Lend pool supply props
|
|
18
|
+
* @typedef {Object} SolanaPaymentProps
|
|
19
|
+
* @property {SolanaPoolInfo} poolInfo The metadata of the pool.
|
|
20
|
+
* @property {function():void|undefined} handleSuccess Optional function to notify that the lending pool supply action is successful.
|
|
21
|
+
*/
|
|
22
|
+
export interface SolanaPaymentProps {
|
|
23
|
+
poolInfo: SolanaPoolInfo
|
|
24
|
+
handleClose: () => void
|
|
25
|
+
handleSuccess?: () => void
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function SolanaPayment({
|
|
29
|
+
poolInfo,
|
|
30
|
+
handleClose,
|
|
31
|
+
handleSuccess,
|
|
32
|
+
}: SolanaPaymentProps): React.ReactElement | null {
|
|
33
|
+
const dispatch = useDispatch()
|
|
34
|
+
const { creditStateAccount, loading: isLoadingBorrowerAccounts } =
|
|
35
|
+
useBorrowerAccounts(poolInfo.chainId, poolInfo.poolName)
|
|
36
|
+
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!step) {
|
|
39
|
+
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
40
|
+
}
|
|
41
|
+
}, [dispatch, step])
|
|
42
|
+
|
|
43
|
+
const title = 'Make Payment'
|
|
44
|
+
if (isLoadingBorrowerAccounts) {
|
|
45
|
+
return (
|
|
46
|
+
<WidgetWrapper
|
|
47
|
+
isOpen
|
|
48
|
+
isLoading
|
|
49
|
+
loadingTitle={title}
|
|
50
|
+
handleClose={handleClose}
|
|
51
|
+
handleSuccess={handleSuccess}
|
|
52
|
+
/>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<WidgetWrapper
|
|
58
|
+
isOpen
|
|
59
|
+
loadingTitle={title}
|
|
60
|
+
handleClose={handleClose}
|
|
61
|
+
handleSuccess={handleSuccess}
|
|
62
|
+
>
|
|
63
|
+
{step === WIDGET_STEP.ChooseAmount && creditStateAccount && (
|
|
64
|
+
<ChooseAmount
|
|
65
|
+
poolInfo={poolInfo}
|
|
66
|
+
creditStateAccount={creditStateAccount}
|
|
67
|
+
/>
|
|
68
|
+
)}
|
|
69
|
+
{step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
|
|
70
|
+
{step === WIDGET_STEP.Done && (
|
|
71
|
+
<Done poolInfo={poolInfo} handleAction={handleClose} />
|
|
72
|
+
)}
|
|
73
|
+
{step === WIDGET_STEP.Error && (
|
|
74
|
+
<ErrorModal
|
|
75
|
+
title={title}
|
|
76
|
+
errorReason='Sorry there was an error'
|
|
77
|
+
errorMessage={errorMessage}
|
|
78
|
+
handleOk={handleClose}
|
|
79
|
+
/>
|
|
80
|
+
)}
|
|
81
|
+
</WidgetWrapper>
|
|
82
|
+
)
|
|
83
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -89,6 +89,10 @@ import {
|
|
|
89
89
|
SolanaBorrow,
|
|
90
90
|
SolanaBorrowProps,
|
|
91
91
|
} from './components/CreditLine/solanaBorrow'
|
|
92
|
+
import {
|
|
93
|
+
SolanaPayment,
|
|
94
|
+
SolanaPaymentProps,
|
|
95
|
+
} from './components/CreditLine/solanaPayment'
|
|
92
96
|
|
|
93
97
|
/**
|
|
94
98
|
* Mapping of your JSON-RPC connections indexed by chainId
|
|
@@ -566,8 +570,6 @@ function SolanaWidget(props: WCProps<SolanaWidgetProps>) {
|
|
|
566
570
|
/**
|
|
567
571
|
* Lend pool supply widget props for Solana pools
|
|
568
572
|
* @typedef {Object} SolanaLendSupplyWidgetProps
|
|
569
|
-
* @property {SolanaLendSupplyProps} SolanaLendSupplyProps - Specific widget props
|
|
570
|
-
* @property {SolanaWidgetProps} SolanaWidgetProps - Widget general props.
|
|
571
573
|
*/
|
|
572
574
|
type SolanaLendSupplyWidgetProps = SolanaLendSupplyProps & SolanaWidgetProps
|
|
573
575
|
|
|
@@ -587,8 +589,6 @@ export function SolanaLendSupplyWidget(props: SolanaLendSupplyWidgetProps) {
|
|
|
587
589
|
/**
|
|
588
590
|
* Lend pool supply widget props for Solana pools
|
|
589
591
|
* @typedef {Object} SolanaLendAddRedemptionWidgetProps
|
|
590
|
-
* @property {SolanaLendSupplyProps} SolanaLendSupplyProps - Specific widget props
|
|
591
|
-
* @property {SolanaWidgetProps} SolanaWidgetProps - Widget general props.
|
|
592
592
|
*/
|
|
593
593
|
type SolanaLendAddRedemptionWidgetProps = SolanaLendAddRedemptionProps &
|
|
594
594
|
SolanaWidgetProps
|
|
@@ -611,8 +611,6 @@ export function SolanaLendAddRedemptionWidget(
|
|
|
611
611
|
/**
|
|
612
612
|
* Lend pool supply widget props for Solana pools
|
|
613
613
|
* @typedef {Object} SolanaLendCancelRedemptionWidgetProps
|
|
614
|
-
* @property {SolanaLendSupplyProps} SolanaLendSupplyProps - Specific widget props
|
|
615
|
-
* @property {SolanaWidgetProps} SolanaWidgetProps - Widget general props.
|
|
616
614
|
*/
|
|
617
615
|
type SolanaLendCancelRedemptionWidgetProps = SolanaLendCancelRedemptionProps &
|
|
618
616
|
SolanaWidgetProps
|
|
@@ -635,8 +633,6 @@ export function SolanaLendCancelRedemptionWidget(
|
|
|
635
633
|
/**
|
|
636
634
|
* Lend pool supply widget props for Solana pools
|
|
637
635
|
* @typedef {Object} SolanaBorrowWidgetProps
|
|
638
|
-
* @property {SolanaLendSupplyProps} SolanaLendSupplyProps - Specific widget props
|
|
639
|
-
* @property {SolanaWidgetProps} SolanaWidgetProps - Widget general props.
|
|
640
636
|
*/
|
|
641
637
|
type SolanaBorrowWidgetProps = SolanaBorrowProps & SolanaWidgetProps
|
|
642
638
|
|
|
@@ -652,3 +648,22 @@ export function SolanaBorrowWidget(props: SolanaBorrowWidgetProps) {
|
|
|
652
648
|
</SolanaWidget>
|
|
653
649
|
)
|
|
654
650
|
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Lend pool supply widget props for Solana pools
|
|
654
|
+
* @typedef {Object} SolanaPaymentWidgetProps
|
|
655
|
+
*/
|
|
656
|
+
type SolanaPaymentWidgetProps = SolanaPaymentProps & SolanaWidgetProps
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Lend pool supply widget for Solana pools
|
|
660
|
+
*
|
|
661
|
+
* @param {SolanaPaymentWidgetProps} props - Widget props
|
|
662
|
+
*/
|
|
663
|
+
export function SolanaPaymentWidget(props: SolanaPaymentWidgetProps) {
|
|
664
|
+
return (
|
|
665
|
+
<SolanaWidget {...props}>
|
|
666
|
+
<SolanaPayment {...props} />
|
|
667
|
+
</SolanaWidget>
|
|
668
|
+
)
|
|
669
|
+
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getSentinelAddress,
|
|
3
|
-
SolanaPoolInfo,
|
|
4
|
-
SolanaTokenUtils,
|
|
5
|
-
} from '@huma-finance/shared'
|
|
6
|
-
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
Account,
|
|
10
|
-
createApproveCheckedInstruction,
|
|
11
|
-
TOKEN_2022_PROGRAM_ID,
|
|
12
|
-
} from '@solana/spl-token'
|
|
13
|
-
import { useConnection, useWallet } from '@solana/wallet-adapter-react'
|
|
14
|
-
import { PublicKey, Transaction } from '@solana/web3.js'
|
|
15
|
-
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
16
|
-
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
17
|
-
import { setStep } from '../../../store/widgets.reducers'
|
|
18
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
19
|
-
|
|
20
|
-
type Props = {
|
|
21
|
-
poolInfo: SolanaPoolInfo
|
|
22
|
-
tokenAccount: Account
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function ApproveAllowance({
|
|
26
|
-
poolInfo,
|
|
27
|
-
tokenAccount,
|
|
28
|
-
}: Props): React.ReactElement | null {
|
|
29
|
-
const dispatch = useAppDispatch()
|
|
30
|
-
const { wallet, publicKey, sendTransaction, signTransaction } = useWallet()
|
|
31
|
-
const sentinel = useMemo(
|
|
32
|
-
() => getSentinelAddress(poolInfo.chainId),
|
|
33
|
-
[poolInfo.chainId],
|
|
34
|
-
)
|
|
35
|
-
const { connection } = useConnection()
|
|
36
|
-
const [transaction, setTransaction] = useState<Transaction>()
|
|
37
|
-
|
|
38
|
-
const handleSuccess = useCallback(() => {
|
|
39
|
-
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
40
|
-
}, [dispatch])
|
|
41
|
-
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
async function getTx() {
|
|
44
|
-
if (!wallet || !publicKey || !connection || !signTransaction) {
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const tx = new Transaction().add(
|
|
49
|
-
createApproveCheckedInstruction(
|
|
50
|
-
tokenAccount.address,
|
|
51
|
-
new PublicKey(poolInfo.underlyingMint.address),
|
|
52
|
-
new PublicKey(sentinel), // delegate
|
|
53
|
-
publicKey, // owner of the wallet
|
|
54
|
-
BigInt(
|
|
55
|
-
SolanaTokenUtils.parseUnits(
|
|
56
|
-
'100000000000', // 100 billion
|
|
57
|
-
poolInfo.underlyingMint.decimals,
|
|
58
|
-
).toString(),
|
|
59
|
-
), // amount
|
|
60
|
-
poolInfo.underlyingMint.decimals,
|
|
61
|
-
undefined, // multiSigners
|
|
62
|
-
TOKEN_2022_PROGRAM_ID,
|
|
63
|
-
),
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
setTransaction(tx)
|
|
67
|
-
}
|
|
68
|
-
getTx()
|
|
69
|
-
}, [
|
|
70
|
-
connection,
|
|
71
|
-
dispatch,
|
|
72
|
-
poolInfo.underlyingMint.address,
|
|
73
|
-
poolInfo.underlyingMint.decimals,
|
|
74
|
-
publicKey,
|
|
75
|
-
sendTransaction,
|
|
76
|
-
sentinel,
|
|
77
|
-
signTransaction,
|
|
78
|
-
tokenAccount.address,
|
|
79
|
-
wallet,
|
|
80
|
-
])
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<SolanaTxSendModal
|
|
84
|
-
tx={transaction}
|
|
85
|
-
chainId={poolInfo.chainId}
|
|
86
|
-
handleSuccess={handleSuccess}
|
|
87
|
-
/>
|
|
88
|
-
)
|
|
89
|
-
}
|