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

@white-matrix/matrix-flow-market-sdk

v0.1.4

Published

`yarn add @white-matrix/matrix-flow-market-sdk`

Downloads

27

Readme

Install

yarn add @white-matrix/matrix-flow-market-sdk

API reference

core apis VoucherClient You can also check Demo-front-page for reference

public async checkNFTsCollection(address: string): Promise<boolean> {
        try {
            const response = await fcl.send([
                checkNFTsCollection,
                fcl.args([fcl.arg(address, t.Address)]),
                fcl.limit(1000)
            ]);
            return fcl.decode(response);
        } catch (error) {
            console.error(error);
            return Promise.reject(error);
        }
    }

    /**
     * Get all assets from given account
     *
     * @async
     * @param {string} recipient - recipient address
     * @returns {Promise<MatrixMarketPlaceNFT[]>} transaction id
     * @example ret = await client.getNFTs("0x01cf0e2f2f715450");
     */
    public async getNFTs(account: string): Promise<MatrixMarketPlaceNFT[]> {
        try {
            const response = await fcl.send([getNFTsScript, fcl.args([fcl.arg(account, t.Address)]), fcl.limit(2000)]);
            console.log(response);
            return fcl.decode(response);
        } catch (error) {
            console.error(error);
            return Promise.reject(error);
        }
    }

    /**
     * Pre-check user storage capabilities
     *
     * @async
     * @param {string} address - userAddress
     * @param {number} currentBalance - userCurrentFlowBalance
     * @param {number} paymentAmount - amount Of Flow user to pay
     * @param {number} numberOfVouchers - number of vouchers user to mint
     * @returns {Promise<void>}
     */
    public async checkCapacity(
        address: string,
        currentBalance: number,
        paymentAmount: number,
        numberOfVouchers: number
    ): Promise<void> {
        try {
            const expectLeftBalance = currentBalance - paymentAmount;
            if (expectLeftBalance < 0.001) {
                return Promise.reject("Please may sure you have > 0.001 FLOW balance after payment");
            }
            console.log("expect balance", expectLeftBalance);

            const usedBytes = await fcl.decode(
                await fcl.send([getUsedStorageScript, fcl.args([fcl.arg(address, t.Address)]), fcl.limit(1000)])
            );

            console.log("used bytes", usedBytes);

            const thresholdInBytes = expectLeftBalance * 1e8 - usedBytes - numberOfVouchers * 500;

            console.log("thresholdInBytes", thresholdInBytes);

            if (thresholdInBytes < 100) {
                return Promise.reject(
                    "Please reserve more FLOW in your wallet, it seems like will run out of storage and likely cause a failed mint"
                );
            }
        } catch (error) {
            console.error(error);
            return Promise.reject("Something is wrong with checking Voucher Collection");
        }
    }

    public async createList(nftId: number, price: string): Promise<string> {
        try {
            const response = await fcl.send([
                createListingScript,
                fcl.args([fcl.arg(nftId, t.UInt64), fcl.arg(price, t.UFix64)]),
                fcl.proposer(fcl.currentUser().authorization),
                fcl.authorizations([fcl.currentUser().authorization]),
                fcl.limit(1000),
                fcl.payer(fcl.currentUser().authorization)
            ]);
            const ret = await fcl.tx(response).onceSealed();
            if (ret.errorMessage !== "" && ret.status != 4) {
                return Promise.reject(ret.errorMessage);
            }
            return response.transactionId;
        } catch (error) {
            console.error(error);
            return Promise.reject(error);
        }
    }

    public async purchaseList(listingResourceId: number, adminAddress: string): Promise<string> {
        try {
            const response = await fcl.send([
                purchaseListingScript,
                fcl.args([fcl.arg(listingResourceId, t.UInt64), fcl.arg(adminAddress, t.Address)]),
                fcl.proposer(fcl.currentUser().authorization),
                fcl.authorizations([fcl.currentUser().authorization]),
                fcl.limit(1000),
                fcl.payer(fcl.currentUser().authorization)
            ]);
            const ret = await fcl.tx(response).onceSealed();
            if (ret.errorMessage !== "" && ret.status != 4) {
                return Promise.reject(ret.errorMessage);
            }
            return response.transactionId;
        } catch (error) {
            console.error(error);
            return Promise.reject(error);
        }
    }

    public async removeList(listingResourceID: number): Promise<string> {
        try {
            const response = await fcl.send([
                removeListingScript,
                fcl.args([fcl.arg(listingResourceID, t.UInt64)]),
                fcl.proposer(fcl.currentUser().authorization),
                fcl.authorizations([fcl.currentUser().authorization]),
                fcl.limit(1000),
                fcl.payer(fcl.currentUser().authorization)
            ]);
            const ret = await fcl.tx(response).onceSealed();
            if (ret.errorMessage !== "" && ret.status != 4) {
                return Promise.reject(ret.errorMessage);
            }
            return response.transactionId;
        } catch (error) {
            console.error(error);
            return Promise.reject(error);
        }
    }

    public async initStorefront(): Promise<string> {
        try {
            const response = await fcl.send([
                initStorefront,
                fcl.proposer(fcl.currentUser().authorization),
                fcl.authorizations([fcl.currentUser().authorization]),
                fcl.limit(1000),
                fcl.payer(fcl.currentUser().authorization)
            ]);
            const ret = await fcl.tx(response).onceSealed();
            if (ret.errorMessage !== "" && ret.status != 4) {
                return Promise.reject(ret.errorMessage);
            }
            return response.transactionId;
        } catch (error) {
            console.error(error);
            return Promise.reject(error);
        }
    }

    public async initNFTCollection(): Promise<string> {
        try {
            const response = await fcl.send([
                initNFTCollection,
                fcl.proposer(fcl.currentUser().authorization),
                fcl.authorizations([fcl.currentUser().authorization]),
                fcl.limit(1000),
                fcl.payer(fcl.currentUser().authorization)
            ]);
            const ret = await fcl.tx(response).onceSealed();
            if (ret.errorMessage !== "" && ret.status != 4) {
                return Promise.reject(ret.errorMessage);
            }
            return response.transactionId;
        } catch (error) {
            console.error(error);
            return Promise.reject(error);
        }
    }