Skip to content

Commit

Permalink
Adding QR codes for all addresses of a contact
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamkmr04 committed Jan 4, 2024
1 parent 71fe896 commit 09e5474
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import NodeInfo from './views/NodeInfo';
import NetworkInfo from './views/NetworkInfo';
import Lockscreen from './views/Lockscreen';
import NostrContacts from './views/NostrContacts';
import ContactInfo from './views/ContactInfo';

// Settings views
import Settings from './views/Settings/Settings';
Expand Down Expand Up @@ -395,6 +396,9 @@ const AppScenes = {
},
NostrContacts: {
screen: NostrContacts
},
ContactInfo: {
screen: ContactInfo
}
};

Expand Down
6 changes: 1 addition & 5 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"general.content": "Content",
"general.lightningInvoice": "Lightning invoice",
"general.or": "or",
"general.readOnlyWallet": "Read-only wallet",
"general.reset": "Reset",
"general.other": "Other",
"views.Settings.Support.title": "Support ZEUS",
Expand Down Expand Up @@ -471,7 +470,6 @@
"views.OpenChannel.private": "Private",
"views.Payment.title": "Payment",
"views.Payment.inTransitPayment": "In Transit Payment",
"views.Payment.failedPayment": "Failed Payment",
"views.Payment.fee": "Fee",
"views.Payment.paymentHash": "Payment Hash",
"views.Payment.paymentPreimage": "Payment Preimage",
Expand Down Expand Up @@ -508,7 +506,6 @@
"views.PaymentRequest.lndGettingReadyReceive": "LND is getting ready to receive payments. Please wait.",
"views.PaymentRequest.isPmtHashSigValid": "Payment hash signature",
"views.PaymentRequest.isRelaysSigValid": "Relays signature",
"views.PaymentRequest.notAllowedToSend": "This wallet is not allowed to send funds!",
"views.Receive.title": "Receive",
"views.Receive.successCreate": "Successfully created invoice",
"views.Receive.warningLndHub": "Please note that LNDHub has a fixed on-chain address",
Expand Down Expand Up @@ -592,6 +589,7 @@
"views.NostrContacts.enterNpub": "Enter npub",
"views.NostrContacts.importContactsError": "Failed to import contacts. Please try again.",
"views.ContactDetails.saveToContacts": "Save to Contacts",
"views.ContactInfo.title": "Contact Info",
"views.Settings.title": "Settings",
"views.Settings.enabled": "Enabled",
"views.Settings.disabled": "Disabled",
Expand Down Expand Up @@ -814,7 +812,6 @@
"views.ActivityFilter.onChainPayments": "On-chain payments",
"views.ActivityFilter.minimumAmount": "Minimum Amount (sats)",
"views.ActivityFilter.inTransit": "In transit payments",
"views.ActivityFilter.isFailed": "Failed payments",
"general.clearChanges": "Clear changes",
"views.Routing.RoutingEvent.sourceChannel": "Source Channel",
"views.Routing.RoutingEvent.destinationChannel": "Destination Channel",
Expand Down Expand Up @@ -907,7 +904,6 @@
"views.Settings.LightningAddress.nostrKeys.changeWarning": "Warning: changing your Nostr keys will delete your pending payments. Please redeem your pending payments before submitting new keys.",
"views.Settings.LightningAddress.explainer1": "To get started with a lightning address you must first have a lightning channel and inbound liquidity.",
"views.Settings.LightningAddress.explainer2": "The easiest way to do so is to purchase a 0-conf channel from our LSP, OLYMPUS by ZEUS. Just generate an invoice and pay yourself from another lightning wallet.",
"views.Settings.LightningAddress.explainer3": "For best results, open up a channel with our node, OLYMPUS by ZEUS.",
"views.Settings.LightningAddress.get0ConfChan": "Get 0-conf channel",
"views.Settings.LightningAddressSettings.title": "Lightning address settings",
"views.Settings.LightningAddressSettings.automaticallyAccept": "Automatically accept payments on startup",
Expand Down
15 changes: 12 additions & 3 deletions views/ContactDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,21 @@ export default class ContactDetails extends React.Component<
</TouchableOpacity>
);

