Skip to content

Commit 068ce95

Browse files
committed
docs
1 parent d5fca11 commit 068ce95

File tree

4 files changed

+134
-61
lines changed

4 files changed

+134
-61
lines changed

Changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# CHANGELOG
22

33
### JS SDK Version ChangeLog
4-
### v0.2.6
4+
### v0.2.8
5+
1) NFT refactory the interface fot doc
6+
### v0.2.7
57
1) NFT withdraw L2 -> L1
68
2) NFT Deposit L1 -> L2 (NFT approvedAll fot Exchange)
79
3) NFT Transfer L2 -> L2

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@loopring-web/loopring-sdk",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"author": "Loopring Dev Team",
55
"description": "Loopring SDK",
66
"private": false,

src/api/nft_api.ts

Lines changed: 42 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { myLog } from '../utils/log_tools';
55
import Web3 from 'web3';
66
import { genExchangeData, sendRawTx } from './contract_api';
77
import contracts from './ethereum/contracts';
8+
import { ApproveParam, ContractNFTMetaParam, DepositNFTParam, IsApproveParam } from '../defs/nft_defs';
89

910
export enum NFTType {
1011
ERC1155 = 0,
@@ -45,13 +46,12 @@ export class NFTAPI extends BaseAPI {
4546
type === NFTType.ERC1155 ? contracts.Contracts.erc1155Abi : contracts.Contracts.erc721Abi,
4647
contractAddress
4748
);
48-
49-
// new Contract(
50-
// type === NFTType.ERC1155 ? erc1155Abi : erc721Abi,
51-
// contractAddress
52-
// );
5349
}
5450

