Skip to content

Commit

Permalink
try swapping out queries for event binding
Browse files Browse the repository at this point in the history
doesn't seem to be firing at the moment
  • Loading branch information
geoknee committed Oct 9, 2023
1 parent eb0f620 commit 44cb3d0
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions packages/payment-proxy-client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,6 @@ export default function App() {
.finally(() => console.timeEnd("Connect to Nitro Node"));
}, [url]);

const updateChannelInfo = async (channelId: string) => {
if (channelId == "") {
throw new Error("Empty channel id provided");
}
const paymentChannel = await nitroClient?.GetPaymentChannel(channelId);
setPaymentChannelInfo(paymentChannel);
};

const triggerFileDownload = (file: File) => {
// This will prompt the browser to download the file
const blob = new Blob([file], { type: file.type });
Expand All @@ -149,15 +141,15 @@ export default function App() {
// await nitroClient.WaitForObjective(result.Id);

setPaymentChannelId(result.ChannelId);
updateChannelInfo(result.ChannelId);
console.timeEnd("Create Payment Channel");

// TODO: Slightly hacky but we wait a beat before querying so we see the updated balance
setTimeout(() => {
updateChannelInfo(result.ChannelId);
}, 1000);
};
// nitroClient.PaymentChannelUpdated(result.ChannelId, setPaymentChannelInfo);
// const paymentChannel = await nitroClient?.GetPaymentChannel(
// result.ChannelId
// );
// setPaymentChannelInfo(paymentChannel);

console.timeEnd("Create Payment Channel");
};
const fetchAndDownloadFile = async () => {
setErrorText("");
setFetchInProgress(true);
Expand All @@ -182,25 +174,17 @@ export default function App() {
nitroClient,
(progress) => {
setDownloadProgress(progress);
updateChannelInfo(paymentChannelInfo.ID);
}
)
: await fetchFile(
selectedFile.url,
skipPayment ? 0 : costPerByte * selectedFile.size,
paymentChannelInfo.ID,
nitroClient,
() => {
updateChannelInfo(paymentChannelInfo.ID);
}
() => {}
);
setDownloadProgress(100);
triggerFileDownload(file);

// TODO: Slightly hacky but we wait a beat before querying so we see the updated balance
setTimeout(() => {
updateChannelInfo(paymentChannelInfo.ID);
}, 50);
} catch (e: unknown) {
console.error(e);

Expand Down

0 comments on commit 44cb3d0

Please sign in to comment.