Skip to content

Commit 4f219a0

Browse files
committed
fix(lightning): make gift code wait for peers
1 parent 45d6140 commit 4f219a0

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

src/screens/Gift/Loading.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { showSheet } from '../../store/utils/ui';
2323
import { BodyM } from '../../styles/text';
2424
import { giftOrder, giftPay, openChannel } from '../../utils/blocktank';
2525
import { vibrate } from '../../utils/helpers';
26+
import { waitForLdkPeers } from '../../utils/lightning';
2627

2728
const imageSrc = require('../../assets/illustrations/gift.png');
2829

@@ -117,6 +118,8 @@ const Loading = ({
117118
sheetRef.current?.close();
118119
};
119120

121+
await waitForLdkPeers();
122+
120123
if (maxInboundCapacity >= amount) {
121124
await getWithLiquidity();
122125
} else {

src/screens/Shop/ShopMain.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { memo, ReactElement } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { StyleSheet, View } from 'react-native';
4+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
45
import { WebView, WebViewMessageEvent } from 'react-native-webview';
56

67
import NavigationHeader from '../../components/NavigationHeader';
@@ -15,6 +16,7 @@ const ShopMain = ({
1516
}: RootStackScreenProps<'ShopMain'>): ReactElement => {
1617
const { page } = route.params;
1718
const { t } = useTranslation('other');
19+
const insets = useSafeAreaInsets();
1820

1921
const baseUrl = 'https://embed.bitrefill.com';
2022
// Payment method "bitcoin" gives a unified invoice
@@ -38,8 +40,9 @@ const ShopMain = ({
3840

3941
<View style={styles.content}>
4042
<WebView
41-
style={styles.webview}
43+
containerStyle={[styles.webview, { marginBottom: insets.bottom }]}
4244
source={{ uri }}
45+
forceDarkOn={true}
4346
onMessage={handleMessage}
4447
/>
4548
</View>
@@ -58,8 +61,6 @@ const styles = StyleSheet.create({
5861
webview: {
5962
backgroundColor: '#141716',
6063
borderRadius: 8,
61-
flex: 1,
62-
marginBottom: 16,
6364
},
6465
});
6566

src/utils/blocktank/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,6 @@ export const giftPay = async (invoice: string): Promise<Result<IGift>> => {
399399
};
400400

401401
export const giftOrder = async (code: string): Promise<Result<IGift>> => {
402-
// Ensure we're properly connected to the Blocktank node prior to buying a channel.
403-
const addPeersRes = await addPeers();
404-
if (addPeersRes.isErr()) {
405-
return err(i18n.t('other:bt_error_connect'));
406-
}
407-
408402
// Get the node ID to use for the order.
409403
const nodeIdResult = await getNodeId();
410404
if (nodeIdResult.isErr()) {

src/utils/lightning/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,23 @@ export const waitForLdk = async (): Promise<void> => {
11511151
});
11521152
};
11531153

1154+
export const waitForLdkPeers = async (): Promise<void> => {
1155+
await tryNTimes({
1156+
toTry: async () => {
1157+
const peersResult = await ldk.listPeers();
1158+
if (peersResult.isOk()) {
1159+
if (peersResult.value.length > 0) {
1160+
return ok(peersResult.value);
1161+
}
1162+
return err('no peers connected');
1163+
}
1164+
return err('error getting peers');
1165+
},
1166+
times: 5,
1167+
interval: 1000,
1168+
});
1169+
};
1170+
11541171
export const waitForLdkChannels = async (): Promise<void> => {
11551172
await tryNTimes({
11561173
toTry: async () => {

0 commit comments

Comments
 (0)