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

Mintbase / mintbase-js / 8233788221

11 Mar 2024 01:38PM UTC coverage: 76.955%. First build
8233788221

Pull #486

github

sainthiago
add condition
Pull Request #486: Add allKeys param to mintbase-wallet

860 of 1307 branches covered (65.8%)

Branch coverage included in aggregate %.

1177 of 1340 relevant lines covered (87.84%)

13.24 hits per line

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

62.5
/packages/sdk/src/buy/buy.ts
1
/* eslint-disable @typescript-eslint/camelcase */
2
import { mbjs } from '../config/config';
3✔
3
import { MAX_GAS, ONE_YOCTO  } from '../constants';
3✔
4
import { ERROR_MESSAGES } from '../errorMessages';
3✔
5
import { BuyArgs, BuyArgsFtResponse, BuyArgsResponse, FT_METHOD_NAMES, MARKET_METHOD_NAMES, NearContractCall } from '../types';
3✔
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> => {
3✔
15
  const { contractAddress = mbjs.keys.contractAddress, tokenId, referrerId = null, marketId = mbjs.keys.marketAddress, price, affiliateAccount } = args;
9!
16

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

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

26
    return {
6✔
27
      contractAddress: args.ftAddress,
28
      args: {
29
        receiver_id: marketId || mbjs.keys.marketAddress,
4!
30
        amount: price,
31
        msg: JSON.stringify({
32
          nft_contract_id: contractAddress || mbjs.keys.contractAddress,
4!
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 {
3✔
43
    contractAddress: marketId || mbjs.keys.marketAddress,
2!
44
    args: {
45
      nft_contract_id: contractAddress || mbjs.keys.contractAddress,
2!
46
      token_id: tokenId,
47
      referrer_id: affiliateAccount || referrerId,
2!
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