Skip to content

Commit

Permalink
Update near-api-js to v3 (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored Jul 3, 2024
1 parent 0cd1490 commit 709057e
Show file tree
Hide file tree
Showing 17 changed files with 3,692 additions and 5,971 deletions.
9,461 changes: 3,669 additions & 5,792 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,10 @@
"eslint-plugin-simple-import-sort": "^5.0.3",
"fetch-mock": "^9.11.0",
"graphql": "^16.6.0",
"isomorphic-fetch": "^3.0.0",
"jest": "^29.1.1",
"jest-environment-jsdom": "^29.1.2",
"lerna": "^7.0.0",
"lerna": "^8.0.0",
"lerna-jest": "^0.5.4",
"serve": "^14.0.1",
"superagent": "^8.0.3",
"ts-jest": "^29.0.3",
"typescript": "^4.8.4",
"@near-wallet-selector/wallet-utils": "^8.9.7"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { META_SERVICE_HOST_TESTNET } from '../../constants';
import { OWNED_MINTED_ORDER_BY, ParsedDataReturn, UserTokensFilter, UserTokensQueryResult } from '../../types';
import { OWNED_MINTED_ORDER_BY, ParsedDataReturn, UserTokensQueryResult } from '../../types';
import fetchMock from 'fetch-mock';
import { Network, mbjs } from '@mintbase-js/sdk';
import { getUserMintedTokens } from '../userMintedTokens/userMintedTokens';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { META_SERVICE_HOST_TESTNET } from '../../constants';
import { OWNED_MINTED_ORDER_BY, ParsedDataReturn, UserTokensFilter, UserTokensQueryResult } from '../../types';
import { OWNED_MINTED_ORDER_BY, ParsedDataReturn, UserTokensQueryResult } from '../../types';

import fetchMock from 'fetch-mock';
import { Network, mbjs } from '@mintbase-js/sdk';
Expand Down
35 changes: 0 additions & 35 deletions packages/react/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react/src/MintbaseWalletContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
// import { invokeContractMethod } from './transactions';
import React from 'react';
import { render, screen, act, waitFor } from '@testing-library/react';
import { act, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { useMbWallet, MintbaseWalletContextProvider } from './MintbaseWalletContext';
import {
Expand Down
32 changes: 0 additions & 32 deletions packages/react/src/hooks/methods/nearPrice.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/react/src/hooks/methods/nearPrice.types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react/src/hooks/useNearPrice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import { nearPrice } from './methods/nearPrice';
import { nearPrice } from '@mintbase-js/data';

type UseNearPriceReturn = {
nearPrice: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/rpc/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const callViewMethod = async <T>({
}: {
contractId: string;
method: string;
args?: Record<string, any>;
args?: Record<string, unknown>;
network?: string;
rpc?: RPC_OPTIONS;
}): Promise<T> => {
Expand Down
7 changes: 2 additions & 5 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
"license": "MIT",
"dependencies": {
"bn.js": "5.2.1",
"near-api-js": "^2.1.4"
},
"devDependencies": {
"@near-wallet-selector/core": "8.9.3"
}
"near-api-js": "^3.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dependencies": {
"@mintbase-js/sdk": "0.5.2-beta.0",
"form-data": "^4.0.0",
"near-api-js": "^2.1.4"
"near-api-js": "^3.0.0"
},
"devDependencies": {
"@types/node": "18.11.9"
Expand Down
1 change: 0 additions & 1 deletion packages/storage/src/node-uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
MAX_UPLOAD_BYTES,
MAX_UPLOAD_ERROR_MSG,
MINTBASE_API_ANON_USER,
MINTBASE_API_KEY_HEADER,
} from './constants';
import { ArweaveResponse } from './types';
/**
Expand Down
3 changes: 2 additions & 1 deletion packages/storage/src/uploadReference.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe('upload tests in browser', () => {
const result = await uploadReference(referenceObject);

const [call] = fetchMock.mock.calls;
expect((call as any)[1].headers['mb-api-key']).toBe(FAKE_API_KEY);
type Call = {headers: Record<string, string>}[]
expect((call as Call)[1].headers['mb-api-key']).toBe(FAKE_API_KEY);
expect(result).toEqual({
status: 200,
media_url: 'https://arweave.net/undefined',
Expand Down
6 changes: 1 addition & 5 deletions packages/wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
"author": "Mintbase",
"license": "MIT",
"dependencies": {
"@near-wallet-selector/core": "8.9.5",
"@near-wallet-selector/wallet-utils": "^8.9.5",
"bn.js": "^5.2.1",
"near-api-js": "^2.1.3"
},
"peerDependencies": {
"near-api-js": "^2.0.0"
"near-api-js": "^3.0.0"
}
}
91 changes: 11 additions & 80 deletions packages/wallet/src/mintbase-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@ import { getCallbackUrl } from './utils';
import { createAction } from '@near-wallet-selector/wallet-utils';


export enum TransactionSuccessEnum {
MINT = 'mint',
TRANSFER = 'transfer',
BURN = 'burn',
DEPLOY_STORE = 'deploy-store',
MAKE_OFFER = 'make-offer',
REVOKE_MINTER = 'revoke-minter',
ADD_MINTER = 'add-minter',
TRANSFER_STORE_OWNERSHIP = 'transfer-store-ownership',
AUCTION_LIST = 'list',
SIMPLE_SALE_LIST = 'simple-sale-list',
UNLIST = 'unlist',
TAKE_OFFER = 'take-offer',
WITHDRAW_OFFER = 'withdraw-offer',
}

interface MintbaseWalletState {
wallet: nearAPI.WalletConnection;
}
Expand All @@ -35,12 +19,6 @@ interface MintbaseWalletAccount {
publicKey: string;
}

export type CallBackArgs = {
args: object;
type: TransactionSuccessEnum;
}


export const MintbaseWallet: WalletBehaviourFactory<
BrowserWallet,
{
Expand Down Expand Up @@ -145,13 +123,6 @@ export const MintbaseWallet: WalletBehaviourFactory<
if (!state.wallet.isSignedIn()) {
throw new Error('Wallet not signed in');
}
//// near-api-js code fails if no lak
// const { cbUrl } = getCallbackUrl(callbackUrl ?? '');

// return state.wallet.requestSignTransactions({
// transactions: await transformTransactions(transactions),
// callbackUrl: cbUrl,
// });

const { cbUrl } = getCallbackUrl(callbackUrl ?? '');

Expand Down Expand Up @@ -202,7 +173,7 @@ export const MintbaseWallet: WalletBehaviourFactory<

return account.signAndSendTransaction({
receiverId: receiverId || contractId,
actions: actions.map((action) => createAction(action)) as any,
actions: actions.map((action) => createAction(action)) as nearAPI.transactions.Action[],
walletCallbackUrl: callback,
});
};
Expand Down Expand Up @@ -235,15 +206,15 @@ export const MintbaseWallet: WalletBehaviourFactory<
newUrl.searchParams.set('callbackUrl', callbackUrl);

try {
const response = await fetch(newUrl.toString())
const response = await fetch(newUrl.toString());
const data = await response.json();

const { isValid } = data
return isValid
const { isValid } = data;
return isValid;
} catch (e) {
return false
return false;
}
}
};

const getAvailableBalance = async (): Promise<void> => {
// const accountId = state.wallet.getAccountId();
Expand All @@ -254,15 +225,14 @@ export const MintbaseWallet: WalletBehaviourFactory<
const getAccounts = async (): Promise<MintbaseWalletAccount[]> => {
const accountId = state.wallet.getAccountId();
const account = state.wallet.account();
const currentAccount: string = window.localStorage.getItem(
'mintbase-wallet:account-creation-data',
);

if (!accountId || !account) {
if (!accountId || !account || !currentAccount) {
return [];
}

const currentAccount: string = window.localStorage.getItem(
'mintbase-wallet:account-creation-data',
)!;

return [
{
accountId,
Expand All @@ -285,45 +255,6 @@ export const MintbaseWallet: WalletBehaviourFactory<
return null;
};

// const transformTransactions = async (
// transactions: Array<Optional<Transaction, 'signerId'>>,
// ): Promise<Array<nearAPI.transactions.Transaction>> => {
// const account = state.wallet.account();
// const { networkId, signer, provider } = account.connection;

// const localKey = await signer.getPublicKey(account.accountId, networkId);

// return Promise.all(
// transactions.map(async (transaction, index) => {
// const actions = transaction.actions.map((action) =>
// createAction(action),
// );
// const accessKey = await account.accessKeyForTransaction(
// transaction.receiverId,
// actions as any,
// localKey,
// );

// if (!accessKey) {
// throw new Error(
// `Failed to find matching key for transaction sent to ${transaction.receiverId}`,
// );
// }

// const block = await provider.block({ finality: 'final' });

// return nearAPI.transactions.createTransaction(
// account.accountId,
// nearAPI.utils.PublicKey.from(accessKey.public_key),
// transaction.receiverId,
// accessKey.access_key.nonce + index + 1,
// actions as any,
// nearAPI.utils.serialize.base_decode(block.header.hash),
// );
// }),
// );
// };

return {
getAccountId,
isSignedIn,
Expand All @@ -336,6 +267,6 @@ export const MintbaseWallet: WalletBehaviourFactory<
getAccounts,
switchAccount,
signAndSendTransactions,
verifyMessage
verifyMessage,
};
};
1 change: 0 additions & 1 deletion packages/wallet/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Mintbase Wallet Utils file
*/


const checkCallbackUrl = (callbackUrl: string): string => {
function isValidURL(url): boolean {
const urlPattern = /^(https?|ftp|http?):\/\/[^\s/$.?#].[^\s]*$/;
Expand Down

0 comments on commit 709057e

Please sign in to comment.