Giter Site home page Giter Site logo

stakeordie / griptape.js Goto Github PK

View Code? Open in Web Editor NEW
29.0 29.0 12.0 646 KB

Griptape is a framework for developing dApps on Secret Network.

Home Page: https://griptapejs.com

License: MIT License

TypeScript 99.65% JavaScript 0.35%
secret-network secretjs

griptape.js's People

Contributors

blake-regalia avatar david-sod avatar gildardosod avatar jsandovalg avatar luiseel avatar reuvenpo avatar vpringle97 avatar yepayepayepa 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

Watchers

 avatar  avatar  avatar  avatar

griptape.js's Issues

Add Viewing Keys API Keplr wrapper

Add a wrapped version of the Viewing Keys API to enable users to create viewing keys using Keplr and pass them into the current Viewing Keys API:

import { keplrViewingKeyManager as vks } from '@stakeordie/griptape.js';

const sefi = ...
const key = ...
vks.add(sefi, key);

Add `shutdown` function

This function should do:

  • Remove the "connected" local storage key
  • Emit a new event called "shutdown" and add its proper listener called onShutdown

Viewing Key API `add` method has wrong TypeScript for the first parameter

When using Griptape.js in TypeScript, add method in ViewingKeyManager class has the wrong type for contracts, therefore you get a type error in TypeScript.

Steps to reproduce the behavior:

  1. Create a contract instance.
  2. Use ViewingKeyManager instance to add a viewing for that contract instance.

Expected behavior
There should be no error.

Screenshots
image

Not error is being thrown when adding an `undefined` viewing key

When using the viewingKeyManager.add and as the second argument you pass undefined, you don't get any error,
and a viewing key gets added without key.

To Reproduce

  1. import viewingKeyManager from @stakeordie/griptape.js
  2. Define a simple contract to add a viewing key for
  3. Use the viewingKeyManager.add method and pass undefined as the second parameter
  4. Check localStorage

Expected behavior

It should throw an error due to the fact that you are adding an undefined viewing key.

Rename `Callback` type on `src/events/index.ts`

  • Change Callback to EventCallback
  • Create a new type for returned callback from an Event Handler named CleanListenerCallback
  • Change all returned references to return the CleanListenerCallback
export type CleanListenerCallback = () => void;

Add event `unsubscribe` method

Add a method to unsubscribe from an event, something like:

const unsubscribe = onAccountAvailable(
  () => console.log('Account available!'));
unsubscribe(); // remove the last callback

Add entropy as part of the context in the Contracts API

Some messages require and entropy as describe in some of the SNIP-20 specification.

Let's remove the responsibility of the user of the Contracts API to provide that piece of data by adding entropy as part of the Contracts API context. So the final interface for the context will be:

export interface Context {
  address?: string;
  key?: string;
  padding?: string;
  height?: number;
  entropy: string;
}

Remove SNIP-20 specific code for preventing query/message execution

When executing a contract, there is some SNIP-20 specific code that handles and warns the user if they are not providing either an address or key for a specific query as follows:

const hasAddress = getValue(result, 'address');
if (hasOwnDeepProperty(result, 'address') && !hasAddress) {
warn(func, result, 'No address available');
return;
}
const hasKey = getValue(result, 'key');
if (hasOwnDeepProperty(result, 'key') && !hasKey) {
warn(func, result, 'No key available');
return;
}

We should remove this and maybe provide and API to handle specific scenarios in which we want to prevent the execution of a query.

Feature Request

Server Side querying of public universal data. Example: n/900 minted.

Change `fees` type of `ContractMessageRequest`

Change the type of fees property to be number and calculate the fees based on the following function:

const gasPriceUscrt = 0.25;
export function getFeeForExecute(gas: number): StdFee {
  return {
    amount: [
      { amount: String(Math.floor(gas * gasPriceUscrt) + 1), denom: "uscrt" },
    ],
    gas: String(gas),
  };
}

So then, you can do:

const stkd = {
  messages: {
    stake() {
      const handleMsg = { stake: { } };
      const fees = 650000;
      return { handleMsg, fees };
    }
  }
}

Adjust `transferAmount` parameter

When calling contracts, adjust transferAmount to receive an Object rather than an array:

doTx() {
  const transferAmount = { amount: '...', denom: '...' };
  return { transferAmount };
}

Add package exports for namespacing

As an API grows, I find valuable to being able to use only specific parts of the API by using nodejs subpath exports.

This means, the API should be imported in a submodule fashion:

import { refContract } from '@stakeordie/griptape.js/contracts';
import { snip20def } from '@stakeordie/griptape.js/contracts/definitions'

Add contracts registry to the Contracts API

This feature request is for adding to the Contracts API a contract registry. The purpose of the contract registry is to hold all the instances of a particular contract, such that you are able to get that contract through an API rather that accessing to the itself.

Here's and example of how that API will look:

import {
  snip20Def,
  createContract,
  getContract
} from '@stakeordie/griptape.js';

const stkd = createContract(...);

const list = getSnip20s(); // [ { symbol: '...', address: '...' } ]

list.forEach(({ symbol: id, address: at }) => {
  const spec = { id, at, definition: snip20Def };
  createContract(spec);
})

getContract('sefi').getBalance();
getContract('stkd').getBalance();

getContract('stkd') === stkd // true

Add support for multi transactions

Add support for multi transactions based on the multiExecute API on secretjs.

The API might look like this:

const sefi = createContract(...);
multiMessage([
  message(sefi.send),
  message(sefi.transfer, arg1, arg2)
])

Handling contract responses

When calling a contract, sometimes the respond contains valuable information that could be used for example, to improve UI/UX. The issue here is that the current secretjs implementation, returns a data property as an array of integers (bytes). One way to handle and properly decode these set of integer could be as follows:

const decoder = new TextDecoder('utf-8');
const raw = await sefi.createViewingKey();
const decoded = decoder.decode(raw.data);
if (decoded) {
  const res = JSON.parse(decoded);
  viewingKeyManager.add(sefi, res.create_viewing_key.key);
}

That being said, there should be a way of:

  1. Get the raw response as a javascript object
  2. Get just the response of the data property
  3. Being able to handle empty responses

In order to do that, I propose the following API:

interface ContractResponse {
  get: () => object;
  getRaw: () => object;
  isEmpty: () => boolean;
}

Add support for utility functions for contract management

secretjs has methods for getting contracts and instantiated them like, mostly those on SigningCosmWasm:

interface SigningCosmWasmClient {
  instantiate(
    codeId: number,
    initMsg: object,
    label: string,
    memo?: string,
    transferAmount?: readonly Coin[],
    fee?: StdFee,
    contractCodeHash?: string,
  ): Promise<InstantiateResult>;
}

Lets expose those features to be able to manage contracts (upload code, instantiate and get them from the blockchain)

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.