Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/screens/Gift/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { showSheet } from '../../store/utils/ui';
import { BodyM } from '../../styles/text';
import { giftOrder, giftPay, openChannel } from '../../utils/blocktank';
import { vibrate } from '../../utils/helpers';
import { waitForLdkPeers } from '../../utils/lightning';

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

Expand Down Expand Up @@ -117,6 +118,8 @@ const Loading = ({
sheetRef.current?.close();
};

await waitForLdkPeers();

if (maxInboundCapacity >= amount) {
await getWithLiquidity();
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/screens/Shop/ShopMain.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { memo, ReactElement } from 'react';
import { useTranslation } from 'react-i18next';
import { StyleSheet, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { WebView, WebViewMessageEvent } from 'react-native-webview';

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

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

<View style={styles.content}>
<WebView
style={styles.webview}
containerStyle={[styles.webview, { marginBottom: insets.bottom }]}
source={{ uri }}
forceDarkOn={true}
onMessage={handleMessage}
/>
</View>
Expand All @@ -58,8 +61,6 @@ const styles = StyleSheet.create({
webview: {
backgroundColor: '#141716',
borderRadius: 8,
flex: 1,
marginBottom: 16,
},
});

Expand Down
6 changes: 0 additions & 6 deletions src/utils/blocktank/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,6 @@ export const giftPay = async (invoice: string): Promise<Result<IGift>> => {
};

export const giftOrder = async (code: string): Promise<Result<IGift>> => {
// Ensure we're properly connected to the Blocktank node prior to buying a channel.
const addPeersRes = await addPeers();
if (addPeersRes.isErr()) {
return err(i18n.t('other:bt_error_connect'));
}

// Get the node ID to use for the order.
const nodeIdResult = await getNodeId();
if (nodeIdResult.isErr()) {
Expand Down
17 changes: 17 additions & 0 deletions src/utils/lightning/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,23 @@ export const waitForLdk = async (): Promise<void> => {
});
};

export const waitForLdkPeers = async (): Promise<void> => {
await tryNTimes({
toTry: async () => {
const peersResult = await ldk.listPeers();
if (peersResult.isOk()) {
if (peersResult.value.length > 0) {
return ok(peersResult.value);
}
return err('no peers connected');
}
return err('error getting peers');
},
times: 5,
interval: 1000,
});
};

export const waitForLdkChannels = async (): Promise<void> => {
await tryNTimes({
toTry: async () => {
Expand Down
Loading