Skip to content

Commit 870da01

Browse files
committed
add statusCallback param
1 parent 599a0fb commit 870da01

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

packages/mrl/src/getTransferData/getTransferData.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export async function getTransferData({
108108
amount,
109109
isAutomatic,
110110
{ evmSigner, polkadotSigner }: Partial<Signers>,
111+
statusCallback,
111112
): Promise<string[]> {
112113
const source = route.source.chain;
113114

@@ -155,6 +156,7 @@ export async function getTransferData({
155156
sourceAddress,
156157
transfer,
157158
polkadotSigner,
159+
statusCallback,
158160
);
159161

160162
return [hash];

packages/mrl/src/mrl.interfaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
} from '@moonbeam-network/xcm-sdk';
55
import type { AnyChain, AssetAmount } from '@moonbeam-network/xcm-types';
66
import type { Signer } from '@polkadot/api/types';
7-
import type { IKeyringPair } from '@polkadot/types/types';
7+
import type { IKeyringPair, ISubmittableResult } from '@polkadot/types/types';
88
import type { TokenTransfer } from '@wormhole-foundation/sdk-connect';
99
import type { WalletClient } from 'viem';
1010

@@ -24,6 +24,7 @@ export interface TransferData {
2424
amount: bigint | number | string,
2525
isAutomatic: boolean,
2626
signers: Signers,
27+
statusCallback?: (params: ISubmittableResult) => void,
2728
): Promise<string[]>;
2829
}
2930

packages/sdk/src/services/polkadot/PolkadotService.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,37 @@ export class PolkadotService {
9090
account: string,
9191
config: ExtrinsicConfig,
9292
signer: PolkadotSigner | IKeyringPair,
93+
statusCallback?: (params: ISubmittableResult) => void,
9394
): Promise<string> {
9495
const extrinsic = this.getExtrinsic(config);
95-
const hash = await extrinsic.signAndSend(
96-
this.#isSigner(signer) ? account : signer,
97-
{
98-
nonce: -1,
99-
signer: this.#isSigner(signer) ? signer : undefined,
100-
withSignedTransaction: true,
101-
},
102-
);
10396

104-
return hash.toString();
97+
const hash = await new Promise<string>((resolve, reject) => {
98+
extrinsic
99+
.signAndSend(
100+
this.#isSigner(signer) ? account : signer,
101+
{
102+
nonce: -1,
103+
signer: this.#isSigner(signer) ? signer : undefined,
104+
withSignedTransaction: true,
105+
},
106+
(result) => {
107+
if (result.isError || result.dispatchError) {
108+
reject(
109+
new Error(
110+
result.dispatchError?.toString() || 'Transaction failed',
111+
),
112+
);
113+
}
114+
if (result.txHash) {
115+
resolve(result.txHash.toString());
116+
}
117+
statusCallback?.(result);
118+
},
119+
)
120+
.catch(reject);
121+
});
122+
123+
return hash;
105124
}
106125

107126
#isSigner(signer: PolkadotSigner | IKeyringPair): signer is PolkadotSigner {

0 commit comments

Comments
 (0)