Git Product home page Git Product logo

scio-labs / use-inkathon Goto Github PK

View Code? Open in Web Editor NEW
50.0 5.0 15.0 4 MB

Typesafe React hooks and utility functions that simplify the process of working with Substrate-based networks and ink! smart contracts.

Home Page: https://inkathon.xyz

License: GNU General Public License v3.0

TypeScript 99.81% JavaScript 0.19%
blockchain hooks ink javascript polkadot polkadot-blockchain polkadot-js polkadot-js-api polkadot-network react

use-inkathon's People

Contributors

github-actions[bot] avatar ical10 avatar leechael avatar maximiliandietel03 avatar niklasp avatar pawel-szydlo avatar peetzweg avatar wottpal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

use-inkathon's Issues

Cache WSProvider + api?

I have e multichain app (pollkadot relay + kusama relay). Atm switchActiveChain disconnects the connected api. in case of a dapp with only limited chains it would be great to cache the api instances alongside their wsprovider instances for faster and better ux

Also can you enable discussions as i feel this is more of a discussion.

Unhandled Runtime Error Error: No signer specified, either via api.setSigner or via sign options. You possibly need to pass through an explicit keypair for the origin so it can be used for signing.

Hey i've been getting this error while calling the contractTx method. The thing is the method sometimes runs no problem and sometimes does not.

Here is the function that calls the contractTx method. https://github.com/corlys/next-useinkathon/blob/641d6f867bcf50b5176e90746d63e89aa53a7ac3/src/pages/index.tsx#L39

Cycle through RPCs if initialisation fails

As of now rpc1 of Pop Network seems to be broken/down temporarily. The chains config for pop has 3 rpc configured. However, my dapp using Pop network is broken as it just tries to connect to the first rpc in the rpc array.

It would be great if it would cycle through the rpcs in the chains config if the current one fails.

As of now I'm not aware how to make use-inkathon use another rpc than the first one in the hardcoded SubstrateChain object.

Dedicated Wallet Connection

Right now, it's only possible to initiate a generalized connect which triggers all Substrate-enabled extensions (SubWallet, Talisman, polkadot.js, etc.). Instead, it would be nice if a user could directly select a wallet he/she wants to connect with, and then only this one gets triggered (like with talisman-connect).

Support all ink!-compatible chains

Add support in chains.ts for all Substrate-based chains supporting ink! smart contracts:

  • [Development] Local Node
  • [Testnet] Rococo
  • [Testnet] Aleph Zero
  • [Testnet] Shibuya
  • [Testnet] t3rn
  • [Testnet] Enjin
  • [Testnet] Bit.Country
  • [Testnet] peaq
  • [Testnet] Pendulum
  • [Testnet] Phala PoC-5
  • [Mainnet] Shiden
  • [Mainnet] Astar
  • [Mainnet] Aleph Zero
  • [Mainnet] Phala
  • [Mainnet] Amplitude
  • [Mainnet] Pendulum

I've accumulated this list from use.ink & contracts-ui but it might not be fully complete or up-to-date. – We need to check.

Lack of installation requirements

pnpm add @scio-labs/use-inkathon
# or
npm install @scio-labs/use-inkathon
# or
yarn add @scio-labs/use-inkathon

installing the package module isn't enough (this is v0.10.0) because app will get this error:

6:29:45 PM [vite] error while updating dependencies:
Error: Build failed with 6 errors:
node_modules/@scio-labs/use-inkathon/dist/chunk-6OTXFMWK.js:2:59: ERROR: Could not resolve "@polkadot/util"
node_modules/@scio-labs/use-inkathon/dist/chunk-6OTXFMWK.js:3:45: ERROR: Could not resolve "@polkadot/api-contract"
node_modules/@scio-labs/use-inkathon/dist/chunk-6OTXFMWK.js:4:53: ERROR: Could not resolve "@polkadot/api"
node_modules/@scio-labs/use-inkathon/dist/chunk-6OTXFMWK.js:5:32: ERROR: Could not resolve "@polkadot/util-crypto"
node_modules/@scio-labs/use-inkathon/dist/chunk-O4R6XJ2C.js:8:32: ERROR: Could not resolve "@polkadot/api-contract"
...
    at failureErrorWithLog (/Users/dellwatson/Desktop/hyape_1/starex_v2/node_modules/vite/node_modules/esbuild/lib/main.js:1650:15)
    at /Users/dellwatson/Desktop/hyape_1/starex_v2/node_modules/vite/node_modules/esbuild/lib/main.js:1058:25
    at /Users/dellwatson/Desktop/hyape_1/starex_v2/node_modules/vite/node_modules/esbuild/lib/main.js:1526:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

