thencc / algonautjs

A front end friendly Algorand utility
MIT License
10 stars 1 forks source link

api design Q #61

Closed spencercap closed 1 year ago

spencercap commented 1 year ago

should we make all methods + config funcs individual exports that relate to a central state instance? versus how it is now where most utils are members + methods of the large Algonaut() class.


reference: look how mobx does this w a global configure func (https://mobx.js.org/configuration.html#proxy-support)

import { configure } from "mobx"

configure({
    useProxies: "never"
})

then, instead of how we do it now, it would look something like...

import { 
  setNodeConfig,
  connect, 
  sendAlgo
} from '@thencc/algonautjs';

// set node to use (globally)
setNodeConfig({
    BASE_SERVER: 'https://testnet-algorand.api.purestake.io/ps2',
    API_TOKEN: { 'X-API-Key': 'MY_KEY_HERE' }, // key is header, value is token
    LEDGER: 'TestNet',
    PORT: ''
});

// connect acct 
let accts = await connect(); // uses inkey as single wallet default. similar to how it is now. + stores in localstorage

// construct a txn + sign it + send it
let t = await sendAlgo({
  to: '123', 
  amount: 1000
});

idea:

import { 
  AnyWalletState
} from '@thencc/algonautjs';

console.log(AnyWalletState.address); // would be populated on page load IF user had connected an acct to the dapp previously
spencercap commented 1 year ago

NOTE: @youraerials hates this approach! it moves the floor out for under ya and it's super hard to debug. i saw it with my own eyes!