Skip to main content

Streamlit component that allows you to connect to Pera Wallet.

Project description

pera_wallet

A Streamlit component to connect to Pera Wallet.

Installation instructions

pip install pera-wallet

Usage instructions

import streamlit as st

from pera_wallet import pera_wallet

if 'wallet' not in st.session_state:
    st.session_state.wallet = {'status': 'disconnected', 'address': None}

if 'txn' not in st.session_state:
    st.session_state.txn = None

NETWORK = 'testnet'

st.title('My App')


def account():
    with st.expander('Account', expanded=True):
        # Add msgpack-encoded transactions to sign, if needed
        transactions_to_sign = []

        wallet = pera_wallet(
            network=NETWORK,
            transactions_to_sign=transactions_to_sign,
            key='pera_wallet',
        )
        if wallet is not None:
            wallet_state, txn_state = wallet
            st.session_state.wallet = wallet_state
            st.session_state.txn = txn_state

            if st.session_state.txn:
                match st.session_state.txn:
                    case {'status': 'proposed'}:
                        st.info(
                            'Please open the Pera Wallet app to sign this transaction.',
                            icon='✍️',
                        )
                    case {'status': 'submitted'}:
                        st.info(
                            'Transaction submitted. Waiting for confirmation.',
                            icon='⏳',
                        )
                    case {'status': 'confirmed', 'txId': tx_id}:
                        st.success(
                            f'Transaction confirmed! View your transaction on [lora](https://lora.algokit.io/{NETWORK}/transaction/{tx_id}) the explorer.',
                            icon='🥳',
                        )
                    case {'status': 'failed', 'msg': msg}:
                        st.error(f'Transaction failed: {msg}', icon='😞')

        if st.session_state.wallet['status'] == 'unavailable':
            st.error('Wallet is only available in secure contexts (HTTPS).')
        else:
            st.caption(
                f'Connected address: {st.session_state.wallet["address"]}'
                if st.session_state.wallet['status'] == 'connected'
                else 'Connect your wallet to begin.'
            )


account()

if not st.session_state.wallet['address']:
    st.stop()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pera_wallet-0.0.11.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pera_wallet-0.0.11-py3-none-any.whl (14.2 MB view details)

Uploaded Python 3

File details

Details for the file pera_wallet-0.0.11.tar.gz.

File metadata

  • Download URL: pera_wallet-0.0.11.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for pera_wallet-0.0.11.tar.gz
Algorithm Hash digest
SHA256 88dab62b724fa000b17829ff4a3abd320ea8675d26949bd2f23e301331c478ac
MD5 32b8e3d2ee8caa8c8c1f01451fe17ad9
BLAKE2b-256 f664b40a91635c01f58e08378d922f5677fc82b5aa15b2b5605c3d9c6faa4f68

See more details on using hashes here.

File details

Details for the file pera_wallet-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: pera_wallet-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 14.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for pera_wallet-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 a08087c3e3831e1dc830e02e2064954ad78800ed3cb6a44db7800fcc7d954b3e
MD5 1cb8d0c7478644bb8e1badcec92d7ccd
BLAKE2b-256 e4489d3b18ed16ce3da7db1b202c09f70e7219b925b68e469e192727cc199315

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page