-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
376 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { InMemoryKeyStore } from 'near-api-js/lib/key_stores'; | ||
import { connect } from './account'; | ||
import { NEAR_ENV } from './constants'; | ||
|
||
describe('connect', () => { | ||
it('should return an account with connection', async () => { | ||
const keyStore = new InMemoryKeyStore(); | ||
const account = await connect('mb_alice.testnet', keyStore, 'testnet'); | ||
expect(account.connection).not.toBeNull(); | ||
}); | ||
|
||
it('should default network to NEAR_ENV', async () => { | ||
const keyStore = new InMemoryKeyStore(); | ||
const account = await connect('mb_alice.testnet', keyStore); | ||
expect(account.connection.networkId).toBe(NEAR_ENV); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { connect as connectToNear, Account } from 'near-api-js'; | ||
import { KeyStore } from 'near-api-js/lib/key_stores'; | ||
import { NearNetwork, NEAR_ENV, NEAR_RPC_URL } from './constants'; | ||
|
||
/** | ||
* Connect to a NEAR account `accountId` with credentials in `keyStore` {@link KeyStore} | ||
* | ||
* @param call an array or single instance of {@link NearContractCall} to execute | ||
* @param signingOptions object containing either near wallet selector | ||
* wallet: {@link Wallet} or account: {@link Account}, defaults to wallet when present | ||
* @returns a result for single transactions of {@link FinalExecutionOutcome}, or void for batches | ||
*/ | ||
export const connect = async ( | ||
accountId: string, | ||
keyStore: KeyStore, | ||
network: NearNetwork = NEAR_ENV, | ||
): Promise<Account> => { | ||
const near = await connectToNear({ | ||
keyStore, | ||
networkId: network, | ||
nodeUrl: network === 'testnet' | ||
? NEAR_RPC_URL.TESTNET | ||
: NEAR_RPC_URL.MAINNET, | ||
headers: {}, | ||
}); | ||
return await near.account(accountId); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
/* eslint-disable max-len */ | ||
import type { NetworkId } from '@near-wallet-selector/core'; | ||
|
||
export const NEAR_WALLET_ENV = ( | ||
process.env.NEAR_WALLET_ENV || 'testnet' | ||
) as NetworkId; | ||
export type NearNetwork = 'mainnet' | 'testnet'; | ||
|
||
export const NEAR_ENV = ( | ||
process.env.NEAR_ENV || 'testnet' | ||
) as NearNetwork; | ||
|
||
// FIXME: these should probably live in sdk module | ||
export const DEFAULT_MINTBASE_CONTRACT_TESTNET = 'mintspace2.testnet'; | ||
export const DEFAULT_MINTBASE_CONTRACT_MAINNET = 'mintbase1.near'; | ||
|
||
export const NEAR_WALLET_SELECTOR_DEBUG = NEAR_WALLET_ENV === 'testnet'; | ||
export const NEAR_WALLET_SELECTOR_DEBUG = NEAR_ENV === 'testnet'; | ||
|
||
export const NEAR_LOGIN_CONTRACT_ID = process.env.NEAR_LOGIN_CONTRACT_ID; | ||
|
||
export const WALLET_CONNECTION_POLL_INTERVAL = 1_000; | ||
// how long to wait for the user to make the connection to the wallet. | ||
export const WALLET_CONNECTION_TIMEOUT = 30_000; | ||
|
||
export const NEAR_RPC_URL = { | ||
TESTNET: 'https://rpc.testnet.near.org', | ||
MAINNET: 'https://rpc.mainnet.near.org', | ||
}; | ||
|
||
// error messages | ||
export const WALLET_SETUP_NOT_CALLED_ERROR = 'Call and await setupWalletSelectorComponents() before registering a subscriber'; | ||
export const WALLET_CONNECTION_NOT_FOUND = `Wallet connection not recieved after ${WALLET_CONNECTION_TIMEOUT}ms`; | ||
export const WALLET_CONNECTION_NOT_FOUND = `Wallet connection not received after ${WALLET_CONNECTION_TIMEOUT}ms`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# @mintbase-js/sdk | ||
|
||
This module provides a set of convenience wrappers around invocation of Mintbase smart contract methods, but also exposes a low-level isomorphic [execute](#execute) method that can be passed raw `NearContractCall` information. | ||
|
||
Finish implementations and documentation for: | ||
|
||
- [ ] Transfer Token | ||
- [ ] Buy Token | ||
- [ ] List Token | ||
- [ ] Rest of the methods... | ||
|
||
Later TODOs: | ||
- [ ] Analytics via Opt in | ||
- [ ] Compute NEAR [gas fees](https://github.com/near/near-api-js/blob/master/packages/cookbook/utils/calculate-gas.js) and report consumption analytics | ||
|
||
# execute(callOptions, signingOptions) | ||
|
||
`execute` is the Core method used to invoke smart contract methods via browser [wallet](https://github.com/near/wallet-selector) or an authenticated NEAR Account via [functionCall](https://docs.near.org/tools/near-api-js/reference/classes/account.Account#functioncall) method. | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.