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

Mintbase / mintbase-js / 10668820689

02 Sep 2024 02:16PM UTC coverage: 72.702%. First build
10668820689

Pull #534

github

rubenmarcus
react package
Pull Request #534: remove browser wallet check

877 of 1390 branches covered (63.09%)

Branch coverage included in aggregate %.

1195 of 1460 relevant lines covered (81.85%)

13.35 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
import { mbjs } from '../config/config';
3✔
2
import { MAX_GAS, ONE_YOCTO  } from '../constants';
3✔
3
import { ERROR_MESSAGES } from '../errorMessages';
3✔
4
import { BuyArgs, BuyArgsFtResponse, BuyArgsResponse, FT_METHOD_NAMES, MARKET_METHOD_NAMES, NearContractCall, USDC_ADDRESS, USDT_ADDRESS } from '../types';
3✔
5

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

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

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

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

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

41
  return {
3✔
42
    contractAddress: marketId || mbjs.keys.marketAddress,
2!
43
    args: {
44
      nft_contract_id: contractAddress || mbjs.keys.contractAddress,
2!
45
      token_id: tokenId,
46
      referrer_id: affiliateAccount || referrerId,
2!
47
    },
48
    methodName: MARKET_METHOD_NAMES.BUY,
49
    gas: MAX_GAS,
50
    deposit: price,
51
  };
52
};
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