-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: redesign send rpc transfer flow
- Loading branch information
1 parent
c525f91
commit 699bf7d
Showing
42 changed files
with
1,740 additions
and
800 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,78 @@ | ||
import { useEffect, useMemo, useState } from 'react'; | ||
|
||
import type { MarketData } from '@leather.io/models'; | ||
|
||
import type { FeesRawData, RawFee } from '@app/components/bitcoin-fees-list/bitcoin-fees.utils'; | ||
|
||
export type FeeType = 'slow' | 'standard' | 'fast' | 'custom'; | ||
|
||
export interface FeeDisplayInfo { | ||
feeType: FeeType; | ||
baseUnitsValue: number; | ||
feeRate: number; | ||
titleLeft: string; | ||
captionLeft: string; | ||
titleRight?: string; | ||
captionRight?: string; | ||
} | ||
|
||
export interface FormatFeeForDisplayArgs { | ||
rawFee: RawFee; | ||
marketData: MarketData; | ||
} | ||
|
||
interface UseFeesProps { | ||
defaultFeeType?: FeeType; | ||
fees: FeesRawData; | ||
getCustomFeeData(rate: number): RawFee; | ||
marketData: MarketData; | ||
formatFeeForDisplay({ rawFee, marketData }: FormatFeeForDisplayArgs): FeeDisplayInfo; | ||
} | ||
|
||
export function useFeesHandler({ | ||
defaultFeeType = 'standard', | ||
fees, | ||
getCustomFeeData, | ||
marketData, | ||
formatFeeForDisplay, | ||
}: UseFeesProps) { | ||
const [selectedFeeType, setSelectedFeeType] = useState<FeeType>(defaultFeeType); | ||
const [editFeeSelected, setEditFeeSelected] = useState<FeeType>(selectedFeeType); | ||
const [customFeeRate, setCustomFeeRate] = useState<string>(''); | ||
|
||
const customFeeData = getCustomFeeData(Number(customFeeRate)); | ||
|
||
const selectedFeeData = useMemo(() => { | ||
if (selectedFeeType === 'custom') { | ||
return formatFeeForDisplay({ rawFee: customFeeData, marketData }); | ||
} | ||
|
||
const rawFee = fees[selectedFeeType]; | ||
|
||
if (!rawFee) { | ||
return {}; | ||
} | ||
|
||
return formatFeeForDisplay({ rawFee, marketData }); | ||
}, [fees, selectedFeeType, customFeeData, marketData, formatFeeForDisplay]); | ||
|
||
useEffect(() => { | ||
if (customFeeRate === '' && selectedFeeType !== 'custom') { | ||
const data = fees[selectedFeeType]; | ||
if (data && data.feeRate) { | ||
setCustomFeeRate(data.feeRate.toString()); | ||
} | ||
} | ||
}, [fees, selectedFeeType, customFeeRate]); | ||
|
||
return { | ||
selectedFeeType, | ||
setSelectedFeeType, | ||
selectedFeeData, | ||
editFeeSelected, | ||
setEditFeeSelected, | ||
customFeeRate, | ||
setCustomFeeRate, | ||
customFeeData, | ||
}; | ||
} |
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
Oops, something went wrong.