Skip to content

Commit 01c84c5

Browse files
committed
fixes in getMoonChainData
1 parent 870da01 commit 01c84c5

File tree

4 files changed

+32
-44
lines changed

4 files changed

+32
-44
lines changed

packages/mrl/src/getTransferData/getMoonChainData.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@ import { type MrlAssetRoute, getMoonChain } from '@moonbeam-network/xcm-config';
22
import { getBalance, getDestinationFee } from '@moonbeam-network/xcm-sdk';
33
import { Parachain } from '@moonbeam-network/xcm-types';
44
import { getMultilocationDerivedAddresses } from '@moonbeam-network/xcm-utils';
5-
import type {
6-
DestinationTransferData,
7-
MoonChainTransferData,
8-
} from '../mrl.interfaces';
5+
import type { MoonChainTransferData } from '../mrl.interfaces';
96

107
interface GetMoonChainDataParams {
11-
destinationData: DestinationTransferData;
128
route: MrlAssetRoute;
139
sourceAddress: string;
1410
}
1511

1612
export async function getMoonChainData({
17-
destinationData,
1813
route,
1914
sourceAddress,
2015
}: GetMoonChainDataParams): Promise<MoonChainTransferData> {
@@ -25,18 +20,6 @@ export async function getMoonChainData({
2520
}
2621

2722
const moonChain = getMoonChain(route.source.chain);
28-
// TODO is this used for something? do we need the balance?
29-
// const asset = moonChain.getChainAsset(route.mrl.moonChain.asset);
30-
// const isDestinationMoonChain = route.destination.chain.isEqual(moonChain);
31-
32-
// TODO technically not correct
33-
// if (isDestinationMoonChain) {
34-
// return {
35-
// balance: destinationData.balance,
36-
// chain: destinationData.chain,
37-
// fee: destinationData.fee,
38-
// };
39-
// }
4023

4124
const fee = await getDestinationFee({
4225
address: sourceAddress, // TODO not correct
@@ -48,7 +31,10 @@ export async function getMoonChainData({
4831

4932
let address = sourceAddress;
5033

51-
if (Parachain.is(route.source.chain)) {
34+
if (
35+
Parachain.is(route.source.chain) &&
36+
!route.source.chain.isEqual(moonChain)
37+
) {
5238
const { address20 } = getMultilocationDerivedAddresses({
5339
address: sourceAddress,
5440
paraId: route.source.chain.parachainId,
@@ -66,8 +52,7 @@ export async function getMoonChainData({
6652
});
6753

6854
return {
69-
// TODO technically feeBalance
70-
balance: feeBalance,
55+
feeBalance,
7156
chain: moonChain,
7257
fee,
7358
};

packages/mrl/src/getTransferData/getTransferData.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export async function getTransferData({
6767
});
6868

6969
const moonChainData = await getMoonChainData({
70-
destinationData,
7170
route,
7271
sourceAddress,
7372
});

packages/mrl/src/mrl.interfaces.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ export interface SourceTransferData extends SourceChainTransferData {
3838

3939
export interface DestinationTransferData extends ChainTransferData {}
4040

41-
export type MoonChainTransferData = Omit<ChainTransferData, 'min'>;
41+
export type MoonChainTransferData = Omit<
42+
ChainTransferData,
43+
'min' | 'balance'
44+
> & {
45+
feeBalance: AssetAmount;
46+
};
4247

4348
export interface ChainTransferData {
4449
chain: AnyChain;

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

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,28 @@ export class PolkadotService {
9494
): Promise<string> {
9595
const extrinsic = this.getExtrinsic(config);
9696

97+
const isSigner = this.#isSigner(signer);
98+
const signOptions = {
99+
nonce: -1,
100+
signer: isSigner ? signer : undefined,
101+
withSignedTransaction: true,
102+
};
103+
97104
const hash = await new Promise<string>((resolve, reject) => {
98105
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-
)
106+
.signAndSend(isSigner ? account : signer, signOptions, (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+
})
120119
.catch(reject);
121120
});
122121

0 commit comments

Comments
 (0)