FIX: following onchain+offchain invoice

This commit is contained in:
Ivan Vershigora 2020-06-05 16:15:54 +03:00 committed by Overtorment
parent c332f718de
commit 46653d8551
4 changed files with 29 additions and 26 deletions

View file

@ -211,18 +211,6 @@ const ScanLndInvoiceRoot = () => (
</ScanLndInvoiceStack.Navigator> </ScanLndInvoiceStack.Navigator>
); );
const HandleOffchainAndOnChainStack = createStackNavigator();
const HandleOffchainAndOnChain = () => (
<HandleOffchainAndOnChainStack.Navigator screenOptions={{ headerBackTitleVisible: false, ...defaultStackScreenOptions }}>
{/* screens */}
<HandleOffchainAndOnChainStack.Screen name="SelectWallet" component={SelectWallet} options={SelectWallet.navigationOptions} />
<HandleOffchainAndOnChainStack.Screen name="ScanQRCode" component={ScanQRCodeRoot} />
{/* stacks */}
<HandleOffchainAndOnChainStack.Screen name="ScanLndInvoice" component={ScanLndInvoiceRoot} options={{ headerShown: false }} />
<HandleOffchainAndOnChainStack.Screen name="SendDetails" component={SendDetailsRoot} options={{ headerShown: false }} />
</HandleOffchainAndOnChainStack.Navigator>
);
const AztecoRedeemStack = createStackNavigator(); const AztecoRedeemStack = createStackNavigator();
const AztecoRedeemRoot = () => ( const AztecoRedeemRoot = () => (
<AztecoRedeemStack.Navigator screenOptions={defaultStackScreenOptions}> <AztecoRedeemStack.Navigator screenOptions={defaultStackScreenOptions}>
@ -247,7 +235,6 @@ const Navigation = () => (
<RootStack.Screen name="SendDetailsRoot" component={SendDetailsRoot} options={{ headerShown: false }} /> <RootStack.Screen name="SendDetailsRoot" component={SendDetailsRoot} options={{ headerShown: false }} />
<RootStack.Screen name="LNDCreateInvoiceRoot" component={LNDCreateInvoiceRoot} options={{ headerShown: false }} /> <RootStack.Screen name="LNDCreateInvoiceRoot" component={LNDCreateInvoiceRoot} options={{ headerShown: false }} />
<RootStack.Screen name="ScanLndInvoiceRoot" component={ScanLndInvoiceRoot} options={{ headerShown: false }} /> <RootStack.Screen name="ScanLndInvoiceRoot" component={ScanLndInvoiceRoot} options={{ headerShown: false }} />
<RootStack.Screen name="HandleOffchainAndOnChain" component={HandleOffchainAndOnChain} options={{ headerShown: false }} />
<RootStack.Screen name="AztecoRedeemRoot" component={AztecoRedeemRoot} options={{ headerShown: false }} /> <RootStack.Screen name="AztecoRedeemRoot" component={AztecoRedeemRoot} options={{ headerShown: false }} />
<RootStack.Screen <RootStack.Screen
name="ScanQRCodeRoot" name="ScanQRCodeRoot"

View file

@ -68,12 +68,11 @@ class DeeplinkSchemaMatch {
} }
if (isBothBitcoinAndLightning) { if (isBothBitcoinAndLightning) {
completionHandler([ completionHandler([
'HandleOffchainAndOnChain', 'SelectWallet',
{ {
screen: 'SelectWallet', onWalletSelect: (wallet, { navigation }) => {
params: { navigation.pop(); // close select wallet screen
onWalletSelect: wallet => navigation.navigate(...DeeplinkSchemaMatch.isBothBitcoinAndLightningOnWalletSelect(wallet, isBothBitcoinAndLightning));
completionHandler(DeeplinkSchemaMatch.isBothBitcoinAndLightningOnWalletSelect(wallet, isBothBitcoinAndLightning)),
}, },
}, },
]); ]);
@ -206,18 +205,24 @@ class DeeplinkSchemaMatch {
static isBothBitcoinAndLightningOnWalletSelect(wallet, uri) { static isBothBitcoinAndLightningOnWalletSelect(wallet, uri) {
if (wallet.chain === Chain.ONCHAIN) { if (wallet.chain === Chain.ONCHAIN) {
return [ return [
'SendDetails', 'SendDetailsRoot',
{ {
uri: uri.bitcoin, screen: 'SendDetails',
fromWallet: wallet, params: {
uri: uri.bitcoin,
fromWallet: wallet,
},
}, },
]; ];
} else if (wallet.chain === Chain.OFFCHAIN) { } else if (wallet.chain === Chain.OFFCHAIN) {
return [ return [
'ScanLndInvoice', 'ScanLndInvoiceRoot',
{ {
uri: uri.lndInvoice, screen: 'ScanLndInvoice',
fromSecret: wallet.getSecret(), params: {
uri: uri.lndInvoice,
fromSecret: wallet.getSecret(),
},
}, },
]; ];
} }

View file

@ -75,7 +75,7 @@ const styles = StyleSheet.create({
}, },
}); });
const SelectWallet = () => { const SelectWallet = ({ navigation }) => {
const { chainType, onWalletSelect, availableWallets } = useRoute().params; const { chainType, onWalletSelect, availableWallets } = useRoute().params;
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
let data = chainType let data = chainType
@ -96,7 +96,7 @@ const SelectWallet = () => {
<TouchableOpacity <TouchableOpacity
onPress={() => { onPress={() => {
ReactNativeHapticFeedback.trigger('selection', { ignoreAndroidSystemSettings: false }); ReactNativeHapticFeedback.trigger('selection', { ignoreAndroidSystemSettings: false });
onWalletSelect(item); onWalletSelect(item, { navigation });
}} }}
> >
<View shadowOpacity={40 / 100} shadowOffset={{ width: 0, height: 0 }} shadowRadius={5} style={styles.itemRoot}> <View shadowOpacity={40 / 100} shadowOffset={{ width: 0, height: 0 }} shadowRadius={5} style={styles.itemRoot}>

View file

@ -165,6 +165,17 @@ describe('unit - DeepLinkSchemaMatch', function () {
const navValue = await asyncNavigationRouteFor(event.argument); const navValue = await asyncNavigationRouteFor(event.argument);
assert.deepStrictEqual(navValue, event.expected); assert.deepStrictEqual(navValue, event.expected);
} }
// BIP21 w/BOLT11 support
assert.equal(
(
await asyncNavigationRouteFor({
url:
'bitcoin:1DamianM2k8WfNEeJmyqSe2YW1upB7UATx?amount=0.000001&lightning=lnbc1u1pwry044pp53xlmkghmzjzm3cljl6729cwwqz5hhnhevwfajpkln850n7clft4sdqlgfy4qv33ypmj7sj0f32rzvfqw3jhxaqcqzysxq97zvuq5zy8ge6q70prnvgwtade0g2k5h2r76ws7j2926xdjj2pjaq6q3r4awsxtm6k5prqcul73p3atveljkn6wxdkrcy69t6k5edhtc6q7lgpe4m5k4',
})
)[0],
'SelectWallet',
);
}); });
it('decodes bip21', () => { it('decodes bip21', () => {