51+
/**
52+
* getInfoForNFTTokens
53+
* @param nftDatas NftData[]
54+
*/
5555
public async getInfoForNFTTokens({nftDatas}: { nftDatas: NftData[] }): Promise<{ [ key: string ]: NFTTokenInfo } | undefined> {
5656
try {
5757
const reqParams: ReqParams = {
@@ -74,27 +74,33 @@ export class NFTAPI extends BaseAPI {
7474
}
7575
}
7676

77+
/**
78+
* getContractNFTMeta
79+
* @param web3
80+
* @param tokenAddress
81+
* @param _id
82+
* @param nftType
83+
*/
7784
public async getContractNFTMeta({
7885
web3,
7986
tokenAddress,
8087
_id,
8188
nftType = NFTType.ERC1155,
82-
}: { web3: any, tokenAddress: string, _id: string, nftType?: NFTType }) {
89+
}: ContractNFTMetaParam) {
8390
try {
8491
const result = await this.callContractMethod(web3, NFTMethod.uri, [_id],
8592
tokenAddress,
8693
nftType)
8794
myLog(tokenAddress, '_id', _id, result);
8895
return await (fetch(result.replace('{id}', _id)).then(response => response.json()))
89-
9096
} catch (error) {
9197
return undefined
9298
}
9399

94100
}
95101

96102
/**
97-
*
103+
* approveNFT
98104
* @param web3
99105
* @param from The address that deposits the funds to the exchange
100106
* @param to The address deposits to
@@ -119,19 +125,7 @@ export class NFTAPI extends BaseAPI {
119125
chainId,
120126
nonce,
121127
sendByMetaMask = true
122-
}: {
123-
web3: Web3,
124-
from: string,
125-
depositAddress: string,
126-
tokenAddress: string,
127-
tokenId: string,
128-
nftType: NFTType,
129-
gasPrice: number,
130-
gasLimit: number,
131-
chainId: ChainId,
132-
nonce: number,
133-
sendByMetaMask?: boolean
134-
}) {
128+
}: ApproveParam) {
135129
let data: any;
136130

137131
if (nftType === NFTType.ERC1155) {
@@ -150,19 +144,21 @@ export class NFTAPI extends BaseAPI {
150144

151145
}
152146

147+
/**
148+
* isApprovedForAll
149+
* @param web3
150+
* @param from The address that deposits the funds to the exchange
151+
* @param exchangeAddress loopring exchange address
152+
* @param nftType NFTType
153+
* @param tokenAddress The address of NFT token
154+
*/
153155
public async isApprovedForAll({
154156
web3,
155157
from,
156158
exchangeAddress,
157159
nftType = NFTType.ERC1155,
158160
tokenAddress,
159-
}: {
160-
web3: Web3,
161-
from: string,
162-
exchangeAddress: string,
163-
nftType: NFTType,
164-
tokenAddress: string
165-
} // chainId: ChainId,
161+
}: IsApproveParam
166162
) {
167163

168164
try {
@@ -176,6 +172,23 @@ export class NFTAPI extends BaseAPI {
176172
}
177173
}
178174

175+
176+
/**
177+
* @DepositParam an NFT to the specified account.
178+
* @param web3
179+
* @param from The address that deposits the funds to the exchange
180+
* @param to The account owner's address receiving the funds
181+
* @param nftType The type of NFT contract address (ERC721/ERC1155/...)
182+
* @param tokenAddress The address of NFT token
183+
* @param nftID The token type 'id`.
184+
* @param amount The amount of tokens to deposit.
185+
* @param nonce: number,
186+
* @param gasPrice: number,
187+
* @param gasLimit: number,
188+
* @param extraData Optional extra data used by the deposit contract.
189+
* @param chainId 0|5
190+
* @param sendByMetaMask boolean
191+
*/
179192
public async depositNFT(
180193
{
181194
web3,
@@ -191,21 +204,7 @@ export class NFTAPI extends BaseAPI {
191204
nonce,
192205
extraData,
193206
sendByMetaMask = true
194-
}: {
195-
web3: Web3,
196-
from: string,
197-
exchangeAddress: string,
198-
nftType?: NFTType,
199-
tokenAddress: string,
200-
nftID: string,
201-
amount: number,
202-
gasPrice: number,
203-
gasLimit: number,
204-
chainId?: ChainId,
205-
nonce: number,
206-
extraData?: any,
207-
sendByMetaMask?: boolean
208-
}
207+
}: DepositNFTParam
209208
) {
210209
const data = genExchangeData(NFTMethod.depositNFT, {
211210
from,
@@ -226,20 +225,4 @@ export class NFTAPI extends BaseAPI {
226225
}
227226

228227

229-
/**
230-
* @description Deposits an NFT to the specified account.
231-
* @param web3
232-
* @param from The address that deposits the funds to the exchange
233-
* @param to The account owner's address receiving the funds
234-
* @param nftType The type of NFT contract address (ERC721/ERC1155/...)
235-
* @param tokenAddress The address of the token
236-
* @param nftID The token type 'id`.
237-
* @param amount The amount of tokens to deposit.
238-
* @param nonce: number,
239-
* @param gasPrice: number,
240-
* @param gasLimit: number,
241-
* @param extraData Optional extra data used by the deposit contract.
242-
* @param chainId 0|5
243-
* @param sendByMetaMask boolean
244-
*/
245228

src/defs/nft_defs.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import Web3 from 'web3';
2+
import { ChainId } from './web3_defs';
3+
import { NFTType } from '../api';
4+
5+
/**
6+
* @interface DepositNFTParam
7+
* @description an NFT to the specified account.
8+
* @property web3
9+
* @property DepositParam
10+
* @property from The address that deposits the funds to the exchange
11+
* @property to The account owner's address receiving the funds
12+
* @property nftType The type of NFT contract address (ERC721/ERC1155/...)
13+
* @property tokenAddress The address of the token
14+
* @property nftID The token type 'id`.
15+
* @property amount The amount of tokens to deposit.
16+
* @property nonce: number,
17+
* @property gasPrice: number,
18+
* @property gasLimit: number,
19+
* @property extraData Optional extra data used by the deposit contract.
20+
* @property chainId 0|5
21+
* @property sendByMetaMask boolean
22+
*/
23+
export interface DepositNFTParam {
24+
web3: Web3,
25+
from: string,
26+
exchangeAddress: string,
27+
nftType?: NFTType,
28+
tokenAddress: string,
29+
nftID: string,
30+
amount: number,
31+
gasPrice: number,
32+
gasLimit: number,
33+
chainId?: ChainId,
34+
nonce: number,
35+
extraData?: any,
36+
sendByMetaMask?: boolean
37+
}
38+
39+
/**
40+
* isApprovedForAll
41+
* @property web3
42+
* @property from The address that deposits the funds to the exchange
43+
* @property exchangeAddress loopring exchange address
44+
* @property nftType NFTType
45+
* @property tokenAddress The address of NFT token
46+
*/
47+
export interface IsApproveParam {
48+
web3: Web3,
49+
from: string,
50+
exchangeAddress: string,
51+
nftType: NFTType,
52+
tokenAddress: string
53+
}
54+
55+
/**
56+
* approveNFT
57+
* @property web3
58+
* @property from The address that deposits the funds to the exchange
59+
* @property to The address deposits to
60+
* @property loopringAddress loopring exchange Address
61+
* @property tokenId: the tokenId
62+
* @property chainId
63+
* @property nftType The type of NFT contract address (ERC721/ERC1155/...)
64+
* @property nonce
65+
* @property gasPrice
66+
* @property gasLimit
67+
* @property sendByMetaMask
68+
*/
69+
export interface ApproveParam {
70+
web3: Web3,
71+
from: string,
72+
depositAddress: string,
73+
tokenAddress: string,
74+
tokenId: string,
75+
nftType: NFTType,
76+
gasPrice: number,
77+
gasLimit: number,
78+
chainId: ChainId,
79+
nonce: number,
80+
sendByMetaMask?: boolean
81+
}
82+
83+
export interface ContractNFTMetaParam {
84+
web3: any,
85+
tokenAddress: string,
86+
_id: string,
87+
nftType?: NFTType
88+
}

0 commit comments

Comments
 (0)