diff --git a/android/app/src/main/java/io/bluewallet/bluewallet/CustomSegmentedControlManager.java b/android/app/src/main/java/io/bluewallet/bluewallet/CustomSegmentedControlManager.java index ad70cd656..fb65339c1 100644 --- a/android/app/src/main/java/io/bluewallet/bluewallet/CustomSegmentedControlManager.java +++ b/android/app/src/main/java/io/bluewallet/bluewallet/CustomSegmentedControlManager.java @@ -11,10 +11,12 @@ import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.WritableMap; import com.facebook.react.uimanager.events.RCTEventEmitter; +import android.util.Log; public class CustomSegmentedControlManager extends SimpleViewManager { public static final String REACT_CLASS = "CustomSegmentedControl"; private static boolean isRegistered = false; + private static final String TAG = "CustomSegmentedControlManager"; public static class CustomSegmentedControlView extends LinearLayout { private TabLayout tabLayout; @@ -46,18 +48,26 @@ public class CustomSegmentedControlManager extends SimpleViewManager= 0 && selectedIndex < tabLayout.getTabCount()) { - TabLayout.Tab tab = tabLayout.getTabAt(selectedIndex); - if (tab != null) { - tab.select(); + try { + if (selectedIndex >= 0 && selectedIndex < tabLayout.getTabCount()) { + TabLayout.Tab tab = tabLayout.getTabAt(selectedIndex); + if (tab != null) { + tab.select(); + } } + } catch (Exception e) { + Log.e(TAG, "Error setting property 'selectedIndex': " + e.getMessage()); } } diff --git a/ios/Components/SegmentedControl/CustomSegmentedControlManager.m b/ios/Components/SegmentedControl/CustomSegmentedControlManager.m index 31c6ce256..f8a9b10f7 100644 --- a/ios/Components/SegmentedControl/CustomSegmentedControlManager.m +++ b/ios/Components/SegmentedControl/CustomSegmentedControlManager.m @@ -20,14 +20,22 @@ } - (void)setValues:(NSArray *)values { - [self removeAllSegments]; - for (NSUInteger i = 0; i < values.count; i++) { - [self insertSegmentWithTitle:values[i] atIndex:i animated:NO]; + @try { + [self removeAllSegments]; + for (NSUInteger i = 0; i < values.count; i++) { + [self insertSegmentWithTitle:values[i] atIndex:i animated:NO]; + } + } @catch (NSException *exception) { + NSLog(@"Error setting property 'values': %@", exception.reason); } } - (void)setSelectedIndex:(NSNumber *)selectedIndex { - self.selectedSegmentIndex = selectedIndex.integerValue; + @try { + self.selectedSegmentIndex = selectedIndex.integerValue; + } @catch (NSException *exception) { + NSLog(@"Error setting property 'selectedIndex': %@", exception.reason); + } } - (void)onChange:(UISegmentedControl *)sender { diff --git a/screen/receive/details.js b/screen/receive/details.js index 7186878bd..9898e02e8 100644 --- a/screen/receive/details.js +++ b/screen/receive/details.js @@ -33,8 +33,10 @@ import loc, { formatBalance } from '../../loc'; import { BitcoinUnit, Chain } from '../../models/bitcoinUnits'; import { SuccessView } from '../send/success'; import { useStorage } from '../../hooks/context/useStorage'; -import { AddressTypeTabs, TABS } from '../../components/addresses/AddressTypeTabs'; import { HandOffActivityType } from '../../components/types'; +import SegmentedControl from '../../components/SegmentControl'; + +const segmentControlValues = [loc.wallets.details_address, loc.bip47.payment_code]; const ReceiveDetails = () => { const { walletID, address } = useRoute().params; @@ -49,7 +51,7 @@ const ReceiveDetails = () => { const [showPendingBalance, setShowPendingBalance] = useState(false); const [showConfirmedBalance, setShowConfirmedBalance] = useState(false); const [showAddress, setShowAddress] = useState(false); - const [currentTab, setCurrentTab] = useState(TABS.EXTERNAL); + const [currentTab, setCurrentTab] = useState(segmentControlValues[0]); const { goBack, setParams } = useExtendedNavigation(); const { colors } = useTheme(); const [intervalMs, setIntervalMs] = useState(5000); @@ -431,9 +433,9 @@ const ReceiveDetails = () => { }; const renderTabContent = () => { - const qrValue = currentTab === TABS.EXTERNAL ? bip21encoded : wallet.getBIP47PaymentCode(); + const qrValue = currentTab === segmentControlValues[0] ? bip21encoded : wallet.getBIP47PaymentCode(); - if (currentTab === TABS.EXTERNAL) { + if (currentTab === segmentControlValues[0]) { return {address && renderReceiveDetails()}; } else { return ( @@ -457,14 +459,17 @@ const ReceiveDetails = () => { {wallet.isBIP47Enabled() && ( - tab)} + selectedIndex={Object.values(segmentControlValues).findIndex(tab => tab === currentTab)} + onChange={index => { + const tabKey = Object.keys(segmentControlValues)[index]; + setCurrentTab(segmentControlValues[tabKey]); + }} /> )} - {renderTabContent()} + {showAddress && renderTabContent()}