Skip to content

Commit

Permalink
fix: proofsize field is missing (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
WoeOm authored Jun 20, 2023
1 parent 41252fc commit db1f22c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/components/ExtrinsicLaunch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ export function ExtrinsicLaunch({ className, onTxSuccess }: Props): React.ReactE
const args =
// eslint-disable-next-line no-magic-numbers
argsLength === 5
? [...generalParams, ext.method.toHex(), weightAll.compatibleWeight]
? [...generalParams, ext.method.toHex(), weightAll]
: argsLength === ARG_LENGTH
? [...generalParams, ext.method.toHex(), false, weightAll.compatibleWeight]
? [...generalParams, ext.method.toHex(), false, weightAll]
: [...generalParams, ext];
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions src/components/modals/Transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ function Transfer({
const args =
// eslint-disable-next-line no-magic-numbers
argsLength === 5
? [...generalParams, ext.method.toHex(), weightAll.compatibleWeight]
? [...generalParams, ext.method.toHex(), weightAll]
: argsLength === ARG_LENGTH
? [...generalParams, ext.method.toHex(), false, weightAll.compatibleWeight]
? [...generalParams, ext.method.toHex(), false, weightAll]
: [...generalParams, ext];
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/multiApprove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export function useMultiApprove() {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const info = await api?.query.multisig.multisigs(multiRoot, data.callHash!);
let callData = null;
let weight: CompatibleWeight = convertWeight(api, 0).compatibleWeight;
let weight: CompatibleWeight = convertWeight(api, 0);

if (data.callData && api) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const payment = await api?.tx(data.callData as any).paymentInfo(ZERO_ACCOUNT);
weight = convertWeight(api, payment?.weight || 0).compatibleWeight;
weight = convertWeight(api, payment?.weight || 0);
callData = api?.registry.createType('Call', data.callData);
}

Expand Down
11 changes: 2 additions & 9 deletions src/packages/react-signer/src/TxSigned.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,12 @@ async function wrapTx(
tx = isMultiCall
? api.tx[multiModule].asMulti.meta.args.length === 6
? // We are doing toHex here since we have a Vec<u8> input
api.tx[multiModule].asMulti(
threshold,
others,
timepoint,
tx.method.toHex(),
false,
weightAll.compatibleWeight
)
api.tx[multiModule].asMulti(threshold, others, timepoint, tx.method.toHex(), false, weightAll)
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
api.tx[multiModule].asMulti(threshold, others, timepoint, tx.method)
: api.tx[multiModule].approveAsMulti.meta.args.length === 5
? api.tx[multiModule].approveAsMulti(threshold, others, timepoint, tx.method.hash, weightAll.compatibleWeight)
? api.tx[multiModule].approveAsMulti(threshold, others, timepoint, tx.method.hash, weightAll)
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
api.tx[multiModule].approveAsMulti(threshold, others, timepoint, tx.method.hash);
Expand Down
22 changes: 3 additions & 19 deletions src/utils/helper/weight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,20 @@ export interface WeightV2 extends Struct {
readonly proofSize: Compact<u64>;
}

export type CompatibleWeight =
| BN
| {
refTime: BN;
};
export interface WeightAll {
v1Weight: BN;
v2Weight: {
refTime: BN;
};
compatibleWeight: CompatibleWeight;
}
export type CompatibleWeight = BN | WeightV2;

export function convertWeight(
api: ApiPromise | null,
orig: WeightV1 | WeightV2 | bigint | string | number | BN
): WeightAll {
): CompatibleWeight {
let isWeightV2 = false;
try {
api?.createType('WeightV2', { refTime: 0 });
isWeightV2 = true;
} catch (error) {
isWeightV2 = false;
}

const refTime = (orig as WeightV2).proofSize ? (orig as WeightV2).refTime.toBn() : bnToBn(orig as BN);

return {
v1Weight: refTime,
v2Weight: { refTime },
compatibleWeight: isWeightV2 ? { refTime } : refTime,
};
return isWeightV2 ? (orig as WeightV2) : refTime;
}

0 comments on commit db1f22c

Please sign in to comment.