mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 01:40:12 +01:00
wip
This commit is contained in:
parent
3a759c8f24
commit
1f595b0fd2
@ -35,8 +35,8 @@ interface StorageContextType {
|
||||
resetWallets: () => void;
|
||||
walletTransactionUpdateStatus: WalletTransactionsStatus | string;
|
||||
setWalletTransactionUpdateStatus: (status: WalletTransactionsStatus | string) => void;
|
||||
isElectrumDisabled: boolean;
|
||||
setIsElectrumDisabled: (value: boolean) => void;
|
||||
isElectrumEnabled: boolean;
|
||||
setIsElectrumEnabledStorage: (value: boolean) => void;
|
||||
reloadTransactionsMenuActionFunction: () => void;
|
||||
setReloadTransactionsMenuActionFunction: (func: () => void) => void;
|
||||
getTransactions: typeof BlueApp.getTransactions;
|
||||
@ -73,7 +73,7 @@ export const StorageProvider = ({ children }: { children: React.ReactNode }) =>
|
||||
WalletTransactionsStatus.NONE,
|
||||
);
|
||||
const [walletsInitialized, setWalletsInitialized] = useState<boolean>(false);
|
||||
const [isElectrumDisabled, setIsElectrumDisabled] = useState<boolean>(true);
|
||||
const [isElectrumEnabled, setIsElectrumEnabled] = useState<boolean>(true);
|
||||
const [currentSharedCosigner, setCurrentSharedCosigner] = useState<string>('');
|
||||
const [reloadTransactionsMenuActionFunction, setReloadTransactionsMenuActionFunction] = useState<() => void>(() => {});
|
||||
|
||||
@ -119,7 +119,7 @@ export const StorageProvider = ({ children }: { children: React.ReactNode }) =>
|
||||
|
||||
// Initialize wallets and connect to Electrum
|
||||
useEffect(() => {
|
||||
BlueElectrum.isDisabled().then(setIsElectrumDisabled);
|
||||
BlueElectrum.isDisabled().then(value => setIsElectrumEnabled(!value));
|
||||
if (walletsInitialized) {
|
||||
txMetadata.current = BlueApp.tx_metadata;
|
||||
counterpartyMetadata.current = BlueApp.counterparty_metadata;
|
||||
@ -243,6 +243,13 @@ export const StorageProvider = ({ children }: { children: React.ReactNode }) =>
|
||||
[wallets, addWallet, saveToDisk],
|
||||
);
|
||||
|
||||
const setIsElectrumEnabledStorage = useCallback(
|
||||
async (value: boolean) => {
|
||||
await BlueElectrum.setDisabled(!value);
|
||||
setIsElectrumEnabled(value);
|
||||
},
|
||||
[setIsElectrumEnabled],
|
||||
);
|
||||
const value: StorageContextType = useMemo(
|
||||
() => ({
|
||||
wallets,
|
||||
@ -278,8 +285,8 @@ export const StorageProvider = ({ children }: { children: React.ReactNode }) =>
|
||||
isPasswordInUse: BlueApp.isPasswordInUse,
|
||||
walletTransactionUpdateStatus,
|
||||
setWalletTransactionUpdateStatus,
|
||||
isElectrumDisabled,
|
||||
setIsElectrumDisabled,
|
||||
isElectrumEnabled,
|
||||
setIsElectrumEnabledStorage,
|
||||
reloadTransactionsMenuActionFunction,
|
||||
setReloadTransactionsMenuActionFunction,
|
||||
}),
|
||||
@ -300,8 +307,8 @@ export const StorageProvider = ({ children }: { children: React.ReactNode }) =>
|
||||
resetWallets,
|
||||
walletTransactionUpdateStatus,
|
||||
setWalletTransactionUpdateStatus,
|
||||
isElectrumDisabled,
|
||||
setIsElectrumDisabled,
|
||||
isElectrumEnabled,
|
||||
setIsElectrumEnabledStorage,
|
||||
reloadTransactionsMenuActionFunction,
|
||||
setReloadTransactionsMenuActionFunction,
|
||||
],
|
||||
|
@ -239,8 +239,8 @@
|
||||
"electrum_error_connect": "Cannot connect to the provided Electrum server",
|
||||
"lndhub_uri": "E.g., {example}",
|
||||
"electrum_host": "E.g., {example}",
|
||||
"electrum_offline_mode": "Offline Mode",
|
||||
"electrum_offline_description": "When enabled, your Bitcoin wallets will not attempt to fetch balances or transactions.",
|
||||
"electrum_offline_mode": "Enabled",
|
||||
"electrum_offline_description": "Bitcoin wallets will use the listed servers to fetch balances or transactions.",
|
||||
"electrum_port": "Port, usually {example}",
|
||||
"use_ssl": "Use SSL",
|
||||
"electrum_saved": "Your changes have been saved successfully. Restarting BlueWallet may be required for the changes to take effect.",
|
||||
|
@ -42,7 +42,7 @@ const segmentControlValues = [loc.wallets.details_address, loc.bip47.payment_cod
|
||||
|
||||
const ReceiveDetails = () => {
|
||||
const { walletID, address } = useRoute().params;
|
||||
const { wallets, saveToDisk, sleep, isElectrumDisabled, fetchAndSaveWalletTransactions } = useStorage();
|
||||
const { wallets, saveToDisk, sleep, isElectrumEnabled, fetchAndSaveWalletTransactions } = useStorage();
|
||||
const wallet = wallets.find(w => w.getID() === walletID);
|
||||
const [customLabel, setCustomLabel] = useState('');
|
||||
const [customAmount, setCustomAmount] = useState('');
|
||||
@ -116,7 +116,7 @@ const ReceiveDetails = () => {
|
||||
} else {
|
||||
if (wallet.chain === Chain.ONCHAIN) {
|
||||
try {
|
||||
if (!isElectrumDisabled) newAddress = await Promise.race([wallet.getAddressAsync(), sleep(1000)]);
|
||||
if (isElectrumEnabled) newAddress = await Promise.race([wallet.getAddressAsync(), sleep(1000)]);
|
||||
} catch (error) {
|
||||
console.warn('Error fetching wallet address (ONCHAIN):', error);
|
||||
}
|
||||
@ -148,7 +148,7 @@ const ReceiveDetails = () => {
|
||||
console.error('Error obtaining notifications permissions:', error);
|
||||
}
|
||||
}
|
||||
}, [wallet, saveToDisk, address, setAddressBIP21Encoded, isElectrumDisabled, sleep]);
|
||||
}, [wallet, saveToDisk, address, setAddressBIP21Encoded, isElectrumEnabled, sleep]);
|
||||
|
||||
const onEnablePaymentsCodeSwitchValue = useCallback(() => {
|
||||
if (wallet.allowBIP47()) {
|
||||
|
@ -66,7 +66,7 @@ type ConfirmRouteProp = RouteProp<SendDetailsStackParamList, 'Confirm'>;
|
||||
type ConfirmNavigationProp = NativeStackNavigationProp<SendDetailsStackParamList, 'Confirm'>;
|
||||
|
||||
const Confirm: React.FC = () => {
|
||||
const { wallets, fetchAndSaveWalletTransactions, counterpartyMetadata, isElectrumDisabled } = useStorage();
|
||||
const { wallets, fetchAndSaveWalletTransactions, counterpartyMetadata, isElectrumEnabled } = useStorage();
|
||||
const { isBiometricUseCapableAndEnabled } = useBiometrics();
|
||||
const navigation = useExtendedNavigation<ConfirmNavigationProp>();
|
||||
const route = useRoute<ConfirmRouteProp>(); // Get the route and its params
|
||||
@ -341,7 +341,7 @@ const Confirm: React.FC = () => {
|
||||
<ActivityIndicator />
|
||||
) : (
|
||||
<Button
|
||||
disabled={isElectrumDisabled || state.isButtonDisabled}
|
||||
disabled={isElectrumEnabled || state.isButtonDisabled}
|
||||
onPress={handleSendTransaction}
|
||||
title={loc.send.confirm_sendNow}
|
||||
/>
|
||||
|
@ -22,7 +22,7 @@ import { useStorage } from '../../hooks/context/useStorage';
|
||||
import { useExtendedNavigation } from '../../hooks/useExtendedNavigation';
|
||||
|
||||
const PsbtWithHardwareWallet = () => {
|
||||
const { txMetadata, fetchAndSaveWalletTransactions, isElectrumDisabled, wallets } = useStorage();
|
||||
const { txMetadata, fetchAndSaveWalletTransactions, isElectrumEnabled, wallets } = useStorage();
|
||||
const { isBiometricUseCapableAndEnabled } = useBiometrics();
|
||||
const navigation = useExtendedNavigation();
|
||||
const route = useRoute();
|
||||
@ -176,7 +176,7 @@ const PsbtWithHardwareWallet = () => {
|
||||
</TouchableOpacity>
|
||||
<BlueSpacing20 />
|
||||
<SecondButton
|
||||
disabled={isElectrumDisabled}
|
||||
disabled={isElectrumEnabled}
|
||||
onPress={broadcast}
|
||||
title={loc.send.confirm_sendNow}
|
||||
testID="PsbtWithHardwareWalletBroadcastTransactionButton"
|
||||
|
@ -21,7 +21,7 @@ const About: React.FC = () => {
|
||||
const { navigate } = useExtendedNavigation();
|
||||
const { colors } = useTheme();
|
||||
const { width, height } = useWindowDimensions();
|
||||
const { isElectrumDisabled } = useStorage();
|
||||
const { isElectrumEnabled } = useStorage();
|
||||
|
||||
const stylesHook = StyleSheet.create({
|
||||
textBackup: {
|
||||
@ -43,7 +43,7 @@ const About: React.FC = () => {
|
||||
};
|
||||
|
||||
const handleOnSelfTestPress = () => {
|
||||
if (isElectrumDisabled) {
|
||||
if (isElectrumEnabled) {
|
||||
presentAlert({ message: loc.settings.about_selftest_electrum_disabled });
|
||||
} else {
|
||||
navigate('SelfTest');
|
||||
|
@ -43,7 +43,6 @@ const ElectrumSettings: React.FC = () => {
|
||||
const { server } = useRoute<RouteProps>().params;
|
||||
const { setOptions } = useExtendedNavigation();
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isOfflineMode, setIsOfflineMode] = useState(true);
|
||||
const [serverHistory, setServerHistory] = useState<ElectrumServerItem[]>([]);
|
||||
const [config, setConfig] = useState<{ connected?: number; host?: string; port?: string }>({});
|
||||
const [host, setHost] = useState<string>('');
|
||||
@ -51,7 +50,7 @@ const ElectrumSettings: React.FC = () => {
|
||||
const [sslPort, setSslPort] = useState<number | undefined>(undefined);
|
||||
const [isAndroidNumericKeyboardFocused, setIsAndroidNumericKeyboardFocused] = useState(false);
|
||||
const [isAndroidAddressKeyboardVisible, setIsAndroidAddressKeyboardVisible] = useState(false);
|
||||
const { setIsElectrumDisabled } = useStorage();
|
||||
const { setIsElectrumEnabledStorage, isElectrumEnabled } = useStorage();
|
||||
|
||||
const stylesHook = StyleSheet.create({
|
||||
inputWrap: {
|
||||
@ -89,19 +88,25 @@ const ElectrumSettings: React.FC = () => {
|
||||
const savedSslPort = await AsyncStorage.getItem(BlueElectrum.ELECTRUM_SSL_PORT);
|
||||
const serverHistoryStr = await AsyncStorage.getItem(BlueElectrum.ELECTRUM_SERVER_HISTORY);
|
||||
|
||||
const offlineMode = await BlueElectrum.isDisabled();
|
||||
const parsedServerHistory: ElectrumServerItem[] = serverHistoryStr ? JSON.parse(serverHistoryStr) : [];
|
||||
|
||||
setHost(savedHost || '');
|
||||
setPort(savedPort ? Number(savedPort) : undefined);
|
||||
setSslPort(savedSslPort ? Number(savedSslPort) : undefined);
|
||||
setServerHistory(parsedServerHistory);
|
||||
setIsOfflineMode(offlineMode);
|
||||
|
||||
setConfig(await BlueElectrum.getConfig());
|
||||
configInterval = setInterval(async () => {
|
||||
setConfig(await BlueElectrum.getConfig());
|
||||
}, 500);
|
||||
try {
|
||||
if (isElectrumEnabled) {
|
||||
await BlueElectrum.connectMain();
|
||||
setConfig(await BlueElectrum.getConfig());
|
||||
configInterval = setInterval(async () => {
|
||||
setConfig(await BlueElectrum.getConfig());
|
||||
}, 500);
|
||||
}
|
||||
} catch (error) {
|
||||
triggerHapticFeedback(HapticFeedbackTypes.NotificationError);
|
||||
presentAlert({ message: (error as Error).message });
|
||||
}
|
||||
|
||||
setIsLoading(false);
|
||||
};
|
||||
@ -111,7 +116,7 @@ const ElectrumSettings: React.FC = () => {
|
||||
return () => {
|
||||
if (configInterval) clearInterval(configInterval);
|
||||
};
|
||||
}, []);
|
||||
}, [isElectrumEnabled]);
|
||||
|
||||
useEffect(() => {
|
||||
if (server) {
|
||||
@ -272,9 +277,9 @@ const ElectrumSettings: React.FC = () => {
|
||||
|
||||
useEffect(() => {
|
||||
setOptions({
|
||||
headerRight: isOfflineMode ? null : () => HeaderRight,
|
||||
headerRight: isElectrumEnabled ? () => HeaderRight : undefined,
|
||||
});
|
||||
}, [HeaderRight, isOfflineMode, setOptions]);
|
||||
}, [HeaderRight, isElectrumEnabled, setOptions]);
|
||||
|
||||
const checkServer = async () => {
|
||||
setIsLoading(true);
|
||||
@ -327,15 +332,24 @@ const ElectrumSettings: React.FC = () => {
|
||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
|
||||
|
||||
if (value) {
|
||||
await BlueElectrum.setDisabled(true);
|
||||
setIsElectrumDisabled(true);
|
||||
BlueElectrum.forceDisconnect();
|
||||
try {
|
||||
await BlueElectrum.setDisabled(false);
|
||||
setIsElectrumEnabledStorage(true);
|
||||
await BlueElectrum.connectMain();
|
||||
} catch (error) {
|
||||
triggerHapticFeedback(HapticFeedbackTypes.NotificationError);
|
||||
presentAlert({ message: (error as Error).message });
|
||||
}
|
||||
} else {
|
||||
await BlueElectrum.setDisabled(false);
|
||||
setIsElectrumDisabled(false);
|
||||
BlueElectrum.connectMain();
|
||||
try {
|
||||
setIsElectrumEnabledStorage(false);
|
||||
BlueElectrum.forceDisconnect();
|
||||
await BlueElectrum.setDisabled(true);
|
||||
} catch (error) {
|
||||
triggerHapticFeedback(HapticFeedbackTypes.NotificationError);
|
||||
presentAlert({ message: (error as Error).message });
|
||||
}
|
||||
}
|
||||
setIsOfflineMode(value);
|
||||
};
|
||||
|
||||
const renderElectrumSettings = () => {
|
||||
@ -472,7 +486,7 @@ const ElectrumSettings: React.FC = () => {
|
||||
title={loc.settings.electrum_offline_mode}
|
||||
switch={{
|
||||
onValueChange: onElectrumConnectionEnabledSwitchChange,
|
||||
value: isOfflineMode,
|
||||
value: isElectrumEnabled,
|
||||
testID: 'ElectrumConnectionEnabledSwitch',
|
||||
}}
|
||||
disabled={isLoading}
|
||||
@ -480,7 +494,7 @@ const ElectrumSettings: React.FC = () => {
|
||||
subtitle={loc.settings.electrum_offline_description}
|
||||
/>
|
||||
|
||||
{!isOfflineMode && renderElectrumSettings()}
|
||||
{isElectrumEnabled && renderElectrumSettings()}
|
||||
</ScrollView>
|
||||
);
|
||||
};
|
||||
|
@ -70,7 +70,7 @@ export default class CPFP extends Component {
|
||||
stage: 1,
|
||||
txid,
|
||||
wallet,
|
||||
isElectrumDisabled: true,
|
||||
isElectrumEnabled: true,
|
||||
};
|
||||
}
|
||||
|
||||
@ -185,7 +185,7 @@ export default class CPFP extends Component {
|
||||
>
|
||||
<Text style={styles.actionText}>{loc.send.create_verify}</Text>
|
||||
</TouchableOpacity>
|
||||
<Button disabled={this.context.isElectrumDisabled} onPress={this.broadcast} title={loc.send.confirm_sendNow} />
|
||||
<Button disabled={this.context.isElectrumEnabled} onPress={this.broadcast} title={loc.send.confirm_sendNow} />
|
||||
</BlueCard>
|
||||
</View>
|
||||
);
|
||||
|
@ -51,7 +51,7 @@ import { CommonToolTipActions } from '../../typings/CommonToolTipActions';
|
||||
const ViewEditMultisigCosigners: React.FC = () => {
|
||||
const hasLoaded = useRef(false);
|
||||
const { colors } = useTheme();
|
||||
const { wallets, setWalletsWithNewOrder, isElectrumDisabled } = useStorage();
|
||||
const { wallets, setWalletsWithNewOrder, isElectrumEnabled } = useStorage();
|
||||
const { isBiometricUseCapableAndEnabled } = useBiometrics();
|
||||
const { navigate, dispatch, addListener } = useExtendedNavigation();
|
||||
const openScannerButtonRef = useRef();
|
||||
@ -174,7 +174,7 @@ const ViewEditMultisigCosigners: React.FC = () => {
|
||||
let newWallets = wallets.filter(newWallet => {
|
||||
return newWallet.getID() !== walletID;
|
||||
}) as MultisigHDWallet[];
|
||||
if (!isElectrumDisabled) {
|
||||
if (isElectrumEnabled) {
|
||||
await wallet?.fetchBalance();
|
||||
}
|
||||
newWallets.push(wallet);
|
||||
|
@ -51,7 +51,7 @@ const buttonFontSize =
|
||||
type WalletTransactionsProps = NativeStackScreenProps<DetailViewStackParamList, 'WalletTransactions'>;
|
||||
|
||||
const WalletTransactions: React.FC<WalletTransactionsProps> = ({ route }) => {
|
||||
const { wallets, saveToDisk, setSelectedWalletID, isElectrumDisabled, setReloadTransactionsMenuActionFunction } = useStorage();
|
||||
const { wallets, saveToDisk, setSelectedWalletID, isElectrumEnabled, setReloadTransactionsMenuActionFunction } = useStorage();
|
||||
const { isBiometricUseCapableAndEnabled } = useBiometrics();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const { walletID } = route.params;
|
||||
@ -97,7 +97,7 @@ const WalletTransactions: React.FC<WalletTransactionsProps> = ({ route }) => {
|
||||
|
||||
const refreshTransactions = useCallback(async () => {
|
||||
console.debug('refreshTransactions, ', wallet?.getLabel());
|
||||
if (!wallet || isElectrumDisabled || isLoading) return;
|
||||
if (!wallet || isElectrumEnabled || isLoading) return;
|
||||
setIsLoading(true);
|
||||
let smthChanged = false;
|
||||
try {
|
||||
@ -126,7 +126,7 @@ const WalletTransactions: React.FC<WalletTransactionsProps> = ({ route }) => {
|
||||
}
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [wallet, isElectrumDisabled, isLoading, saveToDisk, pageSize]);
|
||||
}, [wallet, isElectrumEnabled, isLoading, saveToDisk, pageSize]);
|
||||
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
@ -373,7 +373,7 @@ const WalletTransactions: React.FC<WalletTransactionsProps> = ({ route }) => {
|
||||
}, [setReloadTransactionsMenuActionFunction, refreshTransactions]),
|
||||
);
|
||||
|
||||
const refreshProps = isDesktop || isElectrumDisabled ? {} : { refreshing: isLoading, onRefresh: refreshTransactions };
|
||||
const refreshProps = isDesktop || isElectrumEnabled ? {} : { refreshing: isLoading, onRefresh: refreshTransactions };
|
||||
|
||||
return (
|
||||
<View style={styles.flex}>
|
||||
|
@ -104,7 +104,7 @@ const WalletsList: React.FC = () => {
|
||||
getBalance,
|
||||
refreshAllWalletTransactions,
|
||||
setSelectedWalletID,
|
||||
isElectrumDisabled,
|
||||
isElectrumEnabled,
|
||||
setReloadTransactionsMenuActionFunction,
|
||||
} = useStorage();
|
||||
const { isTotalBalanceEnabled } = useSettings();
|
||||
@ -176,7 +176,7 @@ const WalletsList: React.FC = () => {
|
||||
*/
|
||||
const refreshTransactions = useCallback(
|
||||
async (showLoadingIndicator = true, showUpdateStatusIndicator = false) => {
|
||||
if (isElectrumDisabled) {
|
||||
if (isElectrumEnabled) {
|
||||
dispatch({ type: ActionTypes.SET_LOADING, payload: false });
|
||||
return;
|
||||
}
|
||||
@ -185,7 +185,7 @@ const WalletsList: React.FC = () => {
|
||||
dispatch({ type: ActionTypes.SET_LOADING, payload: false });
|
||||
});
|
||||
},
|
||||
[isElectrumDisabled, refreshAllWalletTransactions],
|
||||
[isElectrumEnabled, refreshAllWalletTransactions],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@ -415,7 +415,7 @@ const WalletsList: React.FC = () => {
|
||||
// Optimized for Mac option doesn't like RN Refresh component. Menu Elements now handles it for macOS
|
||||
}, [refreshTransactions]);
|
||||
|
||||
const refreshProps = isDesktop || isElectrumDisabled ? {} : { refreshing: isLoading, onRefresh };
|
||||
const refreshProps = isDesktop || isElectrumEnabled ? {} : { refreshing: isLoading, onRefresh };
|
||||
|
||||
const sections: SectionData[] = [
|
||||
{ key: WalletsListSections.CAROUSEL, data: [WalletsListSections.CAROUSEL] },
|
||||
|
@ -40,7 +40,7 @@ import { CommonToolTipActions } from '../../typings/CommonToolTipActions';
|
||||
const staticCache = {};
|
||||
|
||||
const WalletsAddMultisigStep2 = () => {
|
||||
const { addWallet, saveToDisk, isElectrumDisabled, sleep, currentSharedCosigner, setSharedCosigner } = useStorage();
|
||||
const { addWallet, saveToDisk, isElectrumEnabled, sleep, currentSharedCosigner, setSharedCosigner } = useStorage();
|
||||
const { colors } = useTheme();
|
||||
|
||||
const { navigate, navigateToWalletsList } = useExtendedNavigation();
|
||||
@ -168,7 +168,7 @@ const WalletsAddMultisigStep2 = () => {
|
||||
w.addCosigner(cc[0], fp, cc[2], cc[3]);
|
||||
}
|
||||
w.setLabel(walletLabel);
|
||||
if (!isElectrumDisabled) {
|
||||
if (isElectrumEnabled) {
|
||||
await w.fetchBalance();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user