diff --git a/CHANGELOG.md b/CHANGELOG.md index 96e2f5a69..551138df9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [[v3.1.1](https://github.com/multiversx/mx-sdk-dapp/pull/1341)] - 2024-12-06 + +- [Allow custom HRP](https://github.com/multiversx/mx-sdk-dapp/pull/1340) + ## [[v3.1.0](https://github.com/multiversx/mx-sdk-dapp/pull/1339)] - 2024-12-05 - [Added address table pagination to the Ledger authentication flow](https://github.com/multiversx/mx-sdk-dapp/pull/1338) diff --git a/package.json b/package.json index 7290f69ef..8dd689283 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-dapp", - "version": "3.1.0", + "version": "3.1.1", "description": "A library to hold the main logic for a dapp on the MultiversX blockchain", "author": "MultiversX", "license": "GPL-3.0-or-later", diff --git a/src/UI/SignTransactionsModals/SignWithDeviceModal/components/SignStepBody.tsx b/src/UI/SignTransactionsModals/SignWithDeviceModal/components/SignStepBody.tsx index 8edc54c1e..1d163e873 100644 --- a/src/UI/SignTransactionsModals/SignWithDeviceModal/components/SignStepBody.tsx +++ b/src/UI/SignTransactionsModals/SignWithDeviceModal/components/SignStepBody.tsx @@ -52,7 +52,7 @@ const SignStepBodyComponent = ({ currentTransaction.transactionTokenInfo; const transactionReceiver = multiTxData - ? new Address(receiver).bech32() + ? Address.newFromHex(receiver).toBech32() : currentTransaction.transaction.getReceiver().toString(); const scamReport = currentTransaction.receiverScamInfo; diff --git a/src/hooks/login/useLoginService.ts b/src/hooks/login/useLoginService.ts index 3d29504d8..544c34a87 100644 --- a/src/hooks/login/useLoginService.ts +++ b/src/hooks/login/useLoginService.ts @@ -126,7 +126,7 @@ export const useLoginService = (config?: OnProviderLoginType['nativeAuth']) => { } const messageToSign = new Message({ - address: new Address(address), + address: Address.newFromBech32(address), data: Buffer.from(`${address}${loginToken}`) }); diff --git a/src/hooks/signMessage/getVerifier.ts b/src/hooks/signMessage/getVerifier.ts index 0351f263c..178d3e998 100644 --- a/src/hooks/signMessage/getVerifier.ts +++ b/src/hooks/signMessage/getVerifier.ts @@ -1,7 +1,7 @@ import { Address, UserPublicKey, UserVerifier } from '@multiversx/sdk-core'; export const getVerifier = (address: string) => { - const publicKey = new UserPublicKey(new Address(address).pubkey()); + const publicKey = new UserPublicKey(Address.newFromBech32(address).pubkey()); return new UserVerifier(publicKey); }; diff --git a/src/hooks/signMessage/useSignMessage.ts b/src/hooks/signMessage/useSignMessage.ts index ec1c1303a..2074da596 100644 --- a/src/hooks/signMessage/useSignMessage.ts +++ b/src/hooks/signMessage/useSignMessage.ts @@ -144,7 +144,7 @@ export const useSignMessage = (options?: { hasConsentPopup?: boolean }) => { const callbackUrl = encodeURIComponent(String(callbackRoute)); const signableMessage = new Message({ - address: new Address(address), + address: Address.newFromBech32(address), data: Buffer.from(message) }); diff --git a/src/hooks/signMessage/verifyMessage.ts b/src/hooks/signMessage/verifyMessage.ts index 082046fba..e473d3ddf 100644 --- a/src/hooks/signMessage/verifyMessage.ts +++ b/src/hooks/signMessage/verifyMessage.ts @@ -13,7 +13,7 @@ export const verifyMessage = (signedMessage: string) => { const messageComputer = new MessageComputer(); const msg = new Message({ - address: new Address(address), + address: Address.newFromBech32(address), data: decodedMessage }); diff --git a/src/hooks/transactions/helpers/checkNeedsGuardianSigning.ts b/src/hooks/transactions/helpers/checkNeedsGuardianSigning.ts index 212a31114..b31ccece6 100644 --- a/src/hooks/transactions/helpers/checkNeedsGuardianSigning.ts +++ b/src/hooks/transactions/helpers/checkNeedsGuardianSigning.ts @@ -34,7 +34,7 @@ export const checkNeedsGuardianSigning = ({ }); const chainId = transactions[0].getChainID().valueOf(); - const sender = transactions[0].getSender().bech32().toString(); + const sender = transactions[0].sender; const environment = getEnvironmentForChainId(chainId); const walletProviderAddress = walletAddress ?? fallbackNetworkConfigurations[environment].walletAddress; diff --git a/src/models/newTransaction.ts b/src/models/newTransaction.ts index 6d4405846..f13360a9f 100644 --- a/src/models/newTransaction.ts +++ b/src/models/newTransaction.ts @@ -22,11 +22,11 @@ export function newTransaction(rawTransaction: RawTransactionType) { value: rawTx.value.valueOf(), data: getDataPayloadForTransaction(rawTx.data), nonce: rawTx.nonce.valueOf(), - receiver: new Address(rawTx.receiver), + receiver: Address.newFromBech32(rawTx.receiver), ...(rawTx.receiverUsername ? { receiverUsername: rawTx.receiverUsername } : {}), - sender: new Address(rawTx.sender), + sender: Address.newFromBech32(rawTx.sender), ...(rawTx.senderUsername ? { senderUsername: rawTx.senderUsername } : {}), gasLimit: rawTx.gasLimit.valueOf() ?? GAS_LIMIT, gasPrice: rawTx.gasPrice.valueOf() ?? GAS_PRICE, @@ -35,7 +35,9 @@ export function newTransaction(rawTransaction: RawTransactionType) { ...(rawTx.options ? { options: new TransactionOptions(rawTx.options) } : {}), - ...(rawTx.guardian ? { guardian: new Address(rawTx.guardian) } : {}) + ...(rawTx.guardian + ? { guardian: Address.newFromBech32(rawTx.guardian) } + : {}) }); if (rawTx.guardianSignature) { diff --git a/src/reduxStore/slices/accountInfoSlice.ts b/src/reduxStore/slices/accountInfoSlice.ts index 41dad1af1..dd7bcc245 100644 --- a/src/reduxStore/slices/accountInfoSlice.ts +++ b/src/reduxStore/slices/accountInfoSlice.ts @@ -76,7 +76,7 @@ export const accountInfoSlice = createSlice({ ) => { const address = action.payload; state.address = address; - state.publicKey = address ? new Address(address).hex() : ''; + state.publicKey = address ? Address.newFromBech32(address).hex() : ''; }, setAccount: ( state: AccountInfoSliceType, @@ -173,7 +173,7 @@ export const accountInfoSlice = createSlice({ ) => { const { address } = action.payload; state.address = address; - state.publicKey = new Address(address).hex(); + state.publicKey = Address.newFromBech32(address).hex(); } ); builder.addCase(REHYDRATE, (state, action: any) => { diff --git a/src/services/transactions/isCrossShardTransaction.ts b/src/services/transactions/isCrossShardTransaction.ts index bcbd111aa..cef393efe 100644 --- a/src/services/transactions/isCrossShardTransaction.ts +++ b/src/services/transactions/isCrossShardTransaction.ts @@ -13,10 +13,10 @@ export function isCrossShardTransaction({ senderAddress }: IsCrossShardTransactionPropsType) { try { - const receiver = new Address(receiverAddress); + const receiver = Address.newFromBech32(receiverAddress); const receiverShard = getShardOfAddress(receiver.pubkey()); if (senderShard == null && senderAddress != null) { - const sender = new Address(senderAddress); + const sender = Address.newFromBech32(senderAddress); return getShardOfAddress(sender) === receiverShard; } return receiverShard === senderShard; diff --git a/src/services/transactions/transformAndSignTransactions.ts b/src/services/transactions/transformAndSignTransactions.ts index 45fdb1f8b..479d63a96 100644 --- a/src/services/transactions/transformAndSignTransactions.ts +++ b/src/services/transactions/transformAndSignTransactions.ts @@ -67,7 +67,7 @@ export async function transformAndSignTransactions({ let validatedReceiver = receiver; try { - const addr = new Address(receiver); + const addr = Address.newFromBech32(receiver); validatedReceiver = addr.hex(); } catch (err) { throw ErrorCodesEnum.invalidReceiver; @@ -87,7 +87,7 @@ export async function transformAndSignTransactions({ gasPrice, gasLimit: Number(gasLimit), nonce: Number(computedNonce.valueOf().toString()), - sender: new Address(address).hex(), + sender: Address.newFromBech32(address).hex(), chainID: transactionsChainId, version, options, diff --git a/src/utils/account/addressIsValid.ts b/src/utils/account/addressIsValid.ts index 3e72e5e75..f841c0980 100644 --- a/src/utils/account/addressIsValid.ts +++ b/src/utils/account/addressIsValid.ts @@ -2,8 +2,8 @@ import { Address } from '@multiversx/sdk-core'; function canTransformToPublicKey(address: string) { try { - const checkAddress = new Address(address); - return Boolean(checkAddress.bech32()); + const checkAddress = Address.newFromBech32(address); + return Boolean(checkAddress.toBech32()); } catch { return false; } diff --git a/src/utils/account/signMessage.ts b/src/utils/account/signMessage.ts index 342a5e6ff..2eb3f3f4c 100644 --- a/src/utils/account/signMessage.ts +++ b/src/utils/account/signMessage.ts @@ -25,7 +25,7 @@ export const signMessage = async ({ const callbackUrl = addOriginToLocationPath(callbackRoute); const signableMessage = new Message({ - address: new Address(address), + address: Address.newFromBech32(address), data: Buffer.from(message) }); diff --git a/src/utils/operations/calculateFeeLimit.ts b/src/utils/operations/calculateFeeLimit.ts index ad1ee86f7..64362bd64 100755 --- a/src/utils/operations/calculateFeeLimit.ts +++ b/src/utils/operations/calculateFeeLimit.ts @@ -52,8 +52,8 @@ export function calculateFeeLimit({ const transaction = new Transaction({ nonce: 0, value: TokenPayment.egldFromAmount('0'), - receiver: new Address(placeholderData.to), - sender: new Address(placeholderData.to), + receiver: Address.newFromBech32(placeholderData.to), + sender: Address.newFromBech32(placeholderData.to), gasPrice: parseInt(validGasPrice), gasLimit: usedGasLimit, data: new TransactionPayload(data.trim()), diff --git a/src/utils/transactions/getTokenFromData.ts b/src/utils/transactions/getTokenFromData.ts index 9d0b48e4e..1b27ba0ec 100644 --- a/src/utils/transactions/getTokenFromData.ts +++ b/src/utils/transactions/getTokenFromData.ts @@ -64,14 +64,14 @@ export function getTokenFromData(data?: string): { decodeData(data); if ( [collection, nonce, quantity, receiver].every((el) => Boolean(el)) && - addressIsValid(new Address(receiver).bech32()) + addressIsValid(Address.newFromHex(receiver).toBech32()) ) { return { tokenId: `${collection}-${nonce}`, amount: new BigNumber(quantity, 16).toString(10), collection, nonce, - receiver: new Address(receiver).bech32() + receiver: Address.newFromHex(receiver).toBech32() }; } } catch (err) {} diff --git a/src/utils/transactions/parseMultiEsdtTransferDataForMultipleTransactions.ts b/src/utils/transactions/parseMultiEsdtTransferDataForMultipleTransactions.ts index 7d221d1d1..425590325 100644 --- a/src/utils/transactions/parseMultiEsdtTransferDataForMultipleTransactions.ts +++ b/src/utils/transactions/parseMultiEsdtTransferDataForMultipleTransactions.ts @@ -77,7 +77,7 @@ export function parseMultiEsdtTransferDataForMultipleTransactions({ txInfo: { tokenId, amount, - receiver: transaction.getReceiver().bech32() + receiver: transaction.receiver } }); } diff --git a/src/wrappers/AppInitializer.tsx b/src/wrappers/AppInitializer.tsx index d77aabb80..222fde845 100644 --- a/src/wrappers/AppInitializer.tsx +++ b/src/wrappers/AppInitializer.tsx @@ -113,7 +113,7 @@ export const useAppInitializer = ({ useEffect(() => { if (address) { - const pubKey = new Address(address).hex(); + const pubKey = Address.newFromBech32(address).hex(); if (pubKey !== publicKey) { logout(logoutRoute); }