Skip to content

Commit

Permalink
fix(taro): general fixes for taro integration (#685)
Browse files Browse the repository at this point in the history
-taro nodes connect in order when dropped into the graph
-Taro info asset draw title says 'No Assets' if there are no assets

---------

Co-authored-by: Andrew Oseen <[email protected]>
  • Loading branch information
2 people authored and jamaljsr committed May 16, 2023
1 parent 1514ebd commit 9bc234b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/components/designer/taro/info/AssetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useCallback } from 'react';
import { UnorderedListOutlined } from '@ant-design/icons';
import styled from '@emotion/styled';
import { Button, Divider, Space } from 'antd';
import { usePrefixedTranslation } from 'hooks';
import { TaroBalance } from 'lib/taro/types';
import { useStoreActions } from 'store';
import { format } from 'utils/units';
Expand All @@ -10,6 +11,9 @@ import AssetInfoDrawer from './AssetInfoDrawer';

const Styled = {
Wrapper: styled.div``,
Empty: styled.p`
text-align: center;
`,
};

interface Props {
Expand All @@ -19,6 +23,7 @@ interface Props {
}

const AssetsList: React.FC<Props> = ({ title, balances, nodeName }) => {
const { l } = usePrefixedTranslation('cmps.designer.taro.AssetsList');
const { showAssetInfo } = useStoreActions(s => s.modals);

const handleClick = useCallback(
Expand Down Expand Up @@ -49,7 +54,11 @@ const AssetsList: React.FC<Props> = ({ title, balances, nodeName }) => {
return (
<Wrapper>
<Divider>{title}</Divider>
<DetailsList details={assetDetails} />
{balances && balances.length > 0 ? (
<DetailsList details={assetDetails} />
) : (
<Styled.Empty>{l('noAssets')}</Styled.Empty>
)}
<AssetInfoDrawer />
</Wrapper>
);
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
"cmps.designer.taro.InfoTab.numAssets": "Number of Assets",
"cmps.designer.taro.InfoTab.assets": "Assets",
"cmps.designer.taro.InfoTab.startError": "Unable to connect to {{implementation}} node",
"cmps.designer.taro.AssetsList.noAssets": "No assets have been created.",
"cmps.designer.taro.TaroDetails.info": "Info",
"cmps.designer.taro.TaroDetails.connect": "Connect",
"cmps.designer.taro.TaroDetails.actions": "Actions",
Expand Down
43 changes: 42 additions & 1 deletion src/utils/network.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import detectPort from 'detect-port';
import { CLightningNode, LndNode, NodeImplementation, Status } from 'shared/types';
import { Network } from 'types';
import { defaultRepoState } from './constants';
import { getImageCommand, getOpenPortRange, getOpenPorts, OpenPorts } from './network';
import {
createLndNetworkNode,
createTarodNetworkNode,
getImageCommand,
getOpenPortRange,
getOpenPorts,
OpenPorts,
} from './network';
import { getNetwork, testManagedImages } from './tests';

const mockDetectPort = detectPort as jest.Mock;
Expand Down Expand Up @@ -232,4 +239,38 @@ describe('Network Utils', () => {
expect(ports[lnd2.name].rest).toBe(lnd2.ports.rest + 1);
});
});
describe('createNetworkNodes', () => {
let network: Network;

beforeEach(() => {
network = getNetwork(1, 'taro network', undefined, 3);
});
it('should add a taro node to the network', async () => {
const lnd = createLndNetworkNode(
network,
defaultRepoState.images.LND.versions[0],
undefined,
{ image: '', command: '' },
Status.Stopped,
);
const lnd2 = createLndNetworkNode(
network,
defaultRepoState.images.LND.versions[0],
undefined,
{ image: '', command: '' },
Status.Stopped,
);
network.nodes.lightning.push(lnd);
network.nodes.lightning.push(lnd2);
expect(network.nodes.lightning.length).toBe(5);
const taro = createTarodNetworkNode(
network,
defaultRepoState.images.tarod.latest,
{ image: '', command: '' },
Status.Stopped,
);
network.nodes.taro.push(taro);
expect(network.nodes.taro.length).toBe(4);
});
});
});
5 changes: 2 additions & 3 deletions src/utils/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ const filterLndBackends = (network: Network) => {
if (lndBackends.length === 0) {
throw new Error(l('lndBackendCompatError'));
}
return lndBackends;
return lndBackends[0];
};

export const createTarodNetworkNode = (
Expand All @@ -315,8 +315,7 @@ export const createTarodNetworkNode = (
): TarodNode => {
const { taro } = network.nodes;
const id = taro.length ? Math.max(...taro.map(n => n.id)) + 1 : 0;
const lndBackends = filterLndBackends(network);
const lndBackend = lndBackends[id % lndBackends.length];
const lndBackend = filterLndBackends(network);

const name = `${lndBackend.name}-taro`;
const node: TarodNode = {
Expand Down

0 comments on commit 9bc234b

Please sign in to comment.