Skip to content

Commit

Permalink
instantiate
Browse files Browse the repository at this point in the history
  • Loading branch information
niklabh authored and github-actions[bot] committed Mar 27, 2023
1 parent 97bed3f commit df88f56
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
49 changes: 34 additions & 15 deletions packages/page-contracts/src/Codes/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,42 @@ function Upload ({ onClose }: Props): React.ReactElement {
}, [abiName, setName]);

useEffect((): void => {
let contract: SubmittableExtrinsic<'promise'> | null = null;
let error: string | null = null;

try {
contract = code && contractAbi?.constructors[constructorIndex]?.method && value
? code.tx[contractAbi.constructors[constructorIndex].method]({
gasLimit: weight.isWeightV2 ? weight.weightV2 : weight.weight,
storageDepositLimit: null,
value: contractAbi?.constructors[constructorIndex].isPayable ? value : undefined
}, ...params)
: null;
} catch (e) {
error = (e as Error).message;
async function dryRun () {
let contract: SubmittableExtrinsic<'promise'> | null = null;
let error: string | null = null;

try {
if (code && contractAbi?.constructors[constructorIndex]?.method && value && accountId) {
const dryRunParams: Parameters<typeof api.call.contractsApi.instantiate> =
[
accountId,
contractAbi?.constructors[constructorIndex].isPayable
? api.registry.createType('Balance', value)
: api.registry.createType('Balance', BN_ZERO),
weight.weightV2,
null,
{ Upload: wasm },
contractAbi?.constructors[constructorIndex]?.toU8a(params),
''
];

const dryRunResult = await api.call.contractsApi.instantiate(...dryRunParams);

contract = code.tx[contractAbi.constructors[constructorIndex].method]({
gasLimit: dryRunResult.gasRequired,
storageDepositLimit: dryRunResult.storageDeposit.isCharge ? dryRunResult.storageDeposit.asCharge : null,
value: contractAbi?.constructors[constructorIndex].isPayable ? value : undefined
}, ...params);
}
} catch (e) {
error = (e as Error).message;
}

setUploadTx(() => [contract, error]);
}

setUploadTx(() => [contract, error]);
}, [code, contractAbi, constructorIndex, value, params, weight]);
dryRun().catch((e) => console.error(e));
}, [accountId, wasm, api, code, contractAbi, constructorIndex, value, params, weight]);

const _onAddWasm = useCallback(
(wasm: Uint8Array, name: string): void => {
Expand Down
2 changes: 0 additions & 2 deletions packages/page-contracts/src/shared/InputMegaGas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ interface Props {
className?: string;
estimatedWeight?: BN | null;
estimatedWeightV2?: WeightV2 | null;
help: React.ReactNode;
isCall?: boolean;
weight: UseWeight;
}

function InputMegaGas ({ className,
estimatedWeight,
estimatedWeightV2,
help,
isCall,
weight: { executionTime,
isValid,
Expand Down

0 comments on commit df88f56

Please sign in to comment.