-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathOptimisticTransactionsProvider.tsx
60 lines (53 loc) · 1.66 KB
/
OptimisticTransactionsProvider.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {
LensTransactionStatusType,
useLensTransactionStatusQuery
} from "@hey/lens";
import { OptmisticPublicationType } from "@hey/types/enums";
import type { OptimisticTransaction } from "@hey/types/misc";
import type { FC } from "react";
import { useTransactionStore } from "src/store/persisted/useTransactionStore";
const Transaction: FC<{ transaction: OptimisticTransaction }> = ({
transaction
}) => {
const { removeTransaction, setIndexedPostHash } = useTransactionStore();
useLensTransactionStatusQuery({
fetchPolicy: "no-cache",
notifyOnNetworkStatusChange: true,
onCompleted: ({ lensTransactionStatus }) => {
if (
lensTransactionStatus?.status === LensTransactionStatusType.Failed ||
lensTransactionStatus?.status === LensTransactionStatusType.Complete
) {
// Trigger Profile feed refetch
if (
transaction.type === OptmisticPublicationType.Post &&
lensTransactionStatus.txHash
) {
setIndexedPostHash(lensTransactionStatus.txHash);
}
return removeTransaction(
(transaction.txId || transaction.txHash) as string
);
}
},
pollInterval: 3000,
variables: {
request: {
...(transaction.txId && { forTxId: transaction.txId }),
...(transaction.txHash && { forTxHash: transaction.txHash })
}
}
});
return null;
};
const OptimisticTransactionsProvider: FC = () => {
const { txnQueue } = useTransactionStore();
return (
<>
{txnQueue.map((txn) => (
<Transaction key={txn.txId || txn.txHash} transaction={txn} />
))}
</>
);
};
export default OptimisticTransactionsProvider;