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

[sdk] Support React Native #271

Closed
AtlantisPleb opened this issue Jul 23, 2020 · 3 comments
Closed

[sdk] Support React Native #271

AtlantisPleb opened this issue Jul 23, 2020 · 3 comments
Labels
Feature Feedback gRPC Adjacent An issue where the underlying issue is directly or indirectly related to gRPC JS

Comments

@AtlantisPleb
Copy link

AtlantisPleb commented Jul 23, 2020

Issue To Be Solved

The latest @onflow/sdk is currently unusable by React Native apps. Its required @onflow/send uses the gRPC NodeHttpTransport which does not work with React Native.

SDK calls like sdk.getLatestBlock() fail with the error:

[Unhandled promise rejection: Error: Response closed without grpc-status (Headers only)]
- node_modules/@onflow/send/dist/send.js:1:315 in n.grpc.unary$argument_1.onEnd
- node_modules/@improbable-eng/grpc-web/dist/grpc-web-client.umd.js:1:25082 in t.unary
[...]

Using versions:

  • @onflow/sdk 0.0.28
  • @onflow/send 0.0.15
  • flow version 0.6.0

Suggest A Solution

Allow optional use of the gRPC ReactNativeTransport.

Example commit here showing how we got @onflow/sdk calls working from a React Native app. That hardcodes the ReactNativeTransport but it should probably be a parameter somewhere.

The primary change, from packages/send/src/unary.js:

+ import {ReactNativeTransport} from "@improbable-eng/grpc-web-react-native-transport"

- grpc.setDefaultTransport(NodeHttpTransport())
+ grpc.setDefaultTransport(ReactNativeTransport({}))

All the SDK calls from the example app (getAccount, getEvents, getLatestBlock, getTransactionStatus, ping, script, transaction) worked fine via RN using the above change, though more thorough testing will be needed to identify other potential issues from using RN.

I'm happy to submit a PR for the above if helpful. Open to suggestions on where to put the RN flag, or other considerations re React Native integration unsolved by the above.

@orodio
Copy link
Contributor

orodio commented Aug 24, 2020

@Entryist Good news on this front, we are working at removing gRPC completely from the JS-SDK, and will instead be using standard http requests, so this and an entire other suite of issues should go away naturally. I can't give any promises as to timelines, but I can say it has a fairly high priority from the Access Node side of things and once its an available transport option for us, it will be our highest priority.

@swarlezbarkley
Copy link

I am trying to listen to a flow smart contract event from my Node.js Application.

This is my code for getting the said events:

const getEvents = async (params) => {
  // Define event type from params
  const { contractAddress, contractName, eventName } = params;
  const eventType = `A.${contractAddress}.${contractName}.${eventName}`;

  const { from = 0, to } = params;
  let toBlock;
  if (to === undefined) {
    // Get latest block
    const blockResponse = await fcl.send(
      await sdk.build([sdk.getLatestBlock()])
    );
    toBlock = blockResponse.latestBlock.height;
  } else {
    toBlock = to;
  }

  const response = await fcl.send(
    await sdk.build([sdk.getEvents(eventType, from, toBlock)])
  );

  // Return a list of events
  return response.events;
};

However, I am having this issue.

Error: Response closed without headers

I am using these dependency versions:

@onflow/sdk 0.0.44
@onflow/send 0.0.35
@onflow/fcl 0.0.67

Please help.

@orodio orodio added the gRPC Adjacent An issue where the underlying issue is directly or indirectly related to gRPC label Feb 20, 2021
@orodio
Copy link
Contributor

orodio commented Feb 26, 2021

House keeping, tagging and closing in favour of: #321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Feedback gRPC Adjacent An issue where the underlying issue is directly or indirectly related to gRPC JS
Projects
None yet
Development

No branches or pull requests

3 participants