Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expo Version ([email protected]) #2361

Open
rubixvi opened this issue Jun 22, 2024 · 5 comments · May be fixed by #2693
Open

Expo Version ([email protected]) #2361

rubixvi opened this issue Jun 22, 2024 · 5 comments · May be fixed by #2693
Assignees
Labels
bug Something isn't working
Milestone

Comments

@rubixvi
Copy link

rubixvi commented Jun 22, 2024

Description

The current Expo Version in the SDK is ^49.0.16 within the script.
However, the latest Expo Version is [email protected]

Can we get this updated?

Currently, by passing it with npm install --save @hashgraph/sdk --legacy-peer-deps

Steps to reproduce

  1. Visual Code
  2. Run npx expo install
  3. Run npm install --save @hashgraph/sdk

Additional context

PS F:\XRL Wallet\dev> npm install --save @hashgraph/sdk
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @hashgraph/[email protected]
npm WARN Found: [email protected]
npm WARN node_modules/expo
npm WARN peer expo@"" from [email protected]
npm WARN node_modules/expo-application
npm WARN expo-application@"~5.9.0" from [email protected]
npm WARN node_modules/expo-auth-session
npm WARN 15 more (expo-asset, expo-camera, expo-constants, expo-contacts, ...)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peerOptional expo@"^49.0.16" from @hashgraph/[email protected]
npm WARN node_modules/@hashgraph/cryptography
npm WARN @hashgraph/cryptography@"1.4.8-beta.5" from @hashgraph/[email protected]
npm WARN node_modules/@hashgraph/sdk
npm WARN
npm WARN Conflicting peer dependency: [email protected]
npm WARN node_modules/expo
npm WARN peerOptional expo@"^49.0.16" from @hashgraph/[email protected]
npm WARN node_modules/@hashgraph/cryptography
npm WARN @hashgraph/cryptography@"1.4.8-beta.5" from @hashgraph/[email protected]
npm WARN node_modules/@hashgraph/sdk
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @hashgraph/[email protected]
npm WARN Found: [email protected]
npm WARN node_modules/expo-crypto
npm WARN expo-crypto@"~13.0.0" from [email protected]
npm WARN node_modules/expo-auth-session
npm WARN expo-auth-session@"~5.5.2" from the root project
npm WARN 1 more (the root project)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peerOptional expo-crypto@"^10.1.2" from @hashgraph/[email protected]
npm WARN node_modules/@hashgraph/cryptography
npm WARN @hashgraph/cryptography@"1.4.8-beta.5" from @hashgraph/[email protected]
npm WARN node_modules/@hashgraph/sdk
npm WARN
npm WARN Conflicting peer dependency: [email protected]
npm WARN node_modules/expo-crypto
npm WARN peerOptional expo-crypto@"^10.1.2" from @hashgraph/[email protected]
npm WARN node_modules/@hashgraph/cryptography
npm WARN @hashgraph/cryptography@"1.4.8-beta.5" from @hashgraph/[email protected]
npm WARN node_modules/@hashgraph/sdk
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @hashgraph/[email protected]
npm WARN Found: [email protected]
npm WARN node_modules/expo-random
npm WARN expo-random@"~14.0.1" from the root project
npm WARN
npm WARN Could not resolve dependency:
npm WARN peerOptional expo-random@"^12.1.2" from @hashgraph/[email protected]
npm WARN node_modules/@hashgraph/cryptography
npm WARN @hashgraph/cryptography@"1.4.8-beta.5" from @hashgraph/[email protected]
npm WARN node_modules/@hashgraph/sdk
npm WARN
npm WARN Conflicting peer dependency: [email protected]
npm WARN node_modules/expo-random
npm WARN peerOptional expo-random@"^12.1.2" from @hashgraph/[email protected]
npm WARN node_modules/@hashgraph/cryptography
npm WARN @hashgraph/cryptography@"1.4.8-beta.5" from @hashgraph/[email protected]
npm WARN node_modules/@hashgraph/sdk
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @hashgraph/[email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/expo
npm ERR! peer expo@"
" from [email protected]
npm ERR! node_modules/expo-application
npm ERR! expo-application@"~5.9.0" from [email protected]
npm ERR! node_modules/expo-auth-session
npm ERR! expo-auth-session@"~5.5.2" from the root project
npm ERR! peer expo@"*" from [email protected]
npm ERR! node_modules/expo-asset
npm ERR! expo-asset@"~10.0.9" from [email protected]
npm ERR! 14 more (expo-camera, expo-constants, expo-contacts, expo-crypto, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional expo@"^49.0.16" from @hashgraph/[email protected]
npm ERR! node_modules/@hashgraph/sdk
npm ERR! @hashgraph/sdk@"^2.47.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/expo
npm ERR! peerOptional expo@"^49.0.16" from @hashgraph/[email protected]
npm ERR! node_modules/@hashgraph/sdk
npm ERR! @hashgraph/sdk@"^2.47.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Hedera network

other

Version

v2.47.0

Operating system

Windows

@rubixvi rubixvi added the bug Something isn't working label Jun 22, 2024
@ivaylonikolov7 ivaylonikolov7 self-assigned this Jul 11, 2024
@ivaylonikolov7
Copy link
Contributor

ivaylonikolov7 commented Jul 15, 2024

After some discussion with @rubixvi , we found out that bumping the expo version might not solve their issue. The following text and code is a followup from them.

Code snippets

import { AccountId, Client, TransferTransaction, Hbar } from '@hashgraph/sdk';

const client = Client.forTestnet().setOperator(
process.env.EXPO_PUBLIC_ACCOUNT_ID ?? '',
process.env.EXPO_PUBLIC_PRIVATE_KEY ?? ''
);

const confirmTransaction = async () => {
setModalVisible(false);
try {
const sanitizedRecipientId = sanitizeRecipientId(recipientId);
const sanitizedAmount = sanitizeAmount(amount);
const sanitizedMemo = sanitizeMemo(memo);
const hbarAmount = Number(sanitizedAmount);

  if (isNaN(hbarAmount) || hbarAmount <= 0) {
    setAlertType('error');
    setAlertMessage('Invalid amount. Please enter a valid number.');
    return;
  }

  if (sanitizedRecipientId === accountId) {
    setAlertType('error');
    setAlertMessage('Please check the payment address.');
    return;
  }

const transaction = await new TransferTransaction()
  .addHbarTransfer(accountId, Hbar.fromTinybars(-hbarAmount * 100000000))  // Convert HBAR to tinybars
  .addHbarTransfer(sanitizedRecipientId, Hbar.fromTinybars(hbarAmount * 100000000))
  .setTransactionMemo(sanitizedMemo)
  .execute(client);

const receipt = await transaction.getReceipt(client);
const status = receipt.status;

if (status.toString() === 'SUCCESS') {
  setAlertType('success');
  setAlertMessage('Sending Complete');
  setReceiptNumber(transaction.transactionId.toString());
  clearInputs();
} else {
  setAlertType('error');
  setAlertMessage('Sending Failed');
}
} catch (error) {
setAlertType('error');
setAlertMessage('Sending Failed');
console.error('Error during transaction:', error);
}
};

package.json:

"dependencies": {
"@ethersproject/shims": "^5.7.0",
"@expo/vector-icons": "^14.0.2",
"@hashgraph/sdk": "^2.26.0",
"@react-native-async-storage/async-storage": "^1.24.0",
"@react-native-picker/picker": "^2.7.7",
"@react-navigation/native": "^6.0.2",
"axios": "^1.7.2",
"expo": "~51.0.20",
"expo-camera": "^15.0.13",
"expo-clipboard": "~6.0.3",
"expo-crypto": "~13.0.2",
"expo-font": "~12.0.8",
"expo-local-authentication": "~14.0.1",
"expo-optimize": "^0.2.20",
"expo-print": "^13.0.1",
"expo-random": "^14.0.1",
"expo-router": "~3.5.18",
"expo-secure-store": "~13.0.2",
"expo-sharing": "^12.0.1",
"expo-splash-screen": "~0.27.5",
"expo-status-bar": "~1.12.1",
"expo-web-browser": "~13.0.3",
"long": "^5.2.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-native": "^0.74.3",
"react-native-get-random-values": "^1.11.0",
"react-native-modal-datetime-picker": "^17.1.0",
"react-native-svg": "^15.4.0",
"react-native-web": "^0.19.12",
"react-qr-code": "^2.0.15"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@types/react": "^18.3.3",
"@types/react-native": "^0.73.0",
"@types/react-test-renderer": "^18.0.7",
"eslint": "^9.7.0",
"eslint-config-expo": "^7.0.0",
"metro-minify-terser": "^0.80.9",
"postcss-loader": "^8.1.1",
"react-native-svg-transformer": "^1.4.0",
"react-test-renderer": "^18.3.1",
"ts-node": "^10.9.2",
"typescript": "^5.5.3"
},

Running a buffer:

import { Buffer } from "buffer";

globalThis.Buffer = Buffer;

Layout:

import "react-native-get-random-values"
import "./shims-buffer";
import '@ethersproject/shims';

Error

ERROR Error during transaction: [Error: Not a valid base64 encoded string length]

@ivaylonikolov7
Copy link
Contributor

Hello @rubixvi,

Can I please have the code for sanitizeRecipientId, sanitizeAmount and sanitizeMemo as the current ongoing theory in the team is that your problem might be because of the stuff that's happening inside sanitizeMemo.

@Petyo-Lukanov Petyo-Lukanov added this to the 2.49.0 milestone Jul 15, 2024
@rubixvi
Copy link
Author

rubixvi commented Jul 15, 2024

const sanitizeRecipientId = (input: string): string => {
return input.replace(/[^a-zA-Z0-9.]/g, '');
};

const sanitizeAmount = (input: string): string => {
return input.replace(/[^0-9.]/g, '');
};

const sanitizeMemo = (input: string): string => {
return input.replace(/[^a-zA-Z0-9\s-.]/g, '');
};

Just a simple script to prevent the wrong inputs.

@ivaylonikolov7
Copy link
Contributor

ivaylonikolov7 commented Jul 18, 2024

Hello, @rubixvi.

We managed to reproduce your issue on Android using Android Studio's emulator by following these steps.

  1. creating an expo project
  2. installing @hashgraph/sdk package
  3. adding the code snippet you provided in a useEffect()
  4. running the app in Android environment

In iOS this was working fine. As you said the web version does not have this problem neither. After some investigation we found out that altho expo shows an error with atob's base64 length but the transaction still passes and the transaction receipt shows status code: 22. Which means the transaction was successful. This can be confirmed from hashscan too - https://hashscan.io/testnet/transaction/1721299020.763775003.

or by running this code:

      const response = await new AccountCreateTransaction()
        .setKey(privateKey)
        .execute(client);

      const receipt = await response.getReceipt(client);
      console.log(receipt);

Thank you for your code snippets for the sanitisation methods you useI asked you for the sanitisation methods because I wanted to be sure that there isn't some base64 encoding that you were doing to the memo. I tested that but this wasn't the issue as I tried running the script without any sanitisation and it was still throwing an error in Android environment.

We also tried to deserialise and serialise it back. For two reasons:

  • Wondering if there was some issue with Android converting the transaction to bytes as it uses base64 in some places but this was not the case.
  • Sending the transaction data to the RPC was the last place the code went in the SDK before the base64 error was thrown.
const response = await new AccountCreateTransaction()
        .setKey(privateKey)
        .toBytes();
      
      Transaction.fromBytes(response).execute(client);

The following code didn't throw an error and correctly deserialised the transaction with expected data.

Our current theory is that there is some issue with expo's newest version so we will be making an issue in their repository.

Thank you for raising this issue. Will keep you updated if there's some response from expo.

Expo related issue that I have created: expo/expo#30503

@rubixvi
Copy link
Author

rubixvi commented Jul 19, 2024

Thanks, glad that's all cleared up,
Looks like we'll just to wait for their response.

Atleast it wasn't my coding.

@SimiHunjan SimiHunjan modified the milestones: v2.49.0, v2.50.0 Jul 23, 2024
@annamariyaivanova annamariyaivanova modified the milestones: v2.50.0, v2.51.0 Aug 23, 2024
@SimiHunjan SimiHunjan modified the milestones: v2.51.0, v2.52.0 Sep 4, 2024
@SimiHunjan SimiHunjan removed this from the v2.52.0 milestone Sep 17, 2024
@rwalworth rwalworth added this to the v2.55.0 milestone Nov 12, 2024
@ivaylonikolov7 ivaylonikolov7 linked a pull request Dec 4, 2024 that will close this issue
2 tasks
@agadzhalov agadzhalov modified the milestones: v2.55.0, v2.56.0 Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants