npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@proton/react-native-sdk

v4.2.18

Published

## Installation

Downloads

30

Readme

Proton Web SDK

Installation

yarn add @proton/react-native-sdk react-native-get-random-values @react-native-async-storage/async-storage

cd ios
pod install

Usage

Initialization

import ProtonRNSDK, {
  LinkSession,
  ProtonLink,
} from '@proton/react-native-sdk';

class ProtonSDK {
  chainId: string;
  endpoints: string[];
  requestAccount: string;
  session: LinkSession;
  link: ProtonLink;

  constructor() {
    this.chainId =
      '71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd';
    this.endpoints = ['https://testnet.protonchain.com']; // Multiple for fault tolerance
    this.requestAccount = 'taskly'; // optional
    this.session = null;
    this.link = null;
  }

Login

Using the return value from the default call, call the login method with the chainId, endpoints, the requestAccount and the getReturnUrl function. The getRetunUrl function returns the url scheme of the app that the user will be redirected to after an interaction with the Proton App. Default call will return the user session (LinkSession) and a link (ProtonLink).

login = async () => {
  const { session, link } = await ProtonRNSDK({
    linkOptions: { chainId: this.chainId, endpoints: this.endpoints },
    transportOptions: {
      requestAccount: this.requestAccount,
      getReturnUrl: () => 'taskly://main',
    },
  });

  this.link = link;
  this.session = session;
  return { auth: session.auth };
};

This function can be used in code like this:

// Usage
const protonSDK = new ProtonSDK();

// usage login()
try {
  const { auth } = await protonSDK.login();
  rootStore.setActor(auth.actor);
  rootStore.setPermission(auth.permission);

  // do something like go to a subscription page
  navigation.navigate('subscription');
} catch (ex) {
  // login failed
  Alert.alert('Error', ex.message);
}

Note that login will throw an exception if the user does not authorize the login.

Transaction

To initiatize a transaction, use the transact method of the session object:

sendTransaction = async (actions: Action) => {
  return this.session.transact({ actions: actions }, { broadcast: true });
};

The following code shows a small example how to send 5 XUSDT to an account:

try {
  const actions = [
    {
      account: 'xtokens',
      name: 'transfer',
      authorization: [
        {
          actor: rootStore.actor, // auth.actor that was saved before
          permission: rootStore.permission, // auth.permission that was saved before
        },
      ],
      data: {
        from: rootStore.actor, // auth.actor that was saved before
        to: protonSDK.requestAccount, // the account the transaction is send to
        quantity: '5.000000 XUSDT', // the amount of the transaction
        memo: 'Taskly',
      },
    },
  ];

  const tx = await protonSDK.sendTransaction(actions);

  // navigate to the subscribed page
  navigation.navigate('subscribed');
} catch (ex) {
  // the transaction failed
  Alert.alert('Error', ex.message);
}

Please note that if the user does not authorize the transaction, an exception will be thrown.

Logout

To logout call removeSession on the link object.

logout = async () => {
  await this.link.removeSession(this.requestAccount, this.session.auth);
  this.session = null;
  this.link = null;
};

In the application you can use it like this:

// usage logout
protonSDK.logout();
navigation.navigate('welcome');

Restore session

To restore a previous session, call the default function similar to login, but set the restoreSession key as true in linkOptions.

  restoreSession = async () => {
    try {
      const { link, session } = await ProtonRNSDK({
        linkOptions: {
          chainId: this.chainId,
          endpoints: this.endpoints,
          restoreSession: true,
        },
        transportOptions: {
          requestAccount: this.requestAccount,
          getReturnUrl: () => 'taskly://main',
        },
      });
      this.link = link;
      this.session = session;

      console.log('session', this.session);

      if (session) {
        return {
          auth: this.session.auth
        };
      } else {
        return { auth: { actor: '', permission: '' } };
      }
    } catch (e) {
      return e;
    }
  };
}

The code below shows how restoreSesssion might be used:

try {
  await protonSDK.restoreSession();
} catch (ex) {
  console.warn(ex.message);
}

if (protonSDK.session !== null) {
  console.log('session still exists');
} else {
  console.log('session does not exits anymore');
}