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

fix(general bugs): workflow fixes #685

Merged
merged 4 commits into from
Mar 18, 2023
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
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 @@ -358,6 +358,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 @@ -300,7 +300,7 @@ const filterLndBackends = (network: Network) => {
if (lndBackends.length === 0) {
throw new Error(l('lndBackendCompatError'));
}
return lndBackends;
return lndBackends[0];
};

export const createTarodNetworkNode = (
Expand All @@ -311,8 +311,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