File tree Expand file tree Collapse file tree 3 files changed +32
-10
lines changed
sdk/src/services/polkadot Expand file tree Collapse file tree 3 files changed +32
-10
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ export async function getTransferData({
108
108
amount ,
109
109
isAutomatic ,
110
110
{ evmSigner, polkadotSigner } : Partial < Signers > ,
111
+ statusCallback ,
111
112
) : Promise < string [ ] > {
112
113
const source = route . source . chain ;
113
114
@@ -155,6 +156,7 @@ export async function getTransferData({
155
156
sourceAddress ,
156
157
transfer ,
157
158
polkadotSigner ,
159
+ statusCallback ,
158
160
) ;
159
161
160
162
return [ hash ] ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import type {
4
4
} from '@moonbeam-network/xcm-sdk' ;
5
5
import type { AnyChain , AssetAmount } from '@moonbeam-network/xcm-types' ;
6
6
import type { Signer } from '@polkadot/api/types' ;
7
- import type { IKeyringPair } from '@polkadot/types/types' ;
7
+ import type { IKeyringPair , ISubmittableResult } from '@polkadot/types/types' ;
8
8
import type { TokenTransfer } from '@wormhole-foundation/sdk-connect' ;
9
9
import type { WalletClient } from 'viem' ;
10
10
@@ -24,6 +24,7 @@ export interface TransferData {
24
24
amount : bigint | number | string ,
25
25
isAutomatic : boolean ,
26
26
signers : Signers ,
27
+ statusCallback ?: ( params : ISubmittableResult ) => void ,
27
28
) : Promise < string [ ] > ;
28
29
}
29
30
Original file line number Diff line number Diff line change @@ -90,18 +90,37 @@ export class PolkadotService {
90
90
account : string ,
91
91
config : ExtrinsicConfig ,
92
92
signer : PolkadotSigner | IKeyringPair ,
93
+ statusCallback ?: ( params : ISubmittableResult ) => void ,
93
94
) : Promise < string > {
94
95
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
- ) ;
103
96
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 ;
105
124
}
106
125
107
126
#isSigner( signer : PolkadotSigner | IKeyringPair ) : signer is PolkadotSigner {
You can’t perform that action at this time.
0 commit comments