Merge branch 'master' into Carousel-on-the-main-screen-does-not-working-from-the-first-go

This commit is contained in:
Marcos Rodriguez Velez 2025-02-19 08:55:55 -04:00
commit 66bb0b0e1c
5 changed files with 84 additions and 42 deletions

View file

@ -7,18 +7,24 @@ import { GROUP_IO_BLUEWALLET } from '../blue_modules/currency';
import { BlueApp } from '../class';
import { HandOffComponentProps } from './types';
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;
};
const HandOffComponent: React.FC<HandOffComponentProps> = React.memo(
props => {
const { isHandOffUseEnabled } = useSettings();
const MemoizedHandOffComponent = React.memo(HandOffComponent);
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
);
},
);
export const setIsHandOffUseEnabled = async (value: boolean) => {
try {
@ -44,4 +50,4 @@ export const getIsHandOffUseEnabled = async (): Promise<boolean> => {
}
};
export default MemoizedHandOffComponent;
export default HandOffComponent;

View file

@ -324,11 +324,7 @@ const DetailViewStackScreensStack = () => {
component={SettingsPrivacy}
options={navigationStyle({ title: loc.settings.privacy })(theme)}
/>
<DetailViewStack.Screen
name="AddWalletRoot"
component={AddWalletStack}
options={navigationStyle({ closeButtonPosition: CloseButtonPosition.Left, ...NavigationDefaultOptions })(theme)}
/>
<DetailViewStack.Screen name="AddWalletRoot" component={AddWalletStack} options={NavigationDefaultOptions} />
<DetailViewStack.Screen name="SendDetailsRoot" component={SendDetailsStack} options={NavigationDefaultOptions} />
<DetailViewStack.Screen name="LNDCreateInvoiceRoot" component={LNDCreateInvoiceRoot} options={NavigationDefaultOptions} />
<DetailViewStack.Screen name="ScanLndInvoiceRoot" component={ScanLndInvoiceRoot} options={NavigationDefaultOptions} />

3
package-lock.json generated
View file

@ -26,7 +26,6 @@
"@react-native-menu/menu": "https://github.com/BlueWallet/menu.git#14bab79",
"@react-native/gradle-plugin": "0.76.7",
"@react-native/metro-config": "0.76.7",
"@react-navigation/devtools": "7.0.15",
"@react-navigation/drawer": "7.1.1",
"@react-navigation/native": "7.0.14",
"@react-navigation/native-stack": "7.2.0",
@ -121,6 +120,7 @@
"@react-native/js-polyfills": "^0.76.7",
"@react-native/metro-babel-transformer": "^0.76.7",
"@react-native/typescript-config": "0.76.7",
"@react-navigation/devtools": "7.0.15",
"@testing-library/react-native": "^13.0.1",
"@types/bip38": "^3.1.2",
"@types/bs58check": "^2.1.0",
@ -6280,6 +6280,7 @@
"version": "7.0.15",
"resolved": "https://registry.npmjs.org/@react-navigation/devtools/-/devtools-7.0.15.tgz",
"integrity": "sha512-pxEBVtd6e5ocT7bs6k6ghOJNyb9Fzxm+EYHemHQ53GEin1sQKYpsSHWZEJdFj1cxYp+/+KCT+TueuNDFkJOr4Q==",
"dev": true,
"license": "MIT",
"dependencies": {
"fast-deep-equal": "^3.1.3",

View file

@ -14,6 +14,7 @@
"@react-native/babel-preset": "0.76.7",
"@react-native/eslint-config": "^0.76.7",
"@react-native/js-polyfills": "^0.76.7",
"@react-navigation/devtools": "7.0.15",
"@react-native/metro-babel-transformer": "^0.76.7",
"@react-native/typescript-config": "0.76.7",
"@testing-library/react-native": "^13.0.1",
@ -94,7 +95,6 @@
"@react-native-menu/menu": "https://github.com/BlueWallet/menu.git#14bab79",
"@react-native/gradle-plugin": "0.76.7",
"@react-native/metro-config": "0.76.7",
"@react-navigation/devtools": "7.0.15",
"@react-navigation/drawer": "7.1.1",
"@react-navigation/native": "7.0.14",
"@react-navigation/native-stack": "7.2.0",

View file

@ -42,6 +42,37 @@ 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,25 +490,37 @@ const ReceiveDetails = () => {
}
};
const renderTabContent = () => {
const qrValue = currentTab === segmentControlValues[0] ? bip21encoded : wallet.getBIP47PaymentCode();
const [isLoading, setIsLoading] = useState(false);
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 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 />;
}
return (
<TabContent
currentTab={currentTab}
bip21encoded={bip21encoded}
wallet={wallet}
address={address}
showAddress={showAddress}
isCustom={isCustom}
handleShareButtonPressed={handleShareButtonPressed}
renderReceiveDetails={renderReceiveDetails}
/>
);
};
return (
@ -492,16 +535,12 @@ const ReceiveDetails = () => {
<SegmentedControl
values={segmentControlValues}
selectedIndex={segmentControlValues.findIndex(tab => tab === currentTab)}
onChange={index => {
setCurrentTab(segmentControlValues[index]);
}}
onChange={handleTabChange}
/>
</View>
)}
{showAddress && renderTabContent()}
{address !== undefined && showAddress && (
<HandOffComponent title={loc.send.details_address} type={HandOffActivityType.ReceiveOnchain} userInfo={{ address }} />
)}
{address !== undefined && showAddress && <MemoizedHandoffComponent address={address} />}
{showConfirmedBalance ? renderConfirmedBalance() : null}
{showPendingBalance ? renderPendingBalance() : null}
{!showAddress && !showPendingBalance && !showConfirmedBalance ? <BlueLoading /> : null}