Skip to content

Commit 33ff067

Browse files
Upgrade sdk-core to v.14 and sdk-dapp to v.4 (#331)
* Upgrade sdk-core to v.14 and sdk-dapp to v.4
1 parent 7cedf49 commit 33ff067

File tree

20 files changed

+589
-791
lines changed

20 files changed

+589
-791
lines changed

jest.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ module.exports = {
1212
'^.+\\.(ts|js|tsx|jsx)$': '@swc/jest'
1313
},
1414
transformIgnorePatterns: [
15-
'node_modules/(?!@multiversx/sdk-guardians-provider|@multiversx/sdk-dapp-form|@multiversx/sdk-dapp-nft|@multiversx/sdk-dapp|@multiversx/sdk-wallet-connect-provider|@multiversx/sdk-guardians-provider|@multiversx/sdk-wallet|react-redux|swiper|ssr-window|dom7|axios|react-tooltip|uuid|uint8arrays|multiformats|@lifeomic/axios-fetch|@walletconnect)'
15+
'node_modules/(?!(@multiversx/sdk-.*|@noble/ed25519|react-redux|swiper|ssr-window|dom7|axios|react-tooltip|uuid|uint8arrays|multiformats|@lifeomic/axios-fetch|@walletconnect)/)'
1616
],
1717
moduleNameMapper: {
1818
'^react-native$': 'react-native-web',
19-
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy'
19+
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
20+
'^@multiversx/sdk-(.*)$': '@multiversx/sdk-$1'
2021
},
2122
setupFilesAfterEnv: ['./src/setupTests.ts'],
2223
moduleFileExtensions: [

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"@fortawesome/fontawesome-svg-core": "6.5.1",
1010
"@fortawesome/free-solid-svg-icons": "6.5.1",
1111
"@fortawesome/react-fontawesome": "0.2.0",
12-
"@multiversx/sdk-core": "13.16.0",
13-
"@multiversx/sdk-dapp": "3.1.6",
12+
"@multiversx/sdk-core": "^14.x",
13+
"@multiversx/sdk-dapp": "^4.x",
1414
"axios": "1.7.4",
1515
"classnames": "2.3.2",
1616
"moment": "2.29.4",

src/hooks/transactions/useSendPingPongTransaction.ts

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
import {
2+
AbiRegistry,
3+
SmartContractTransactionsFactory,
4+
TransactionsFactoryConfig
5+
} from '@multiversx/sdk-core/out';
16
import { useCallback, useState } from 'react';
27
import { contractAddress } from 'config';
8+
import pingPongAbi from 'contracts/ping-pong.abi.json';
39
import { signAndSendTransactions } from 'helpers/signAndSendTransactions';
410
import {
511
Address,
@@ -19,8 +25,6 @@ import {
1925
PingRawProps,
2026
PongRawProps
2127
} from 'types/pingPong.types';
22-
import { getChainId } from 'utils/getChainId';
23-
import { smartContract } from 'utils/smartContract';
2428

2529
type PingPongTransactionProps = {
2630
type: SessionEnum;
@@ -89,17 +93,32 @@ export const useSendPingPongTransaction = ({
8993
[]
9094
);
9195

96+
const getSmartContractFactory = async () => {
97+
const abi = AbiRegistry.create(pingPongAbi);
98+
const scFactory = new SmartContractTransactionsFactory({
99+
config: new TransactionsFactoryConfig({
100+
chainID: network.chainId
101+
}),
102+
abi
103+
});
104+
105+
return scFactory;
106+
};
107+
92108
const sendPingTransactionFromAbi = useCallback(
93109
async ({ amount, callbackRoute }: PingRawProps) => {
94110
clearAllTransactions();
95111

96-
const pingTransaction = smartContract.methodsExplicit
97-
.ping()
98-
.withSender(new Address(address))
99-
.withValue(amount ?? '0')
100-
.withGasLimit(60000000)
101-
.withChainID(getChainId())
102-
.buildTransaction();
112+
const scFactory = await getSmartContractFactory();
113+
const pingTransaction = scFactory.createTransactionForExecute(
114+
new Address(address),
115+
{
116+
gasLimit: BigInt(60000000),
117+
function: 'ping',
118+
contract: new Address(contractAddress),
119+
nativeTransferAmount: BigInt(amount)
120+
}
121+
);
103122

104123
const sessionId = await signAndSendTransactions({
105124
transactions: [pingTransaction],
@@ -161,13 +180,16 @@ export const useSendPingPongTransaction = ({
161180
async ({ callbackRoute }: PongRawProps) => {
162181
clearAllTransactions();
163182

164-
const pongTransaction = smartContract.methodsExplicit
165-
.pong()
166-
.withSender(new Address(address))
167-
.withValue('0')
168-
.withGasLimit(60000000)
169-
.withChainID(getChainId())
170-
.buildTransaction();
183+
const scFactory = await getSmartContractFactory();
184+
const pongTransaction = scFactory.createTransactionForExecute(
185+
new Address(address),
186+
{
187+
gasLimit: BigInt(60000000),
188+
function: 'pong',
189+
contract: new Address(contractAddress),
190+
nativeTransferAmount: BigInt(0)
191+
}
192+
);
171193

172194
const sessionId = await signAndSendTransactions({
173195
transactions: [pongTransaction],

src/lib/sdkCore.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
export { AbiRegistry } from '@multiversx/sdk-core/out/smartcontracts/typesystem/abiRegistry';
2-
export { Address } from '@multiversx/sdk-core/out/address';
3-
export { AddressValue } from '@multiversx/sdk-core/out/smartcontracts/typesystem/address';
4-
export { ContractFunction } from '@multiversx/sdk-core/out/smartcontracts/function';
5-
export type { IPlainTransactionObject } from '@multiversx/sdk-core/out/interface';
6-
export { Message } from '@multiversx/sdk-core/out/message';
7-
export { ProxyNetworkProvider } from '@multiversx/sdk-core/out/networkProviders/proxyNetworkProvider';
8-
export { ResultsParser } from '@multiversx/sdk-core/out/smartcontracts/resultsParser';
9-
export { SmartContract } from '@multiversx/sdk-core/out/smartcontracts/smartContract';
10-
export { TokenTransfer } from '@multiversx/sdk-core/out/tokens';
11-
export { Transaction } from '@multiversx/sdk-core/out/transaction';
12-
export { WALLET_PROVIDER_SEND_TRANSACTION_URL } from '@multiversx/sdk-dapp/constants';
1+
export {
2+
AbiRegistry,
3+
Address,
4+
AddressValue,
5+
ContractFunction,
6+
Message,
7+
ProxyNetworkProvider,
8+
SmartContract,
9+
SmartContractController,
10+
TokenTransfer,
11+
Transaction
12+
} from '@multiversx/sdk-core';

src/lib/sdkDapp/sdkDapp.constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export {
33
EXTRA_GAS_LIMIT_GUARDED_TX,
44
GAS_LIMIT,
55
GAS_PRICE,
6-
VERSION
6+
VERSION,
7+
WALLET_PROVIDER_SEND_TRANSACTION_URL
78
} from '@multiversx/sdk-dapp/constants';
89
export { TRANSACTIONS_ENDPOINT } from '@multiversx/sdk-dapp/apiCalls/endpoints';

src/lib/sdkDapp/sdkDapp.helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ export {
44
removeAllSignedTransactions,
55
removeAllTransactionsToSign
66
} from '@multiversx/sdk-dapp/services/transactions/clearTransactions';
7-
export { formatAmount } from '@multiversx/sdk-dapp/utils/operations/formatAmount';
87
export { getInterpretedTransaction } from '@multiversx/sdk-dapp/utils/transactions/getInterpretedTransaction';
98
export { getIsProviderEqualTo } from '@multiversx/sdk-dapp/utils/account/getIsProviderEqualTo';
109
export { getTransactions } from '@multiversx/sdk-dapp/apiCalls/transactions/getTransactions';
1110
export { logout } from '@multiversx/sdk-dapp/utils/logout';
1211
export { newTransaction } from '@multiversx/sdk-dapp/models';
12+
export { parseAmount } from '@multiversx/sdk-dapp/utils/operations/parseAmount';
1313
export { refreshAccount } from '@multiversx/sdk-dapp/utils/account/refreshAccount';
1414
export { sendBatchTransactions } from '@multiversx/sdk-dapp/services/transactions/sendBatchTransactions';
1515
export { sendTransactions } from '@multiversx/sdk-dapp/services/transactions/sendTransactions';

src/lib/sdkDapp/sdkDapp.hooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export { useGetPendingTransactions } from '@multiversx/sdk-dapp/hooks/transactio
1313
export { useGetSignMessageInfoStatus } from '@multiversx/sdk-dapp/hooks/signMessage/useGetSignedMessageStatus';
1414
export { useGetSignMessageSession } from '@multiversx/sdk-dapp/hooks/signMessage/useGetSignMessageSession';
1515
export { useGetSignedTransactions } from '@multiversx/sdk-dapp/hooks/transactions/useGetSignedTransactions';
16+
export { useParseSignedTransactions } from '@multiversx/sdk-dapp/hooks/transactions/useParseSignedTransactions';
1617
export { useSendBatchTransactions } from '@multiversx/sdk-dapp/hooks/transactions/batch/useSendBatchTransactions';
1718
export { useSignMessage } from '@multiversx/sdk-dapp/hooks/signMessage/useSignMessage';
1819
export { useSignTransactions } from '@multiversx/sdk-dapp/hooks/transactions/useSignTransactions';

src/pages/Dashboard/Dashboard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ const WIDGETS: WidgetType[] = [
7474
widget: Transactions,
7575
description: 'List transactions for the connected account',
7676
reference:
77-
'https://api.elrond.com/#/accounts/AccountController_getAccountTransactions'
77+
'https://api.multiversx.com/#/accounts/AccountController_getAccountTransactions'
7878
},
7979
{
8080
title: 'Transactions (Ping & Pong)',
8181
widget: Transactions,
8282
props: { receiver: contractAddress },
8383
description: 'List transactions filtered for a given Smart Contract',
8484
reference:
85-
'https://api.elrond.com/#/accounts/AccountController_getAccountTransactions'
85+
'https://api.multiversx.com/#/accounts/AccountController_getAccountTransactions'
8686
}
8787
];
8888

src/pages/Dashboard/widgets/PingPongAbi/hooks/useGetPingAmount.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { useEffect, useState } from 'react';
2+
import { contractAddress } from 'config';
3+
import pingPongAbi from 'contracts/ping-pong.abi.json';
24
import {
3-
ContractFunction,
5+
AbiRegistry,
6+
Address,
47
ProxyNetworkProvider,
5-
ResultsParser,
8+
SmartContractController,
69
useGetNetworkConfig
710
} from 'lib';
8-
import { smartContract } from 'utils';
9-
10-
const resultsParser = new ResultsParser();
1111

1212
export const useGetPingAmount = () => {
1313
const { network } = useGetNetworkConfig();
@@ -17,19 +17,21 @@ export const useGetPingAmount = () => {
1717

1818
const getPingAmount = async () => {
1919
try {
20-
const query = smartContract.createQuery({
21-
func: new ContractFunction('getPingAmount')
22-
});
23-
const queryResponse = await proxy.queryContract(query);
20+
const abi = AbiRegistry.create(pingPongAbi);
2421

25-
const endpointDefinition = smartContract.getEndpoint('getPingAmount');
22+
const scController = new SmartContractController({
23+
chainID: network.chainId,
24+
networkProvider: proxy,
25+
abi
26+
});
2627

27-
const { firstValue: amount } = resultsParser.parseQueryResponse(
28-
queryResponse,
29-
endpointDefinition
30-
);
28+
const [result] = await scController.query({
29+
contract: Address.newFromBech32(contractAddress),
30+
function: 'getPingAmount',
31+
arguments: []
32+
});
3133

32-
setPingAmount(amount?.valueOf()?.toString(10));
34+
setPingAmount(result?.valueOf()?.toString(10));
3335
} catch (err) {
3436
console.error('Unable to call getPingAmount', err);
3537
}

src/pages/Dashboard/widgets/PingPongAbi/hooks/useGetTimeToPong.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1+
import { contractAddress } from 'config';
2+
import pingPongAbi from 'contracts/ping-pong.abi.json';
13
import {
4+
AbiRegistry,
25
Address,
36
AddressValue,
4-
ContractFunction,
57
ProxyNetworkProvider,
6-
ResultsParser,
8+
SmartContractController,
79
useGetAccount,
810
useGetNetworkConfig
911
} from 'lib';
10-
import { smartContract } from 'utils';
11-
12-
const resultsParser = new ResultsParser();
1312

1413
export const useGetTimeToPong = () => {
1514
const { network } = useGetNetworkConfig();
1615
const { address } = useGetAccount();
16+
const proxy = new ProxyNetworkProvider(network.apiAddress);
1717

1818
const getTimeToPong = async () => {
1919
if (!address) {
2020
return;
2121
}
2222

2323
try {
24-
const query = smartContract.createQuery({
25-
func: new ContractFunction('getTimeToPong'),
26-
args: [new AddressValue(new Address(address))]
24+
const abi = AbiRegistry.create(pingPongAbi);
25+
26+
const scController = new SmartContractController({
27+
chainID: network.chainId,
28+
networkProvider: proxy,
29+
abi
2730
});
28-
const provider = new ProxyNetworkProvider(network.apiAddress);
29-
const queryResponse = await provider.queryContract(query);
30-
const endpointDefinition = smartContract.getEndpoint('getTimeToPong');
31-
const { firstValue } = resultsParser.parseQueryResponse(
32-
queryResponse,
33-
endpointDefinition
34-
);
35-
const secondsRemaining: number = firstValue?.valueOf()?.toNumber();
31+
32+
const [result] = await scController.query({
33+
contract: Address.newFromBech32(contractAddress),
34+
function: 'getTimeToPong',
35+
arguments: [new AddressValue(new Address(address))]
36+
});
37+
38+
const value = result?.valueOf();
39+
const secondsRemaining: number = Number(value);
3640

3741
return secondsRemaining;
3842
} catch (err) {

0 commit comments

Comments
 (0)