@matrix-labs/matrix-storefront-sdk
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -14,6 +14,6 @@ import { FlowEnv } from "./env"; | ||
initStorefront(): Promise<string>; | ||
createList(supportedNFTName: string, supportedNFTAddress: string, royaltyReceivers: [string], royaltyMount: [string], nftId: number, price: string): Promise<string>; | ||
createList(supportedNFTName: string, supportedNFTAddress: string, royaltyReceivers: string[], royaltyMount: string[], nftId: number, price: string): Promise<string>; | ||
purchaseList(supportedNFTName: string, supportedNFTAddress: string, listingResourceId: number, sellerAddress: string): Promise<string>; | ||
removeList(listingResourceID: number): Promise<string>; | ||
getListingIds(account: string): Promise<[number]>; | ||
getListingIds(account: string): Promise<number[]>; | ||
} |
@@ -10,6 +10,6 @@ import { IBindConfigs, IStorefrontClient } from "./IStorefrontClient"; | ||
initStorefront(): Promise<string>; | ||
createList(supportedNFTName: string, supportedNFTAddress: string, royaltyReceivers: [string], royaltyMount: [string], nftId: number, price: string): Promise<string>; | ||
createList(supportedNFTName: string, supportedNFTAddress: string, royaltyReceivers: string[], royaltyMount: string[], nftId: number, price: string): Promise<string>; | ||
purchaseList(supportedNFTName: string, supportedNFTAddress: string, listingResourceId: number, sellerAddress: string): Promise<string>; | ||
removeList(listingResourceID: number): Promise<string>; | ||
getListingIds(account: string): Promise<[number]>; | ||
getListingIds(account: string): Promise<number[]>; | ||
} |
@@ -25,2 +25,11 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -37,177 +46,195 @@ exports.StorefrontClient = void 0; | ||
class StorefrontClient { | ||
async bindFcl(fcl, env, config) { | ||
this.env = env; | ||
this.fcl = fcl; | ||
switch (env) { | ||
case env_1.FlowEnv.flowTestnet: { | ||
await this.fcl | ||
.config() | ||
.put("accessNode.api", "https://access-testnet.onflow.org") | ||
.put("challenge.handshake", "https://flow-wallet-testnet.blocto.app/authn") | ||
.put("0xFUNGIBLE_TOKEN_ADDRESS", config?.fungibleTokenAddress || "0x9a0766d93b6608b7") | ||
.put("0xFUSD_ADDRESS", config?.fusdAddress || "0xe223d8a629e49c68") | ||
.put("0xFLOW_TOKEN_ADDRESS", config?.flowTokenAddress || "0x7e60df042a9c0868") | ||
.put("0xNFT_STOREFRONT", config?.nftStorefront || "0xa56c5e5fd9b9ca22") | ||
.put("0xNON_FUNGIBLE_TOKEN_ADDRESS", config?.nonFungibleTokenAddress || "0x631e88ae7f1d7c20"); | ||
break; | ||
bindFcl(fcl, env, config) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.env = env; | ||
this.fcl = fcl; | ||
switch (env) { | ||
case env_1.FlowEnv.flowTestnet: { | ||
yield this.fcl | ||
.config() | ||
.put("accessNode.api", "https://access-testnet.onflow.org") | ||
.put("challenge.handshake", "https://flow-wallet-testnet.blocto.app/authn") | ||
.put("0xFUNGIBLE_TOKEN_ADDRESS", (config === null || config === void 0 ? void 0 : config.fungibleTokenAddress) || "0x9a0766d93b6608b7") | ||
.put("0xFUSD_ADDRESS", (config === null || config === void 0 ? void 0 : config.fusdAddress) || "0xe223d8a629e49c68") | ||
.put("0xFLOW_TOKEN_ADDRESS", (config === null || config === void 0 ? void 0 : config.flowTokenAddress) || "0x7e60df042a9c0868") | ||
.put("0xNFT_STOREFRONT", (config === null || config === void 0 ? void 0 : config.nftStorefront) || "0xa56c5e5fd9b9ca22") | ||
.put("0xNON_FUNGIBLE_TOKEN_ADDRESS", (config === null || config === void 0 ? void 0 : config.nonFungibleTokenAddress) || "0x631e88ae7f1d7c20"); | ||
break; | ||
} | ||
case env_1.FlowEnv.flowMainnet: { | ||
yield this.fcl | ||
.config() | ||
.put("accessNode.api", "https://flow-access-mainnet.portto.io") | ||
.put("challenge.handshake", "https://flow-wallet.blocto.app/authn") | ||
.put("0xFUNGIBLE_TOKEN_ADDRESS", (config === null || config === void 0 ? void 0 : config.fungibleTokenAddress) || "0xf233dcee88fe0abe") | ||
.put("0xFUSD_ADDRESS", (config === null || config === void 0 ? void 0 : config.fusdAddress) || "0x3c5959b568896393") | ||
.put("0xFLOW_TOKEN_ADDRESS", (config === null || config === void 0 ? void 0 : config.flowTokenAddress) || "0x1654653399040a61") | ||
.put("0xNFT_STOREFRONT", (config === null || config === void 0 ? void 0 : config.nftStorefront) || "") | ||
.put("0xNON_FUNGIBLE_TOKEN_ADDRESS", (config === null || config === void 0 ? void 0 : config.nonFungibleTokenAddress) || "0x1d7e57aa55817448"); | ||
break; | ||
} | ||
case env_1.FlowEnv.localEmulator: | ||
default: | ||
yield this.fcl | ||
.config() | ||
.put("accessNode.api", "http://localhost:8080") | ||
.put("discovery.wallet", "http://localhost:8701/fcl/authn") | ||
.put("0xFUNGIBLE_TOKEN_ADDRESS", (config === null || config === void 0 ? void 0 : config.fungibleTokenAddress) || "0xee82856bf20e2aa6") | ||
.put("0xFUSD_ADDRESS", (config === null || config === void 0 ? void 0 : config.fusdAddress) || "0xf8d6e0586b0a20c7") | ||
.put("0xFLOW_TOKEN_ADDRESS", (config === null || config === void 0 ? void 0 : config.flowTokenAddress) || "0x0ae53cb6e3f42a79") | ||
.put("0xNFT_STOREFRONT", (config === null || config === void 0 ? void 0 : config.nftStorefront) || "0xf8d6e0586b0a20c7") | ||
.put("0xNON_FUNGIBLE_TOKEN_ADDRESS", (config === null || config === void 0 ? void 0 : config.nonFungibleTokenAddress) || "0xf8d6e0586b0a20c7"); | ||
} | ||
case env_1.FlowEnv.flowMainnet: { | ||
await this.fcl | ||
.config() | ||
.put("accessNode.api", "https://flow-access-mainnet.portto.io") | ||
.put("challenge.handshake", "https://flow-wallet.blocto.app/authn") | ||
.put("0xFUNGIBLE_TOKEN_ADDRESS", config?.fungibleTokenAddress || "0xf233dcee88fe0abe") | ||
.put("0xFUSD_ADDRESS", config?.fusdAddress || "0x3c5959b568896393") | ||
.put("0xFLOW_TOKEN_ADDRESS", config?.flowTokenAddress || "0x1654653399040a61") | ||
.put("0xNFT_STOREFRONT", config?.nftStorefront || "") | ||
.put("0xNON_FUNGIBLE_TOKEN_ADDRESS", config?.nonFungibleTokenAddress || "0x1d7e57aa55817448"); | ||
break; | ||
}); | ||
} | ||
setupFcl(key, value) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
switch (this.env) { | ||
case env_1.FlowEnv.flowTestnet: { | ||
yield this.fcl | ||
.config() | ||
.put(key, value); | ||
break; | ||
} | ||
case env_1.FlowEnv.flowTestnet: { | ||
yield this.fcl | ||
.config() | ||
.put(key, value); | ||
break; | ||
} | ||
case env_1.FlowEnv.flowTestnet: { | ||
yield this.fcl | ||
.config() | ||
.put(key, value); | ||
break; | ||
} | ||
} | ||
case env_1.FlowEnv.localEmulator: | ||
default: | ||
await this.fcl | ||
.config() | ||
.put("accessNode.api", "http://localhost:8080") | ||
.put("discovery.wallet", "http://localhost:8701/fcl/authn") | ||
.put("0xFUNGIBLE_TOKEN_ADDRESS", config?.fungibleTokenAddress || "0xee82856bf20e2aa6") | ||
.put("0xFUSD_ADDRESS", config?.fusdAddress || "0xf8d6e0586b0a20c7") | ||
.put("0xFLOW_TOKEN_ADDRESS", config?.flowTokenAddress || "0x0ae53cb6e3f42a79") | ||
.put("0xNFT_STOREFRONT", config?.nftStorefront || "0xf8d6e0586b0a20c7") | ||
.put("0xNON_FUNGIBLE_TOKEN_ADDRESS", config?.nonFungibleTokenAddress || "0xf8d6e0586b0a20c7"); | ||
} | ||
}); | ||
} | ||
async setupFcl(key, value) { | ||
switch (this.env) { | ||
case env_1.FlowEnv.flowTestnet: { | ||
await this.fcl | ||
.config() | ||
.put(key, value); | ||
break; | ||
checkStorefront(address) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const response = yield this.fcl.send([ | ||
check_storefront_1.checkStorefront, | ||
this.fcl.args([this.fcl.arg(address, t.Address)]), | ||
this.fcl.limit(2000) | ||
]); | ||
return this.fcl.decode(response); | ||
} | ||
case env_1.FlowEnv.flowTestnet: { | ||
await this.fcl | ||
.config() | ||
.put(key, value); | ||
break; | ||
catch (error) { | ||
console.error(error); | ||
return Promise.reject(error); | ||
} | ||
case env_1.FlowEnv.flowTestnet: { | ||
await this.fcl | ||
.config() | ||
.put(key, value); | ||
break; | ||
}); | ||
} | ||
initStorefront() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const response = yield this.fcl.send([ | ||
init_storefront_1.initStorefront, | ||
this.fcl.proposer(this.fcl.currentUser().authorization), | ||
this.fcl.authorizations([this.fcl.currentUser().authorization]), | ||
this.fcl.limit(2000), | ||
this.fcl.payer(this.fcl.currentUser().authorization) | ||
]); | ||
const ret = yield this.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); | ||
} | ||
}); | ||
} | ||
async checkStorefront(address) { | ||
try { | ||
const response = await this.fcl.send([ | ||
check_storefront_1.checkStorefront, | ||
this.fcl.args([this.fcl.arg(address, t.Address)]), | ||
this.fcl.limit(2000) | ||
]); | ||
return this.fcl.decode(response); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
return Promise.reject(error); | ||
} | ||
} | ||
async initStorefront() { | ||
try { | ||
const response = await this.fcl.send([ | ||
init_storefront_1.initStorefront, | ||
this.fcl.proposer(this.fcl.currentUser().authorization), | ||
this.fcl.authorizations([this.fcl.currentUser().authorization]), | ||
this.fcl.limit(2000), | ||
this.fcl.payer(this.fcl.currentUser().authorization) | ||
]); | ||
const ret = await this.fcl.tx(response).onceSealed(); | ||
if (ret.errorMessage !== "" && ret.status != 4) { | ||
return Promise.reject(ret.errorMessage); | ||
createList(supportedNFTName, supportedNFTAddress, royaltyReceivers, royaltyMount, nftId, price) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield this.setupFcl("0xsupportedNFTAddress", supportedNFTAddress); | ||
yield this.setupFcl("0xsupportedNFTName", supportedNFTName); | ||
const response = yield this.fcl.send([ | ||
this.fcl.transaction(create_list_1.createListingScript.replace("0xsupportedNFTName", supportedNFTName)), | ||
this.fcl.args([this.fcl.arg(royaltyReceivers, t.Array(t.Address)), this.fcl.arg(royaltyMount, t.Array(t.UFix64)), this.fcl.arg(nftId, t.UInt64), this.fcl.arg(price, t.UFix64)]), | ||
this.fcl.proposer(this.fcl.currentUser().authorization), | ||
this.fcl.authorizations([this.fcl.currentUser().authorization]), | ||
this.fcl.limit(3000), | ||
this.fcl.payer(this.fcl.currentUser().authorization) | ||
]); | ||
const ret = yield this.fcl.tx(response).onceSealed(); | ||
if (ret.errorMessage !== "" && ret.status != 4) { | ||
return Promise.reject(ret.errorMessage); | ||
} | ||
return response.transactionId; | ||
} | ||
return response.transactionId; | ||
} | ||
catch (error) { | ||
console.error(error); | ||
return Promise.reject(error); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
return Promise.reject(error); | ||
} | ||
}); | ||
} | ||
async createList(supportedNFTName, supportedNFTAddress, royaltyReceivers, royaltyMount, nftId, price) { | ||
try { | ||
await this.setupFcl("0xsupportedNFTAddress", supportedNFTAddress); | ||
const response = await this.fcl.send([ | ||
this.fcl.transaction(create_list_1.createListingScript.replace("0xsupportedNFTName", supportedNFTName)), | ||
this.fcl.args([this.fcl.arg(royaltyReceivers, t.Array(t.Address)), this.fcl.arg(royaltyMount, t.Array(t.UFix64)), this.fcl.arg(nftId, t.UInt64), this.fcl.arg(price, t.UFix64)]), | ||
this.fcl.proposer(this.fcl.currentUser().authorization), | ||
this.fcl.authorizations([this.fcl.currentUser().authorization]), | ||
this.fcl.limit(3000), | ||
this.fcl.payer(this.fcl.currentUser().authorization) | ||
]); | ||
const ret = await this.fcl.tx(response).onceSealed(); | ||
if (ret.errorMessage !== "" && ret.status != 4) { | ||
return Promise.reject(ret.errorMessage); | ||
purchaseList(supportedNFTName, supportedNFTAddress, listingResourceId, sellerAddress) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield this.setupFcl("0xsupportedNFTAddress", supportedNFTAddress); | ||
yield this.setupFcl("0xsupportedNFTName", supportedNFTName); | ||
const response = yield this.fcl.send([ | ||
this.fcl.transaction(purchase_list_1.purchaseListingScript.replace("0xsupportedNFTName", supportedNFTName)), | ||
this.fcl.args([this.fcl.arg(listingResourceId, t.UInt64), this.fcl.arg(sellerAddress, t.Address)]), | ||
this.fcl.proposer(this.fcl.currentUser().authorization), | ||
this.fcl.authorizations([this.fcl.currentUser().authorization]), | ||
this.fcl.limit(2000), | ||
this.fcl.payer(this.fcl.currentUser().authorization) | ||
]); | ||
const ret = yield this.fcl.tx(response).onceSealed(); | ||
if (ret.errorMessage !== "" && ret.status != 4) { | ||
return Promise.reject(ret.errorMessage); | ||
} | ||
return response.transactionId; | ||
} | ||
return response.transactionId; | ||
} | ||
catch (error) { | ||
console.error(error); | ||
return Promise.reject(error); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
return Promise.reject(error); | ||
} | ||
}); | ||
} | ||
async purchaseList(supportedNFTName, supportedNFTAddress, listingResourceId, sellerAddress) { | ||
try { | ||
await this.setupFcl("0xsupportedNFTAddress", supportedNFTAddress); | ||
const response = await this.fcl.send([ | ||
this.fcl.transaction(purchase_list_1.purchaseListingScript.replace("0xsupportedNFTName", supportedNFTName)), | ||
this.fcl.args([this.fcl.arg(listingResourceId, t.UInt64), this.fcl.arg(sellerAddress, t.Address)]), | ||
this.fcl.proposer(this.fcl.currentUser().authorization), | ||
this.fcl.authorizations([this.fcl.currentUser().authorization]), | ||
this.fcl.limit(2000), | ||
this.fcl.payer(this.fcl.currentUser().authorization) | ||
]); | ||
const ret = await this.fcl.tx(response).onceSealed(); | ||
if (ret.errorMessage !== "" && ret.status != 4) { | ||
return Promise.reject(ret.errorMessage); | ||
removeList(listingResourceID) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const response = yield this.fcl.send([ | ||
remove_list_1.removeListingScript, | ||
this.fcl.args([this.fcl.arg(listingResourceID, t.UInt64)]), | ||
this.fcl.proposer(this.fcl.currentUser().authorization), | ||
this.fcl.authorizations([this.fcl.currentUser().authorization]), | ||
this.fcl.limit(2000), | ||
this.fcl.payer(this.fcl.currentUser().authorization) | ||
]); | ||
const ret = yield this.fcl.tx(response).onceSealed(); | ||
if (ret.errorMessage !== "" && ret.status != 4) { | ||
return Promise.reject(ret.errorMessage); | ||
} | ||
return response.transactionId; | ||
} | ||
return response.transactionId; | ||
} | ||
catch (error) { | ||
console.error(error); | ||
return Promise.reject(error); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
return Promise.reject(error); | ||
} | ||
}); | ||
} | ||
async removeList(listingResourceID) { | ||
try { | ||
const response = await this.fcl.send([ | ||
remove_list_1.removeListingScript, | ||
this.fcl.args([this.fcl.arg(listingResourceID, t.UInt64)]), | ||
this.fcl.proposer(this.fcl.currentUser().authorization), | ||
this.fcl.authorizations([this.fcl.currentUser().authorization]), | ||
this.fcl.limit(2000), | ||
this.fcl.payer(this.fcl.currentUser().authorization) | ||
]); | ||
const ret = await this.fcl.tx(response).onceSealed(); | ||
if (ret.errorMessage !== "" && ret.status != 4) { | ||
return Promise.reject(ret.errorMessage); | ||
getListingIds(account) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const response = yield this.fcl.send([get_listing_ids_1.getListingIdsScript, this.fcl.args([this.fcl.arg(account, t.Address)])]); | ||
console.log(response); | ||
return this.fcl.decode(response); | ||
} | ||
return response.transactionId; | ||
} | ||
catch (error) { | ||
console.error(error); | ||
return Promise.reject(error); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
return Promise.reject(error); | ||
} | ||
}); | ||
} | ||
async getListingIds(account) { | ||
try { | ||
const response = await this.fcl.send([get_listing_ids_1.getListingIdsScript, this.fcl.args([this.fcl.arg(account, t.Address)])]); | ||
console.log(response); | ||
return this.fcl.decode(response); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
return Promise.reject(error); | ||
} | ||
} | ||
} | ||
exports.StorefrontClient = StorefrontClient; | ||
//# sourceMappingURL=StorefrontClient.js.map |
{ | ||
"name": "@matrix-labs/matrix-storefront-sdk", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"main": "./dist/index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -16,6 +16,6 @@ import {FlowEnv} from "./env"; | ||
initStorefront(): Promise<string>; | ||
createList(supportedNFTName: string, supportedNFTAddress: string, royaltyReceivers: [string], royaltyMount: [string], nftId: number, price: string): Promise<string>; | ||
createList(supportedNFTName: string, supportedNFTAddress: string, royaltyReceivers: string[], royaltyMount: string[], nftId: number, price: string): Promise<string>; | ||
purchaseList(supportedNFTName: string, supportedNFTAddress: string, listingResourceId: number, sellerAddress: string): Promise<string>; | ||
removeList(listingResourceID: number): Promise<string>; | ||
getListingIds(account: string): Promise<[number]>; | ||
getListingIds(account: string): Promise<number[]>; | ||
} |
@@ -122,5 +122,6 @@ import * as t from "@onflow/types"; | ||
public async createList(supportedNFTName: string, supportedNFTAddress: string, royaltyReceivers: [string], royaltyMount: [string], nftId: number, price: string): Promise<string> { | ||
public async createList(supportedNFTName: string, supportedNFTAddress: string, royaltyReceivers: string[], royaltyMount: string[], nftId: number, price: string): Promise<string> { | ||
try { | ||
await this.setupFcl("0xsupportedNFTAddress", supportedNFTAddress); | ||
await this.setupFcl("0xsupportedNFTName", supportedNFTName); | ||
const response = await this.fcl.send([ | ||
@@ -148,2 +149,3 @@ this.fcl.transaction(createListingScript.replace("0xsupportedNFTName", supportedNFTName)), | ||
await this.setupFcl("0xsupportedNFTAddress", supportedNFTAddress); | ||
await this.setupFcl("0xsupportedNFTName", supportedNFTName); | ||
const response = await this.fcl.send([ | ||
@@ -189,3 +191,3 @@ this.fcl.transaction(purchaseListingScript.replace("0xsupportedNFTName", supportedNFTName)), | ||
public async getListingIds(account: string): Promise<[number]> { | ||
public async getListingIds(account: string): Promise<number[]> { | ||
try { | ||
@@ -192,0 +194,0 @@ const response = await this.fcl.send([getListingIdsScript, this.fcl.args([this.fcl.arg(account, t.Address)])]); |
@@ -5,3 +5,3 @@ { | ||
"incremental": true, | ||
"target": "es2020", | ||
"target": "ES6", | ||
"module": "commonjs", | ||
@@ -8,0 +8,0 @@ "declaration": true, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
79548
955
49