mirror of
https://github.com/zhigang1992/wallet.git
synced 2026-01-12 22:53:27 +08:00
refactor: inscription sends, closes #4111
This commit is contained in:
@@ -6,11 +6,14 @@ import get from 'lodash.get';
|
||||
import { AverageBitcoinFeeRates, BtcFeeType } from '@shared/models/fees/bitcoin-fees.model';
|
||||
import { SupportedInscription } from '@shared/models/inscription.model';
|
||||
|
||||
import { useOnMount } from '@app/common/hooks/use-on-mount';
|
||||
import { TaprootUtxo } from '@app/query/bitcoin/ordinals/use-taproot-address-utxos.query';
|
||||
|
||||
import { useSendInscriptionRouteState } from '../hooks/use-send-inscription-route-state';
|
||||
import { createUtxoFromInscription } from './create-utxo-from-inscription';
|
||||
import { SendInscriptionLoader } from './send-inscription-loader';
|
||||
|
||||
export interface SendInscriptionContextState {
|
||||
interface SendInscriptionContextState {
|
||||
feeRates: AverageBitcoinFeeRates;
|
||||
inscription: SupportedInscription;
|
||||
selectedFeeType: BtcFeeType;
|
||||
@@ -25,10 +28,22 @@ export function useSendInscriptionState() {
|
||||
|
||||
export function SendInscriptionContainer() {
|
||||
const [selectedFeeType, setSelectedFeeType] = useState<BtcFeeType | null>(null);
|
||||
const [inscription, setInscription] = useState<SupportedInscription | null>(null);
|
||||
const [utxo, setUtxo] = useState<TaprootUtxo | null>(null);
|
||||
|
||||
const routeState = useSendInscriptionRouteState();
|
||||
|
||||
useOnMount(() => {
|
||||
if (!routeState.inscription) return;
|
||||
setInscription(routeState.inscription);
|
||||
setUtxo(createUtxoFromInscription(routeState.inscription));
|
||||
});
|
||||
|
||||
if (!inscription || !utxo) return null;
|
||||
|
||||
return (
|
||||
<SendInscriptionLoader>
|
||||
{({ feeRates, inscription, utxo }) => (
|
||||
{({ feeRates }) => (
|
||||
<Outlet context={{ feeRates, inscription, selectedFeeType, setSelectedFeeType, utxo }} />
|
||||
)}
|
||||
</SendInscriptionLoader>
|
||||
|
||||
@@ -1,25 +1,12 @@
|
||||
import { Navigate } from 'react-router-dom';
|
||||
|
||||
import { RouteUrls } from '@shared/route-urls';
|
||||
import { AverageBitcoinFeeRates } from '@shared/models/fees/bitcoin-fees.model';
|
||||
|
||||
import { useAverageBitcoinFeeRates } from '@app/query/bitcoin/fees/fee-estimates.hooks';
|
||||
|
||||
import { useSendInscriptionRouteState } from '../hooks/use-send-inscription-route-state';
|
||||
import { createUtxoFromInscription } from './create-utxo-from-inscription';
|
||||
import { SendInscriptionContextState } from './send-inscription-container';
|
||||
|
||||
interface SendInscriptionLoaderProps {
|
||||
children(data: Partial<SendInscriptionContextState>): React.JSX.Element;
|
||||
children(data: { feeRates: AverageBitcoinFeeRates }): React.JSX.Element;
|
||||
}
|
||||
export function SendInscriptionLoader({ children }: SendInscriptionLoaderProps) {
|
||||
const { inscription } = useSendInscriptionRouteState();
|
||||
const { data: feeRates } = useAverageBitcoinFeeRates();
|
||||
|
||||
if (!feeRates) return null;
|
||||
|
||||
if (!inscription) return <Navigate to={RouteUrls.Home} />;
|
||||
|
||||
const utxo = createUtxoFromInscription(inscription);
|
||||
|
||||
return children({ inscription, feeRates, utxo });
|
||||
return children({ feeRates });
|
||||
}
|
||||
|
||||
@@ -4,12 +4,9 @@ import get from 'lodash.get';
|
||||
|
||||
import { SupportedInscription } from '@shared/models/inscription.model';
|
||||
|
||||
import { TaprootUtxo } from '@app/query/bitcoin/ordinals/use-taproot-address-utxos.query';
|
||||
|
||||
export function useSendInscriptionRouteState() {
|
||||
const location = useLocation();
|
||||
return {
|
||||
inscription: get(location.state, 'inscription', null) as SupportedInscription | null,
|
||||
utxo: get(location.state, 'utxo', null) as TaprootUtxo | null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user