Skip to content

Commit

Permalink
fix: access other pages directly
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamjajoo authored and vincenzopalazzo committed Aug 13, 2022
1 parent bdcecb8 commit 4a849d1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
11 changes: 9 additions & 2 deletions model/ModelProvider.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { container } from "tsyringe";
import { GetInfoNode } from "./CoreLN";
import APIProvider from "../api/APIProvider";

class ModelContaint {
static GET_INFO: string = "getinfo";
}

export default class ModelProvider {
public static getNodeInfo(): GetInfoNode {
return container.resolve(ModelContaint.GET_INFO);
public static async getNodeInfo(): Promise<GetInfoNode> {
if (container.isRegistered(ModelContaint.GET_INFO)) {
return container.resolve(ModelContaint.GET_INFO);
} else {
let nodeInfo = await APIProvider.api().getInfo();
this.setNodeInfo(nodeInfo);
return container.resolve(ModelContaint.GET_INFO);
}
}

public static setNodeInfo(nodeInfo: GetInfoNode) {
Expand Down
4 changes: 3 additions & 1 deletion pages/api/channelsInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default async function handler(
funds.channels = funds.channels.filter(
(channel) => channel.node_info != null
);
console.debug("List of channels from command: lightning-listfunds and lighting-listnodes: ");
console.debug(
"List of channels from command: lightning-listfunds and lighting-listnodes: "
);
console.debug(funds.channels);
res.status(200).json({ channels: funds.channels });
} catch (error) {
Expand Down
10 changes: 5 additions & 5 deletions pages/donation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
let offers = null;
let nodeInfo = null;
try {
nodeInfo = await ModelProvider.getNodeInfo();
offers = await APIProvider.api().listOffers(true);
nodeInfo = await APIProvider.api().getInfo();
ModelProvider.setNodeInfo(nodeInfo);
} catch (e) {
console.error(e);
return {
props: {
listOffers: null,
offer: null,
nodeInfo: nodeInfo,
error: e,
error: JSON.stringify(e),
},
};
}
Expand All @@ -58,5 +56,7 @@ export default function DonationPage({
}
console.debug("List of offers from the command: lightning-listoffers: ");
console.debug(listOffers);
return <DonationView nodeInfo={nodeInfo} listOffers={listOffers} offer={offer} />;
return (
<DonationView nodeInfo={nodeInfo} listOffers={listOffers} offer={offer} />
);
}
14 changes: 6 additions & 8 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,23 @@ type AppState = {
};

type AppProps = {
infoNode: GetInfoNode | null;
nodeInfo: GetInfoNode | null;
};

export const getServerSideProps: GetServerSideProps = async (context) => {
let infoNode = null;
let nodeInfo = null;
try {
// TODO: call also list nodes
infoNode = await APIProvider.api().getInfo();
ModelProvider.setNodeInfo(infoNode);
nodeInfo = await ModelProvider.getNodeInfo();
} catch (e) {
console.error(e);
}
return {
props: {
infoNode: infoNode,
nodeInfo: nodeInfo,
},
};
};

export default function Home({ infoNode }: AppProps) {
return <HomeView nodeInfo={infoNode} show={() => 1} />;
export default function Home({ nodeInfo }: AppProps) {
return <HomeView nodeInfo={nodeInfo} show={() => 1} />;
}
3 changes: 1 addition & 2 deletions pages/metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
let getMetricsOneOutput = null;
let nodeInfo = null;
try {
nodeInfo = await APIProvider.api().getInfo();
ModelProvider.setNodeInfo(nodeInfo);
nodeInfo = await ModelProvider.getNodeInfo();
getMetricsOneOutput = await APIProvider.api().getMetricsOneOutput(
nodeInfo.network,
nodeInfo.id
Expand Down

0 comments on commit 4a849d1

Please sign in to comment.