resulting unable to even run locally
even the current example your provide in react-ts folder also not working, i need to install nightlylabs too

[ERROR] Could not resolve "@nightlylabs/wallet-selector-polkadot"

   node_modules/@scio-labs/use-inkathon/dist/chunk-R4LN4DEY.js:2:38:
     2  import { NightlyConnectAdapter } from '@nightlylabs/wallet-selector-polkadot';
                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 You can mark the path "@nightlylabs/wallet-selector-polkadot" as external to exclude it from the
 bundle, which will remove this error and leave the unresolved path in the bundle.

so need to install these dependecies

    "@nightlylabs/wallet-selector-polkadot": "^0.2.6",
    "@polkadot/api": "^10.12.6",
    "@polkadot/api-contract": "^10.12.6",
    "@polkadot/util-crypto": "^12.6.2",
    "@scio-labs/use-inkathon": "^0.10.0",
    ```

Add examples directory

In a new examples/ directory should be two very simple examples that use @scio-labs/use-inkathon as a workspace import. This should make package development much quicker & easier.

The examples should, by far, not showcase all the functionality but just being quite simplistic (connect wallet, read balance, maybe something else).

Balance formatting seems to be broken when `fixedDecimals` is set

Without fixedDecimals (these are correct values):
image

With { fixedDecimals: 2 } (order of magnitude is sometimes incorrect, depending on how big the number is):
image

This is probably a problem with the polkadot library (something related to the withSi option of the formatter?), but maybe use-inkathon could compensate for it somehow?

Questioning the type of balance returned as the formatted balance

I really like the utility of your useBalance() hook - it's def better thought-through than in the other libraries I've researched so far. Got a doubt about one detail though: I'm wondering if it doesn't make more sense to format the reducibleBalance in here and thus expose that one as balanceFormatted.

The reason for asking is that in my experience, it is more common to display reducible balance rather than the overall balance, because that's effectively what a user can actually use. We've had cases in our dapps of users being disoriented by being presented the raw balance and we had to switch to displaying the reducible balance.

Alternatively, all balances (balance, reducibleBalance, freeBalance etc.) could be exposed as formatted, if we don't want to choose for the user. Another alternative, if we're afraid of the complex formatting calculation for all of them on every render, could be to let the user choose which balance to format by passing a parameter to the hook (it should be relatively easy to make it type-safe with some generic).

Wdyt?

Cache selected active account in localStorage

I've noticed that when i reload a page with one connected wallet account, the active account switches to the first account if there more than one account or wallet addresses in the wallet.

Especially on page refresh

This is before page refresh
Screenshot 2023-03-14 at 11 54 16

After page refresh
Screenshot 2023-03-14 at 11 54 34

`usePSP22Balances` ignores active chain

The current behavior is that all PSP22 balances are fetched, totally ignoring the active chain the user is on. Only PSP22s should be fetched where the originChain attribute matches the activeChain.network.

This would have not been an issue with a solution where I actively pass the tokens I want to fetch, but as discussed, for simplicity we stick to the current approach.

NightlyConnect integration

  • Support NightlyConnect (mobile wallet connection) as a wallet provider
  • Compatibility to relay transaction via QR code
  • Integrate connection in scio-labs/inkathon

Hard to scroll and select accounts at the bottom of the list

When having a long list of accounts, scroll position is fixed to the top. Thus making it hard to scroll down and select an account at the bottom of the list. "Scrolling" down using arrow key doesn't help either.

Screen.Recording.2023-04-26.at.16.54.48.mov

Suggested solution:
Set a max-height to the container of the list and add an inner scrollbar

NightlyConnect pops up when no wallet installed

When there are no wallets installed i would not expect to see a nightly connect popup per default.

There is a little bug in the code, as isWalletInstalled always returns true for nightly

if (wallet.id === nightlyConnect.id) return true

const wallets = allSubstrateWallets.filter((w) => isWalletInstalled(w))
if (!wallets?.length) {
const message = 'No Substrate-compatible extension detected'
setError({
code: UseInkathonErrorCode.NoSubstrateExtensionDetected,
message,
})
throw new Error(message)
}
// Determine wallet to use
const preferredWallet = wallet && wallets.find((w) => w.id === wallet.id)
const _wallet = preferredWallet || wallets[0]

wallets will never be [] and so nightlyWallet will always be the preferredWallet that is tried to enable, also if no wallets are installed.

What do you think about tackling this in a feature-add-workaround where instead of using allSubstrateWallets add a supportedWallets value to the provider that defaults to allSubstrateWallets and working with that instead in the provider. I am asking because I had to limit the supported wallets in my dapps and it would solve the issue for all not adding nightlyWallet to the supportedWallets

List of value doesn't return

getname return this value from polkadotjs basically it's a return list.

getname (): Result<Vec<GreeterName>, InkPrimitivesLangError>
{ Ok: [ { name: abc age: 10 } ] }

But while fetching this value in front end using this code.

  // Fetch Name
  const fetchname = async () => {
    if (!contract || !api) return
    setFetchIsLoading(true)
    try {
      const result = await contractQuery(api, '', contract, 'getname')
      const message = unwrapResultOrError<[string]>(result)
      console.log("This is success " + message);
      // setGreeterMessage(message)
    } catch (e) {
      console.error(e)
      toast.error('Error while fetching name. Try again…')
      setGreeterMessage(undefined)
    } finally {
      setFetchIsLoading(false)
    }
  }

on print using console.log("This is success " + message) print,

This is success [object Object]

Instead list of value. What is wrong here?

Improve RPC selection logic

Currently, the RPC selection is too simple. It picks the first item in the rpcUrls array of a SubstrateChain (see https://github.com/scio-labs/use-inkathon/blob/main/src/provider.tsx#L82) and creates a WsProvider object (which even fails if the provided url is not a websocket).

  • It must be determined whether it's a wss/https rpc url (e.g. via regex) and create the according provider object
  • If an RPC connection fails multiple times it should try the next rpc (until the first one works). Otherwise, providing a full list of RPCs somehow makes no sense.

Can't resolve 'crypto' in

Please help me solve this issue:

`ERROR in ./node_modules/useink/dist/chunk-CFOEQQMR.mjs 15759:0-32
Module not found: Error: Can't resolve 'crypto' in 'D:\Test Projects\Substrate Practice\substrate_testapp\node_modules\useink\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
	- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "crypto": false }
