Skip to content

Commit f9bb777

Browse files
authored
feat: update polkadot.js deps (#567)
1 parent 1b130e1 commit f9bb777

File tree

4 files changed

+412
-351
lines changed

4 files changed

+412
-351
lines changed

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
"dependencies": {
3434
"@headlessui/react": "^1.7.18",
3535
"@heroicons/react": "^1.0.6",
36-
"@polkadot/api": "12.4.2",
37-
"@polkadot/api-contract": "12.4.2",
38-
"@polkadot/extension-dapp": "^0.52.3",
39-
"@polkadot/ui-keyring": "^3.9.1",
40-
"@polkadot/ui-shared": "^3.9.1",
36+
"@polkadot/api": "15.8.1",
37+
"@polkadot/api-contract": "15.8.1",
38+
"@polkadot/extension-dapp": "^0.58.6",
39+
"@polkadot/ui-keyring": "^3.12.2",
40+
"@polkadot/ui-shared": "^3.12.2",
4141
"big.js": "^6.2.1",
4242
"buffer": "^6.0.3",
4343
"copy-to-clipboard": "^3.3.3",

src/ui/components/contract/Interact.tsx

+25-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
SubmittableResult,
2222
UIContract,
2323
} from 'types';
24+
import { Text } from '@polkadot/types';
2425
import { AccountSelect } from 'ui/components/account';
2526
import { Button, Buttons, Dropdown } from 'ui/components/common';
2627
import { ArgumentForm, Form, FormField, OptionsForm } from 'ui/components/form';
@@ -100,8 +101,30 @@ export const InteractTab = ({
100101
useEffect((): void => {
101102
async function dryRun() {
102103
if (!message) return;
103-
const o = await api.call.contractsApi.call(...params);
104-
setOutcome(o);
104+
const newOutcome = await api.call.contractsApi.call(...params);
105+
106+
// auto-generated @polkadot/type-augment data uses a different flag representation: `{"ok":{"flags":{"bits":0},"data":"0x00"}}`
107+
let convertedFlags = api.registry.createType('ContractReturnFlags', 0);
108+
if (newOutcome.result.isOk) {
109+
const flags = newOutcome.result.asOk.flags;
110+
const isRevert = flags.bits.toNumber();
111+
convertedFlags = api.registry.createType('ContractReturnFlags', isRevert);
112+
}
113+
114+
const convertedOutcome: ContractExecResult = api.registry.createType('ContractExecResult', {
115+
registry: api.registry,
116+
gasConsumed: newOutcome.gasConsumed,
117+
gasRequired: newOutcome.gasRequired,
118+
storageDeposit: newOutcome.storageDeposit,
119+
// debugMessage is Bytes, must convert to Text
120+
debugMessage: new Text(api.registry, newOutcome.debugMessage.toUtf8()),
121+
result: newOutcome.result.isOk
122+
? { Ok: { flags: convertedFlags, data: newOutcome.result.asOk.data } }
123+
: { Err: newOutcome.result.asErr },
124+
});
125+
126+
// Update the state with the adapted outcome
127+
setOutcome(convertedOutcome);
105128
}
106129

107130
function debouncedDryRun() {

src/ui/components/instantiate/Step2.tsx

+33-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,39 @@ export function Step2() {
9898
try {
9999
const result = await api.call.contractsApi.instantiate(...params);
100100

101-
if (JSON.stringify(dryRunResult) !== JSON.stringify(result)) {
102-
setDryRunResult(result);
101+
// default is no revert
102+
let convertedFlags = api.registry.createType('ContractReturnFlags', 0);
103+
let instantiateResult;
104+
105+
// auto-generated @polkadot/type-augment data uses slightly different types
106+
if (result.result.isOk) {
107+
const okResult = result.result.asOk;
108+
const flags = okResult.result.flags;
109+
const isRevert = flags.bits.toNumber();
110+
convertedFlags = api.registry.createType('ContractReturnFlags', isRevert);
111+
instantiateResult = {
112+
Ok: {
113+
result: { flags: convertedFlags, data: okResult.result.data },
114+
accountId: okResult.accountId,
115+
},
116+
};
117+
} else {
118+
instantiateResult = { Err: result.result.asErr };
119+
}
120+
121+
const convertedOutcome = api.registry.createType('ContractInstantiateResult', {
122+
gasConsumed: result.gasConsumed,
123+
gasRequired: result.gasRequired,
124+
storageDeposit: result.storageDeposit,
125+
// debugMessage is Bytes, must convert to Text
126+
debugMessage: api.registry.createType('Text', result.debugMessage.toU8a()),
127+
result: instantiateResult,
128+
});
129+
130+
const resultJson = JSON.stringify(convertedOutcome.toJSON());
131+
const dryRunResultJson = JSON.stringify(dryRunResult?.toJSON());
132+
if (dryRunResultJson !== resultJson) {
133+
setDryRunResult(convertedOutcome);
103134
}
104135
} catch (e) {
105136
console.error(e);

0 commit comments

Comments
 (0)