Skip to content

Commit 382bd5d

Browse files
committed
feat: add support for 'InBlock' transaction status handling
1 parent 4b42deb commit 382bd5d

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/components/NotificationToasts/TransactionToast/styles.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import styled from 'styled-components';
21
import { TransactionStatus } from '@polymeshassociation/polymesh-sdk/types';
2+
import styled from 'styled-components';
33

44
export const StyledInfoWrapper = styled.div`
55
display: flex;
@@ -22,6 +22,12 @@ const handleStatusType = (status: `${TransactionStatus}`) => {
2222
color: #ffffff;
2323
`;
2424

25+
case TransactionStatus.InBlock:
26+
return `
27+
background-color: #FFF4D6;
28+
color: #B7791F;
29+
`;
30+
2531
case TransactionStatus.Succeeded:
2632
return `
2733
background-color: #D4F7E7;

src/context/TransactionStatusContext/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
// Shared transaction option types
88
export interface BaseTransactionOptions {
99
onTransactionRunning?: () => void | Promise<void>;
10+
onInBlock?: () => void | Promise<void>;
1011
onProcessedByMiddleware?: () => void | Promise<void>;
1112
onError?: (error: Error) => void | Promise<void>;
1213
/**

src/context/TransactionStatusContext/provider.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ const TransactionStatusProvider = ({
103103
| (() => void | Promise<void>),
104104
onError?: (error: Error) => void | Promise<void>,
105105
onTransactionRunning?: () => void | Promise<void>,
106+
onInBlock?: () => void | Promise<void>,
106107
middlewareCleanup?: {
107108
middlewareUnsubscribe?: () => void;
108109
middlewarePromise?: Promise<void>;
@@ -121,6 +122,12 @@ const TransactionStatusProvider = ({
121122
}
122123
break;
123124

125+
case TransactionStatus.InBlock:
126+
if (onInBlock) {
127+
onInBlock();
128+
}
129+
break;
130+
124131
case TransactionStatus.Succeeded:
125132
if (onSuccess) {
126133
if (isProposal) {
@@ -187,6 +194,7 @@ const TransactionStatusProvider = ({
187194
): Promise<ReturnValue | MultiSigProposal> {
188195
const {
189196
onTransactionRunning,
197+
onInBlock,
190198
onProcessedByMiddleware,
191199
onSuccess,
192200
onError,
@@ -226,6 +234,7 @@ const TransactionStatusProvider = ({
226234
onSuccess,
227235
onError,
228236
onTransactionRunning,
237+
onInBlock,
229238
{ middlewareUnsubscribe, middlewarePromise },
230239
isProposal,
231240
);
@@ -271,6 +280,7 @@ const TransactionStatusProvider = ({
271280
): Promise<ReturnValue[] | MultiSigProposal> {
272281
const {
273282
onTransactionRunning,
283+
onInBlock,
274284
onProcessedByMiddleware,
275285
onSuccess,
276286
onError,
@@ -319,6 +329,7 @@ const TransactionStatusProvider = ({
319329
onSuccess,
320330
onError,
321331
onTransactionRunning,
332+
onInBlock,
322333
{ middlewareUnsubscribe, middlewarePromise },
323334
isProposal,
324335
);

src/hooks/polymesh/useTransactionStatus.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { PolymeshTransactionBatch } from '@polymeshassociation/polymesh-sdk/internal';
12
import {
23
GenericPolymeshTransaction,
34
TransactionStatus,
45
TxTag,
56
} from '@polymeshassociation/polymesh-sdk/types';
6-
import { PolymeshTransactionBatch } from '@polymeshassociation/polymesh-sdk/internal';
77
import { Id, toast } from 'react-toastify';
88
import { TransactionToast } from '~/components/NotificationToasts';
99

@@ -64,6 +64,27 @@ const useTransactionStatus = () => {
6464
containerId: 'notification-center',
6565
});
6666
break;
67+
68+
case TransactionStatus.InBlock:
69+
toast.update(toastId, {
70+
render: (
71+
<TransactionToast
72+
txHash={transaction.txHash}
73+
status={transaction.status}
74+
tag={tag}
75+
isTxBatch={isTxBatch}
76+
batchSize={isTxBatch ? transaction.transactions.length : 0}
77+
timestamp={Date.now()}
78+
/>
79+
),
80+
type: 'info',
81+
isLoading: false,
82+
autoClose: false,
83+
closeOnClick: false,
84+
containerId: 'notification-center',
85+
});
86+
break;
87+
6788
case TransactionStatus.Succeeded:
6889
toast.update(toastId, {
6990
render: (

0 commit comments

Comments
 (0)