ERROR in ./node_modules/useink/dist/chunk-CFOEQQMR.mjs
Cannot read properties of undefined (reading 'module')`

This is my code i just ran npm i useink command and use this code:

`import { UseInkProvider } from 'useink';
import { RococoContractsTestnet, ShibuyaTestnet } from 'useink/chains';

function App() {
  return (
    <UseInkProvider 
      config={{ 
        dappName: 'Flipper', 
        chains: [RococoContractsTestnet, ShibuyaTestnet] ,
      }}
    >
      
    </UseInkProvider>
  );
}

export default App`

Ability to use 'ecdsa' type instead of the usual 'sr25519'

Is it possible to use ecdsa type instead of sr25519? Since ink only exposes how to verify ecdsa signatures using ink::env::ecdsa_recover() . Its possible to do it on the using polkadotjs's keyrings if we are using polkadotjs library.

//using @polkadot/keyring
import { Keyring } from '@polkadot/keyring';

...
// create a keyring with some non-default values specified
const keyring = new Keyring({ type: 'ecdsa' });

...
//using @polkadot/ui-keyring
import keyring from '@polkadot/ui-keyring';
import { cryptoWaitReady } from '@polkadot/util-crypto';

cryptoWaitReady().then(() => {
  // load all available addresses and accounts
  keyring.loadAll({ ss58Format: 42, type: 'sr25519' });

  // additional initialization here, including rendering
});

If its possible using this library is there a way to do it?

Error Message

image

Hello everyone, have you ever experienced an error like this? I tried to call contract using contractTx, maybe someone knows why? Thank you to all of you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.