Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustments after implementing mrl package in dapp #401

Merged
merged 8 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions packages/mrl/src/getTransferData/getTransferData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export async function getTransferData({
amount,
isAutomatic,
{ evmSigner, polkadotSigner }: Partial<Signers>,
statusCallback,
): Promise<string[]> {
const source = route.source.chain;

Expand Down Expand Up @@ -155,6 +156,7 @@ export async function getTransferData({
sourceAddress,
transfer,
polkadotSigner,
statusCallback,
);

return [hash];
Expand Down
3 changes: 2 additions & 1 deletion packages/mrl/src/mrl.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
} from '@moonbeam-network/xcm-sdk';
import type { AnyChain, AssetAmount } from '@moonbeam-network/xcm-types';
import type { Signer } from '@polkadot/api/types';
import type { IKeyringPair } from '@polkadot/types/types';
import type { IKeyringPair, ISubmittableResult } from '@polkadot/types/types';
import type { TokenTransfer } from '@wormhole-foundation/sdk-connect';
import type { WalletClient } from 'viem';

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

Expand Down
37 changes: 28 additions & 9 deletions packages/sdk/src/services/polkadot/PolkadotService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,37 @@ export class PolkadotService {
account: string,
config: ExtrinsicConfig,
signer: PolkadotSigner | IKeyringPair,
statusCallback?: (params: ISubmittableResult) => void,
): Promise<string> {
const extrinsic = this.getExtrinsic(config);
const hash = await extrinsic.signAndSend(
this.#isSigner(signer) ? account : signer,
{
nonce: -1,
signer: this.#isSigner(signer) ? signer : undefined,
withSignedTransaction: true,
},
);

return hash.toString();
const hash = await new Promise<string>((resolve, reject) => {
Rihyx marked this conversation as resolved.
Show resolved Hide resolved
extrinsic
.signAndSend(
this.#isSigner(signer) ? account : signer,
{
nonce: -1,
signer: this.#isSigner(signer) ? signer : undefined,
withSignedTransaction: true,
},
(result) => {
if (result.isError || result.dispatchError) {
reject(
new Error(
result.dispatchError?.toString() || 'Transaction failed',
),
);
}
if (result.txHash) {
resolve(result.txHash.toString());
}
statusCallback?.(result);
},
)
.catch(reject);
});

return hash;
}

#isSigner(signer: PolkadotSigner | IKeyringPair): signer is PolkadotSigner {
Expand Down