Revert "FIX: unblock UI as user switches address type"

This reverts commit a1d5941a75.
This commit is contained in:
Marcos Rodriguez Velez 2025-02-18 21:25:03 -04:00
parent 82f13fbded
commit e4cea4f451
2 changed files with 35 additions and 80 deletions

View file

@ -7,24 +7,18 @@ import { GROUP_IO_BLUEWALLET } from '../blue_modules/currency';
import { BlueApp } from '../class';
import { HandOffComponentProps } from './types';
const HandOffComponent: React.FC<HandOffComponentProps> = React.memo(
props => {
const { isHandOffUseEnabled } = useSettings();
const HandOffComponent: React.FC<HandOffComponentProps> = props => {
const { isHandOffUseEnabled } = useSettings();
if (!props || !props.type || !props.userInfo || Object.keys(props.userInfo).length === 0) {
console.debug('HandOffComponent: Missing required type or userInfo data');
return null;
}
const userInfo = JSON.stringify(props.userInfo);
console.debug(`HandOffComponent is rendering. Type: ${props.type}, UserInfo: ${userInfo}...`);
return isHandOffUseEnabled ? <Handoff {...props} /> : null;
};
if (!props || !props.type || !props.userInfo || Object.keys(props.userInfo).length === 0) {
return null;
}
return isHandOffUseEnabled ? <Handoff {...props} /> : null;
},
(prevProps, nextProps) => {
return (
prevProps.type === nextProps.type &&
JSON.stringify(prevProps.userInfo) === JSON.stringify(nextProps.userInfo) &&
prevProps.title === nextProps.title
);
},
);
const MemoizedHandOffComponent = React.memo(HandOffComponent);
export const setIsHandOffUseEnabled = async (value: boolean) => {
try {
@ -50,4 +44,4 @@ export const getIsHandOffUseEnabled = async (): Promise<boolean> => {
}
};
export default HandOffComponent;
export default MemoizedHandOffComponent;

View file

@ -31,37 +31,6 @@ import TipBox from '../../components/TipBox';
const segmentControlValues = [loc.wallets.details_address, loc.bip47.payment_code];
const TabContent = React.memo(
({ currentTab, bip21encoded, wallet, address, showAddress, isCustom, handleShareButtonPressed, renderReceiveDetails }) => {
const qrValue = useMemo(
() => (currentTab === segmentControlValues[0] ? bip21encoded : wallet?.getBIP47PaymentCode()),
[currentTab, bip21encoded, wallet],
);
if (currentTab === segmentControlValues[0]) {
return <View style={styles.container}>{address && renderReceiveDetails()}</View>;
} else {
return (
<View style={styles.container}>
{!qrValue && <Text>{loc.bip47.not_found}</Text>}
{qrValue && (
<>
<TipBox description={loc.receive.bip47_explanation} containerStyle={styles.tip} />
<QRCodeComponent value={qrValue} />
<CopyTextToClipboard text={qrValue} truncated={false} />
</>
)}
</View>
);
}
},
);
const MemoizedHandoffComponent = React.memo(
({ address }) => <HandOffComponent title={loc.send.details_address} type={HandOffActivityType.ReceiveOnchain} userInfo={{ address }} />,
(prevProps, nextProps) => prevProps.address === nextProps.address,
);
const ReceiveDetails = () => {
const { walletID, address } = useRoute().params;
const { wallets, saveToDisk, sleep, fetchAndSaveWalletTransactions } = useStorage();
@ -459,37 +428,25 @@ const ReceiveDetails = () => {
}
};
const [isLoading, setIsLoading] = useState(false);
const handleTabChange = useCallback(index => {
setIsLoading(true);
// Use requestAnimationFrame to prevent UI blocking (better than InteractionManager)
requestAnimationFrame(() => {
setCurrentTab(segmentControlValues[index]);
// Add a small delay to allow the UI to update (sadly needed hack)
setTimeout(() => {
setIsLoading(false);
}, 100);
});
}, []);
const renderTabContent = () => {
if (isLoading) {
return <BlueLoading />;
}
const qrValue = currentTab === segmentControlValues[0] ? bip21encoded : wallet.getBIP47PaymentCode();
return (
<TabContent
currentTab={currentTab}
bip21encoded={bip21encoded}
wallet={wallet}
address={address}
showAddress={showAddress}
isCustom={isCustom}
handleShareButtonPressed={handleShareButtonPressed}
renderReceiveDetails={renderReceiveDetails}
/>
);
if (currentTab === segmentControlValues[0]) {
return <View style={styles.container}>{address && renderReceiveDetails()}</View>;
} else {
return (
<View style={styles.container}>
{!qrValue && <Text>{loc.bip47.not_found}</Text>}
{qrValue && (
<>
<TipBox description={loc.receive.bip47_explanation} containerStyle={styles.tip} />
<QRCodeComponent value={qrValue} />
<CopyTextToClipboard text={qrValue} truncated={false} />
</>
)}
</View>
);
}
};
return (
@ -504,12 +461,16 @@ const ReceiveDetails = () => {
<SegmentedControl
values={segmentControlValues}
selectedIndex={segmentControlValues.findIndex(tab => tab === currentTab)}
onChange={handleTabChange}
onChange={index => {
setCurrentTab(segmentControlValues[index]);
}}
/>
</View>
)}
{showAddress && renderTabContent()}
{address !== undefined && showAddress && <MemoizedHandoffComponent address={address} />}
{address !== undefined && showAddress && (
<HandOffComponent title={loc.send.details_address} type={HandOffActivityType.ReceiveOnchain} userInfo={{ address }} />
)}
{showConfirmedBalance ? renderConfirmedBalance() : null}
{showPendingBalance ? renderPendingBalance() : null}
{!showAddress && !showPendingBalance && !showConfirmedBalance ? <BlueLoading /> : null}