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

snaptrade-react

v3.2.1

Published

A React component for SnapTrade connection portal.

Downloads

6,979

Readme

NPM Version NPM Downloads npm-bundle-size license-badge

📖 Table of Contents

🚀 Getting Started

npm install snaptrade-react
import { useState } from 'react';
import { SnapTradeReact } from 'snaptrade-react';

const ConnectBrokerage = () => {
  const [open, setOpen] = useState(false);
  const [redirectLink, setRedirectLink] = useState(null);

  const connectionProcess = () => {
    // call "https://api.snaptrade.com/api/v1/snapTrade/login" to  generate a redirect link
    const link = getRedirectURI();

    // update the state with the generated link
    setRedirectLink(link);

    // update the "open" state to show the modal
    setOpen(true);
  };
  return (
    <div>
      {/* your Connect button */}
      <button onClick={connectionProcess}>Connect</button>

      <SnapTradeReact
        loginLink={redirectLink}
        isOpen={open}
        close={() => setOpen(false)}
      />
    </div>
  );
};

export default ConnectBrokerage;

⚙️ Configuration

SnapTradeReact requires the following props:

*: optional

| Prop | Type | Default value | Description | | -------------- | ----------------------------------------------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | loginLink | string | undefined | The generated redirect link. (retrieve by calling https://api.snaptrade.com/api/v1/snapTrade/login) | | isOpen | boolean | undefined | Determines to show/hide the modal. | | close | Function | undefined | A function to be called when user clicks out of the modal or click the X button. | | onSuccess* | Function | undefined | A callback function that is executed upon successful connection to a brokerage. This function returns the authorization ID associated with the new connection. | | onError* | Function | undefined | A callback function that is triggered when a user encounters an error while attempting to connect to a brokerage. This function returns an object containing both an error code, status code and a detailed description of the error. | | onExit* | Function | undefined | A callback function that is triggered when a user closes the modal or exits the second tab (opened for making an oAuth connection) without successfully connecting to a brokerage. | | | | contentLabel* | string | Connect Account via SnapTrade | Indicating how the content container should be announced to screenreaders. | | style* | overlay: { backgroundColor: string, zIndex: number} | overlay: { backgroundColor: 'rgba(255, 255, 255, 0.75)', zIndex: 1} | Change styling for the overlay. |

📚 Using the useWindowMessage Hook

The useWindowMessage hook can be used to listen for window messages and handle success, error, exit, and close modal events. Here’s how to use it:

import { useEffect } from 'react';
import { useWindowMessage } from 'snaptrade-react/hooks/useWindowMessage';

const MyComponent = () => {
  const onSuccess = (data) => {
    console.log('Success:', data);
  };

  const onError = (data) => {
    console.error('Error:', data);
  };

  const onExit = () => {
    console.log('Exit');
  };

  const close = () => {
    console.log('Close');
  };

  useWindowMessage({
    handleSuccess: onSuccess,
    handleError: onError,
    handleExit: onExit,
    close: close,
  });

  return <div>My Component</div>;
};

export default MyComponent;

This hook handles the SUCCESS, ERROR, CLOSED, and CLOSE_MODAL events and triggers the corresponding callbacks.

👨🏼‍⚖️ License & copyrights

Licensed under Apache License 2.0.