Improve liquid (#890)
* remove unused imports * remove legacy liquid navigation listener * add extra details prop to spark receive payment wrapper * improve robusness of liquid swaps * bump breez sdk + change swap message * making sure to only mark failed if payment truly failed * improve fee
This commit is contained in:
@@ -4,7 +4,6 @@ import { useAppStatus } from './appStatus';
|
||||
import { crashlyticsLogReport } from '../app/functions/crashlyticsLogs';
|
||||
import { useRootstockProvider } from './rootstockSwapContext';
|
||||
import i18next from 'i18next';
|
||||
import { useNodeContext } from './nodeContext';
|
||||
|
||||
export function RootstockNavigationListener() {
|
||||
const navigation = useNavigation();
|
||||
@@ -37,35 +36,3 @@ export function RootstockNavigationListener() {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function LiquidNavigationListener() {
|
||||
const navigation = useNavigation();
|
||||
const { didGetToHomepage } = useAppStatus();
|
||||
const { pendingLiquidPayment, setPendingLiquidPayment } = useNodeContext();
|
||||
const isNavigating = useRef(false); // Use a ref for local state
|
||||
|
||||
useEffect(() => {
|
||||
if (!pendingLiquidPayment) return;
|
||||
if (!didGetToHomepage) {
|
||||
setPendingLiquidPayment(null);
|
||||
return;
|
||||
}
|
||||
if (isNavigating.current) return;
|
||||
crashlyticsLogReport(`Navigating to confirm tx page in liquid listener `);
|
||||
isNavigating.current = true;
|
||||
|
||||
setTimeout(() => {
|
||||
requestAnimationFrame(() => {
|
||||
navigation.navigate('ErrorScreen', {
|
||||
errorMessage: i18next.t('errormessages.receivedLiquid'),
|
||||
});
|
||||
isNavigating.current = false;
|
||||
console.log('cleaning up navigation for liquid');
|
||||
});
|
||||
}, 100);
|
||||
|
||||
setPendingLiquidPayment(null);
|
||||
}, [pendingLiquidPayment, didGetToHomepage]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import loadNewFiatData from '../app/functions/saveAndUpdateFiatData';
|
||||
import { useKeysContext } from './keys';
|
||||
import { useAppStatus } from './appStatus';
|
||||
import { useSparkWallet } from './sparkContext';
|
||||
import { useGlobalContactsInfo } from './globalContacts';
|
||||
import { useWebView } from './webViewContext';
|
||||
import liquidToSparkSwap from '../app/functions/spark/liquidToSparkSwap';
|
||||
import { useAuthContext } from './authContext';
|
||||
import { ensureLiquidConnection } from '../app/functions/breezLiquid/liquidNodeManager';
|
||||
@@ -22,12 +22,11 @@ import { SATSPERBITCOIN } from '../app/constants';
|
||||
const NodeContextManager = createContext(null);
|
||||
|
||||
const GLobalNodeContextProider = ({ children }) => {
|
||||
const { globalContactsInformation } = useGlobalContactsInfo();
|
||||
const { sparkInformation } = useSparkWallet();
|
||||
const { sendWebViewRequest } = useWebView();
|
||||
const { contactsPrivateKey, publicKey, accountMnemoinc } = useKeysContext();
|
||||
const { didGetToHomepage, minMaxLiquidSwapAmounts } = useAppStatus();
|
||||
const { masterInfoObject } = useGlobalContextProvider();
|
||||
const [pendingLiquidPayment, setPendingLiquidPayment] = useState(null);
|
||||
const [liquidNodeInformation, setLiquidNodeInformation] = useState({
|
||||
didConnectToNode: null,
|
||||
transactions: [],
|
||||
@@ -108,11 +107,18 @@ const GLobalNodeContextProider = ({ children }) => {
|
||||
useEffect(() => {
|
||||
async function swapLiquidToSpark() {
|
||||
try {
|
||||
if (liquidNodeInformation.userBalance > minMaxLiquidSwapAmounts.min) {
|
||||
setPendingLiquidPayment(true);
|
||||
await liquidToSparkSwap(
|
||||
globalContactsInformation.myProfile.uniqueName,
|
||||
);
|
||||
// Only sweep funds that aren't already locked in an in-flight send,
|
||||
// so overlapping balance updates can't trigger a double swap.
|
||||
const spendableSat =
|
||||
liquidNodeInformation.userBalance -
|
||||
(liquidNodeInformation.pendingSend || 0);
|
||||
if (spendableSat > minMaxLiquidSwapAmounts.min) {
|
||||
await liquidToSparkSwap({
|
||||
mnemonic: accountMnemoinc,
|
||||
sparkInformation,
|
||||
spendableSat,
|
||||
sendWebViewRequest,
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('transfering liquid to spark error', err);
|
||||
@@ -126,10 +132,12 @@ const GLobalNodeContextProider = ({ children }) => {
|
||||
}, [
|
||||
didGetToHomepage,
|
||||
liquidNodeInformation.userBalance,
|
||||
minMaxLiquidSwapAmounts,
|
||||
liquidNodeInformation.pendingSend,
|
||||
minMaxLiquidSwapAmounts.min,
|
||||
sparkInformation.didConnect,
|
||||
sparkInformation.identityPubKey,
|
||||
globalContactsInformation?.myProfile?.uniqueName,
|
||||
accountMnemoinc,
|
||||
sendWebViewRequest,
|
||||
masterInfoObject.enabledLiquidAutoSwap,
|
||||
]);
|
||||
|
||||
@@ -147,8 +155,6 @@ const GLobalNodeContextProider = ({ children }) => {
|
||||
toggleLiquidNodeInformation,
|
||||
toggleFiatStats,
|
||||
fiatStats,
|
||||
pendingLiquidPayment,
|
||||
setPendingLiquidPayment,
|
||||
SATS_PER_DOLLAR,
|
||||
}),
|
||||
[
|
||||
@@ -156,8 +162,6 @@ const GLobalNodeContextProider = ({ children }) => {
|
||||
fiatStats,
|
||||
toggleFiatStats,
|
||||
toggleLiquidNodeInformation,
|
||||
pendingLiquidPayment,
|
||||
setPendingLiquidPayment,
|
||||
SATS_PER_DOLLAR,
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user