• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Mintbase / mintbase-js / 5268867622

pending completion
5268867622

push

github

sainthiago
:alien: update token attributes props

605 of 821 branches covered (73.69%)

Branch coverage included in aggregate %.

905 of 976 relevant lines covered (92.73%)

4.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.52
/packages/sdk/src/buy/buy.ts
1
/* eslint-disable @typescript-eslint/camelcase */
2
import { mbjs } from '../config/config';
1✔
3
import { MAX_GAS, ONE_YOCTO  } from '../constants';
1✔
4
import { ERROR_MESSAGES } from '../errorMessages';
1✔
5
import { BuyArgs, BuyArgsFtResponse, BuyArgsResponse, FT_METHOD_NAMES, MARKET_METHOD_NAMES, NearContractCall } from '../types';
1✔
6

7
//todo make a buy at listed price method
8

9
/**
10
 * Buys a listed token for a specified price as long as its above the price for which is was listed
11
 * @param buyArguments {@link BuyArgs}
12
 * @returns contract call to be passed to @mintbase-js/sdk execute method
13
 */
14
export const buy = (args: BuyArgs): NearContractCall<BuyArgsResponse | BuyArgsFtResponse> => {
1✔
15
  const { contractAddress = mbjs.keys.contractAddress, tokenId, referrerId = null, marketId = mbjs.keys.marketAddress, price, affiliateAccount } = args;
3!
16

17
  if (contractAddress == null) {
3!
18
    throw new Error(ERROR_MESSAGES.CONTRACT_ADDRESS);
×
19
  }
20

21
  if (args.ftAddress) {
3✔
22
    if (!Object.values(mbjs.keys.ftAddresses).includes(args.ftAddress)) {
2!
23
      throw new Error(ERROR_MESSAGES.UNSUPPORTED_FT);
×
24
    }
25

26
    return {
2✔
27
      contractAddress: args.ftAddress,
28
      args: {
29
        receiver_id: marketId || mbjs.keys.marketAddress,
2!
30
        amount: price,
31
        msg: JSON.stringify({
32
          nft_contract_id: contractAddress || mbjs.keys.contractAddress,
2!
33
          token_id: tokenId,
34
        }),
35
      },
36
      methodName: FT_METHOD_NAMES.FT_TRANSFER_CALL,
37
      gas: MAX_GAS,
38
      deposit: ONE_YOCTO,
39
    };
40
  }
41

42
  return {
1✔
43
    contractAddress: marketId || mbjs.keys.marketAddress,
1!
44
    args: {
45
      nft_contract_id: contractAddress || mbjs.keys.contractAddress,
1!
46
      token_id: tokenId,
47
      referrer_id: affiliateAccount || referrerId,
1!
48
    },
49
    methodName: MARKET_METHOD_NAMES.BUY,
50
    gas: MAX_GAS,
51
    deposit: price,
52
  };
53
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc