Skip to content
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
3 changes: 1 addition & 2 deletions packages/create/src/components/AppBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState, useEffect } from "react";
import { useState, useEffect } from "react";
import { NavLink, useLocation } from "react-router-dom";
import { RLogo } from "request-ui";
import { Link, Hidden } from "@material-ui/core";

import {
AppBar,
Expand Down
2 changes: 1 addition & 1 deletion packages/create/src/containers/CreatePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FormikHelpers } from "formik";
import React, { useState } from "react";
import { useState } from "react";
import { useHistory } from "react-router";
import { isCancelError, useCreateRequest } from "request-shared";
import { useErrorReporter } from "request-ui";
Expand Down
10 changes: 9 additions & 1 deletion packages/create/src/containers/RequestPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import { useEffect, useState } from "react";
import { makeStyles, Typography } from "@material-ui/core";
import { useWeb3React } from "@web3-react/core";
import {
Expand Down Expand Up @@ -84,10 +84,18 @@ const RequestPageInner = () => {
request,
loading,
update,
setOnConfirmation,
counterCurrency,
counterValue,
} = useRequest();

useEffect(() => {
if (request?.status === 'waiting') {
setOnConfirmation(update);
}
// eslint-disable-next-line
}, [request]); // not including update and setOnConfirmation here because they won't change

const cancel = async () => {
if (!request || !account || !chainId) {
throw new Error("cannot cancel because page is not ready");
Expand Down
3 changes: 2 additions & 1 deletion packages/pay/src/containers/DemoPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ const DemoPage = () => {
counterValue: "1.00",
request,
loading: !request,
setPending: () => {},
setOnConfirmation: () => { },
setPending: () => { },
update: () => Promise.resolve(),
}}
>
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/src/contexts/RequestContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface IContext {
counterCurrency: CurrencyDefinition;
/** the request's expected amount in counter currency */
counterValue?: string;
setOnConfirmation: (onConfirmation: () => void) => void;
/**
* set the pending status for UX purposes
* Pending means the payment is being processed and takes a long time.
Expand Down Expand Up @@ -72,6 +73,7 @@ export const RequestProvider: React.FC<{ chainId?: string | number }> = ({
const counterCurrency = currencyManager.from("USD")!;
const [counterValue, setCounterValue] = useState<string>("");
const [pending, setPending] = useState(false);
const [onConfirmation, setOnConfirmation] = useState<() => void>();

// gets counter currency rate
const rate = useRate(parsedRequest?.currency, counterCurrency);
Expand Down Expand Up @@ -100,6 +102,9 @@ export const RequestProvider: React.FC<{ chainId?: string | number }> = ({
});
parseResult.loaded = true;
setParsedRequest(parseResult);
if (onConfirmation) {
result.request.waitForConfirmation().then(onConfirmation);
}
}
};

Expand All @@ -125,6 +130,7 @@ export const RequestProvider: React.FC<{ chainId?: string | number }> = ({
counterCurrency,
counterValue,
setPending,
setOnConfirmation,
update: useCallback(
() => fetchRequest(id, chainId, pending),
[id, chainId, pending]
Expand Down