Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v0.9.0] Improve PaymentPath #2130

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
88 changes: 58 additions & 30 deletions components/PaymentPath.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import { inject, observer } from 'mobx-react';
import { observer } from 'mobx-react';

import PrivacyUtils from '../utils/PrivacyUtils';
import { themeColor } from '../utils/ThemeUtils';
Expand Down Expand Up @@ -86,7 +86,7 @@ const Hop = (props: any) => {
fontFamily: 'PPNeueMontreal-Medium'
}}
>
{path.length}
{path.length + 1}
</Text>
</View>
</Row>
Expand All @@ -97,6 +97,8 @@ const Hop = (props: any) => {

const ExpandedHop = (props: any) => {
const { pathIndex, hop, path, aliasMap, loading } = props;
const isOrigin = hop.sent != null;
const isDestination = pathIndex === path.length;
return (
<View
key={pathIndex}
Expand All @@ -105,10 +107,9 @@ const ExpandedHop = (props: any) => {
marginRight: 20,
borderStyle: 'dotted',
borderLeftWidth: 3,
borderColor:
path.length == pathIndex + 1
? 'transparent'
: themeColor('secondaryText')
borderColor: isDestination
? 'transparent'
: themeColor('secondaryText')
}}
>
<Row>
Expand Down Expand Up @@ -154,7 +155,9 @@ const ExpandedHop = (props: any) => {
}}
>
{`${
aliasMap.get(hop.pubKey)
isOrigin
? localeString('views.Channel.yourNode')
: aliasMap.get(hop.pubKey)
? PrivacyUtils.sensitiveValue(
aliasMap.get(hop.pubKey)
)
Expand All @@ -176,31 +179,43 @@ const ExpandedHop = (props: any) => {
</Row>

<View style={{ marginLeft: 50, marginBottom: 15 }}>
<KeyValue
keyValue={localeString('models.Payment.forwarded')}
value={<Amount sats={hop.forwarded} toggleable />}
sensitive
/>

<KeyValue
keyValue={localeString('models.Payment.fee')}
value={<Amount sats={hop.fee} toggleable />}
sensitive
/>
{hop.sent ? (
<KeyValue
keyValue={localeString('general.sent')}
value={<Amount sats={hop.sent} toggleable />}
sensitive
/>
) : (
<KeyValue
keyValue={
isDestination
? localeString('general.received')
: localeString('models.Payment.forwarded')
}
value={<Amount sats={hop.forwarded} toggleable />}
sensitive
/>
)}
{!isOrigin && !isDestination && (
<KeyValue
keyValue={localeString('models.Payment.fee')}
value={<Amount sats={hop.fee} toggleable />}
sensitive
/>
)}
</View>
</View>
);
};

interface PaymentPathProps {
enhancedPath: any;
enhancedPath: any[];
}

interface PaymentPathState {
expanded: any;
}

@inject('ChannelsStore')
@observer
export default class PaymentPath extends React.Component<
PaymentPathProps,
Expand All @@ -218,28 +233,27 @@ export default class PaymentPath extends React.Component<
const { expanded } = this.state;

const aliasMap = stores.channelsStore.aliasMap;
const ourPubKey = stores.nodeInfoStore.nodeInfo.nodeId;

const paths: any = [];
const paths: any[] = [];
const updateMap = (k: number, v: boolean) => {
this.setState({
expanded: new Map(expanded.set(k, v))
});
};
enhancedPath.map((path: any, index: number) => {
enhancedPath.forEach((path: any[], index: number) => {
const hops: any = [];
let title = '';
path.map((hop: any, key: number) => {
let title = localeString('views.Channel.yourNode');
path.forEach((hop) => {
const displayName = aliasMap.get(hop.pubKey) || hop.node;
title += ', ';
title +=
hop.node.length >= 66
displayName.length >= 66
? `${PrivacyUtils.sensitiveValue(displayName).slice(
0,
6
)}...`
: PrivacyUtils.sensitiveValue(displayName);
if (key + 1 !== path.length) {
title += ', ';
}
});
if (enhancedPath.length > 1) {
hops.push(
Expand All @@ -252,7 +266,21 @@ export default class PaymentPath extends React.Component<
/>
);
}
path.map((hop: any, pathIndex: number) => {
const origin = {
sent: Number(path[0].forwarded) + Number(path[0].fee),
pubKey: ourPubKey
};
if (expanded.get(index) || enhancedPath.length === 1) {
hops.push(
<ExpandedHop
pathIndex={0}
path={path}
hop={origin}
aliasMap={aliasMap}
/>
);
}
path.forEach((hop: any, pathIndex: number) => {
let loading = false;
if (!hop.alias && !aliasMap.get(hop.pubKey)) {
loading = true;
Expand All @@ -263,7 +291,7 @@ export default class PaymentPath extends React.Component<
(expanded.get(index) || enhancedPath.length === 1) &&
hops.push(
<ExpandedHop
pathIndex={pathIndex}
pathIndex={pathIndex + 1}
path={path}
hop={hop}
aliasMap={aliasMap}
Expand Down
2 changes: 1 addition & 1 deletion models/Payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { lnrpc } from '../proto/lightning';
export default class Payment extends BaseModel {
private payment_hash: string | { data: number[]; type: string }; // object if lndhub
creation_date?: string;
value: string | number;
value?: string | number;
fee_sat?: string;
fee_msat?: string;
payment_preimage: string;
Expand Down
2 changes: 1 addition & 1 deletion stores/ChannelsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class ChannelsStore {
};
@observable public showSearch: boolean = false;
// aliasMap
@observable public aliasMap: any = observable.map({});
@observable public aliasMap = observable.map({});

settingsStore: SettingsStore;

Expand Down
Loading