@matrix-labs/matrix-storefront-sdk
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "@matrix-labs/matrix-storefront-sdk", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"main": "./dist/index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "yarn build:clean && yarn tsc", | ||
"build": "yarn build:clean && tsc", | ||
"build:clean": "rm -rf dist && rm -f tsconfig.tsbuildinfo", | ||
@@ -9,0 +9,0 @@ "lint": "eslint \"**/*.{js,ts}\"", |
@@ -0,1 +1,63 @@ | ||
### Install | ||
`yarn add @matrix-labs/matrix-storefront-sdk` | ||
```typescript | ||
/** | ||
* first step | ||
* | ||
* @async | ||
* @param fcl: import * as fcl from "@onflow/fcl" | ||
* @param env: import FlowEnv from "@matrix-labs/matrix-marketplace-nft-sdk" | ||
* @example import * as fcl from "@onflow/fcl"; const client = new MatrixMarketplaceNFTClient(); client.bindFcl(fcl, FlowEnv.flowTestnet); | ||
*/ | ||
bindFcl(fcl: any, env: FlowEnv): Promise<void>; | ||
/** | ||
* before createList or removeList | ||
* @async | ||
* @param address: account's address | ||
*/ | ||
checkStorefront(address: string): Promise<boolean> | ||
/** | ||
* if checkStorefront return false | ||
* @async | ||
*/ | ||
initStorefront(): Promise<string>; | ||
/** | ||
* @async | ||
* @param supportedNFTName: NFT collection name | ||
* @param supportedNFTAddress: NFT collection contract address | ||
* @param nftId: import * as fcl from "@onflow/fcl" | ||
* @param price: import * as fcl from "@onflow/fcl" | ||
* @example createList("MatrixMarketplaceNFT", "0x7f3812b53dd4de20", 3, 3.14) | ||
*/ | ||
createList(supportedNFTName: string, supportedNFTAddress: string, nftId: number, price: string): Promise<string>; | ||
/** | ||
* @async | ||
* @param supportedNFTName: NFT collection name | ||
* @param supportedNFTAddress: NFT collection contract address | ||
* @param listingResourceId: listing id | ||
* @param sellerAddress: seller's address | ||
* @example purchaseList("MatrixMarketplaceNFT", "0x7f3812b53dd4de20", 31425, "0x9a0766d93b6608b7") | ||
*/ | ||
purchaseList(supportedNFTName: string, supportedNFTAddress: string, listingResourceId: number, sellerAddress: string): Promise<string>; | ||
/** | ||
* @async invoke by listing owner | ||
* @param listingResourceId: listing id | ||
* @example removeList(31425) | ||
*/ | ||
removeList(listingResourceID: number): Promise<string>; | ||
/** | ||
* @async | ||
* @param account: account's address | ||
* @example getListingIds("0x9a0766d93b6608b7") | ||
*/ | ||
getListingIds(account: string): Promise<[number]>; | ||
import * as fcl from "@onflow/fcl"; | ||
export const getListingIdsScript: string = fcl.script` | ||
import NonFungibleToken from 0xNON_FUNGIBLE_TOKEN_ADDRESS | ||
import NFTStorefront from 0xNFT_STOREFRONT | ||
@@ -6,0 +5,0 @@ |
@@ -6,6 +6,8 @@ import {FlowEnv} from "./env"; | ||
bindFcl(fcl: any, env: FlowEnv): Promise<void>; | ||
checkStorefront(address: string): Promise<boolean>; | ||
initStorefront(): Promise<string>; | ||
createList(supportedNFTName: string, supportedNFTAddress: string, nftId: number, price: string): Promise<string>; | ||
purchaseList(supportedNFTName: string, supportedNFTAddress: string, listingResourceId: number, adminAddress: string): Promise<string>; | ||
purchaseList(supportedNFTName: string, supportedNFTAddress: string, listingResourceId: number, sellerAddress: string): Promise<string>; | ||
removeList(listingResourceID: number): Promise<string>; | ||
getListingIds(account: string): Promise<[number]>; | ||
} |
@@ -9,2 +9,3 @@ import * as t from "@onflow/types"; | ||
import {getListingIdsScript} from "../cadence/get_listing_ids"; | ||
import {checkStorefront} from "../cadence/check_storefront" | ||
@@ -14,3 +15,3 @@ export class StorefrontClient implements IStorefrontClient { | ||
private fcl: any; | ||
private env: FlowEnv; | ||
private env: FlowEnv | undefined; | ||
@@ -63,3 +64,2 @@ public async bindFcl(fcl: any, env: FlowEnv): Promise<void> { | ||
* @async | ||
* @param {FlowEnv} env - FlowEnv.{localEmulator, flowTestnet, flowMainnet} | ||
* @param {key} - example:"0xNFT_ADDRESS" | ||
@@ -92,9 +92,20 @@ * @param {value} - example:"0x7f3812b53dd4de20" | ||
public async createList(supportedNFTName: string, supportedNFTAddress: string, nftId: number, price: string): Promise<string> { | ||
public async checkStorefront(address: string): Promise<boolean> { | ||
try { | ||
await this.setupFcl("supportedNFTName", supportedNFTName); | ||
await this.setupFcl("supportedNFTAddress", supportedNFTAddress); | ||
const response = await this.fcl.send([ | ||
createListingScript, | ||
this.fcl.args([this.fcl.arg(nftId, t.UInt64), this.fcl.arg(price, t.UFix64)]), | ||
checkStorefront, | ||
this.fcl.args([this.fcl.arg(address, t.Address)]), | ||
this.fcl.limit(1000) | ||
]); | ||
return this.fcl.decode(response); | ||
} catch (error) { | ||
console.error(error); | ||
return Promise.reject(error); | ||
} | ||
} | ||
public async initStorefront(): Promise<string> { | ||
try { | ||
const response = await this.fcl.send([ | ||
initStorefront, | ||
this.fcl.proposer(this.fcl.currentUser().authorization), | ||
@@ -116,3 +127,3 @@ this.fcl.authorizations([this.fcl.currentUser().authorization]), | ||
public async purchaseList(supportedNFTName: string, supportedNFTAddress: string, listingResourceId: number, adminAddress: string): Promise<string> { | ||
public async createList(supportedNFTName: string, supportedNFTAddress: string, nftId: number, price: string): Promise<string> { | ||
try { | ||
@@ -122,4 +133,4 @@ await this.setupFcl("supportedNFTName", supportedNFTName); | ||
const response = await this.fcl.send([ | ||
purchaseListingScript, | ||
this.fcl.args([this.fcl.arg(listingResourceId, t.UInt64), this.fcl.arg(adminAddress, t.Address)]), | ||
createListingScript, | ||
this.fcl.args([this.fcl.arg(nftId, t.UInt64), this.fcl.arg(price, t.UFix64)]), | ||
this.fcl.proposer(this.fcl.currentUser().authorization), | ||
@@ -141,7 +152,9 @@ this.fcl.authorizations([this.fcl.currentUser().authorization]), | ||
public async removeList(listingResourceID: number): Promise<string> { | ||
public async purchaseList(supportedNFTName: string, supportedNFTAddress: string, listingResourceId: number, sellerAddress: string): Promise<string> { | ||
try { | ||
await this.setupFcl("supportedNFTName", supportedNFTName); | ||
await this.setupFcl("supportedNFTAddress", supportedNFTAddress); | ||
const response = await this.fcl.send([ | ||
removeListingScript, | ||
this.fcl.args([this.fcl.arg(listingResourceID, t.UInt64)]), | ||
purchaseListingScript, | ||
this.fcl.args([this.fcl.arg(listingResourceId, t.UInt64), this.fcl.arg(sellerAddress, t.Address)]), | ||
this.fcl.proposer(this.fcl.currentUser().authorization), | ||
@@ -163,6 +176,7 @@ this.fcl.authorizations([this.fcl.currentUser().authorization]), | ||
public async initStorefront(): Promise<string> { | ||
public async removeList(listingResourceID: number): Promise<string> { | ||
try { | ||
const response = await this.fcl.send([ | ||
initStorefront, | ||
removeListingScript, | ||
this.fcl.args([this.fcl.arg(listingResourceID, t.UInt64)]), | ||
this.fcl.proposer(this.fcl.currentUser().authorization), | ||
@@ -184,3 +198,3 @@ this.fcl.authorizations([this.fcl.currentUser().authorization]), | ||
public async getListingIds(account: string): Promise<string> { | ||
public async getListingIds(account: string): Promise<[number]> { | ||
try { | ||
@@ -187,0 +201,0 @@ const response = await this.fcl.send([getListingIdsScript, this.fcl.args([this.fcl.arg(account, t.Address)])]); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75934
50
943
64
1