const filterEmptyValues = (array: any) =>
(array || []).filter((value: any) => value !== '');

const QRButton = () => (
<TouchableOpacity
onPress={() =>
navigation.navigate('QR', {
value: JSON.stringify(this.state.contact),
hideText: true
navigation.navigate('ContactInfo', {
contactData: JSON.stringify(this.state.contact),
addressData: [
...filterEmptyValues(this.state.contact?.lnAddress),
...filterEmptyValues(this.state.contact?.pubkey),
...filterEmptyValues(
this.state.contact?.onchainAddress
)
]
})
}
>
Expand Down
167 changes: 167 additions & 0 deletions views/ContactInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import React, { useEffect, useState } from 'react';
import { Dimensions, View, SafeAreaView } from 'react-native';

import Animated, {
Extrapolate,
SharedValue,
interpolate,
useAnimatedStyle,
useSharedValue
} from 'react-native-reanimated';
import Carousel from 'react-native-reanimated-carousel';

import Header from '../components/Header';
import { themeColor } from '../utils/ThemeUtils';
import CollapsedQR from '../components/CollapsedQR';

interface ContactInfoProps {
navigation: any;
}

interface IntroProps {
navigation: any;
}

const ContactInfo: React.FC<IntroProps> = (props: ContactInfoProps) => {
const [addressData, setAddressData] = useState(['']);
const { navigation } = props;

useEffect(() => {
const contactData = navigation.getParam('contactData', null);
const addressData = navigation.getParam('addressData', null);

setAddressData([contactData, ...addressData]);
}, [navigation]);

let screenWidth: number;
const progressValue = useSharedValue<number>(0);

screenWidth = Dimensions.get('window').width;

const renderItem = ({ item, index }: { item: any; index: number }) => (
<CollapsedQR value={item} expanded hideText={index === 0} />
);
const PaginationItem: React.FC<{
index: number;
backgroundColor: string;
length: number;
animValue: SharedValue<number>;
}> = (props) => {
const { animValue, index, length, backgroundColor } = props;
const width = 10;

const animStyle = useAnimatedStyle(() => {
let inputRange = [index - 1, index, index + 1];
let outputRange = [-width, 0, width];

if (index === 0 && animValue?.value > length - 1) {
inputRange = [length - 1, length, length + 1];
outputRange = [-width, 0, width];
}

return {
transform: [
{
translateX: interpolate(
animValue?.value ?? 0,
inputRange,
outputRange,
Extrapolate.CLAMP
)
}
]
};
}, [animValue, index, length]);
return (
<View
style={{
backgroundColor: themeColor('secondaryText'),
width,
height: width,
borderRadius: 50,
overflow: 'hidden'
}}
>
<Animated.View
style={[
{
borderRadius: 50,
backgroundColor,
flex: 1
},
animStyle
]}
/>
</View>
);
};
return (
<SafeAreaView
style={{
flex: 1,
backgroundColor: themeColor('background')
}}
>
<Header
leftComponent="Back"
containerStyle={{
borderBottomWidth: 0
}}
navigation={navigation}
/>
<View
style={{
flexGrow: 1,
flexShrink: 1,
justifyContent: 'center'
}}
>
<Carousel
withAnimation={{
type: 'spring',
config: {
damping: 13
}
}}
data={addressData}
width={screenWidth}
renderItem={renderItem}
onProgressChange={(_, absoluteProgress) =>
(progressValue.value = absoluteProgress)
}
loop={false}
mode="parallax"
modeConfig={{
parallaxScrollingScale: 0.9,
parallaxScrollingOffset: 0
}}
/>
</View>
{addressData.length > 1 && (
<View
style={{
flexDirection: 'row',
justifyContent: 'space-between',
width: 100,
marginBottom: 10,
alignSelf: 'center'
}}
>
{addressData.map((_, index) => {
return (
<PaginationItem
backgroundColor={themeColor('highlight')}
animValue={progressValue}
index={index}
key={index}
length={addressData.length}
/>
);
})}
</View>
)}
</SafeAreaView>
);
};

export default ContactInfo;

0 comments on commit 09e5474

Please sign in to comment.