Skip to content

Commit

Permalink
added getContractApi and getWalletApi features
Browse files Browse the repository at this point in the history
  • Loading branch information
wpdas committed Jan 12, 2024
1 parent 69c73c7 commit ed41f97
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,37 @@ export const contractApi = naxiosInstance.contractApi(onContractInitHandler)
export const walletApi = naxiosInstance.walletApi(onWalletInitHandler)
```

Or you can invoke them anytime:

```ts
// Invoking a Contract API
import { getContractApi } from '@wpdas/naxios'

// New contract instance
const contract = await getContractApi({
contractId: ANOTHER_CONTRACT_ID,
network: 'testnet',
})

const response = await contract.view('get_users', {
args: { limit: 5 },
})
```

```ts
// Invoking a Wallet API
import { getWalletApi } from '@wpdas/naxios'

// New wallet instance
const walletApi = await getWalletApi({
contractId: ANOTHER_CONTRACT_ID,
network: 'testnet',
})

// Open up the Signin Wallet Modal
walletApi.signInModal()
```

#### Contract API Reference

- `view`: Make a read-only call to retrieve information from the network.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wpdas/naxios",
"version": "1.0.2",
"version": "1.0.3",
"description": "Promise based NEAR Contract and NEAR Wallet client for browser",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { default as naxios } from './naxios'
export default naxios

export * from './naxios'
export * from './hooks'
export * from './managers/types'
20 changes: 19 additions & 1 deletion src/naxios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class naxios {
private network: Network
private walletSelectorModules: WalletModuleFactory[] = [setupMyNearWallet()]

constructor(config: Config) {
constructor(config: Omit<Config, 'onInit'>) {
this.contractId = config.contractId
this.network = config.network
if (config.walletSelectorModules) {
Expand Down Expand Up @@ -41,5 +41,23 @@ class naxios {
}
}

/** Get a New Instant Contract API */
export const getContractApi = (config: Omit<Config, 'onInit'>) => {
return new Promise<ContractManager>((resolve) => {
const contractInstance = new naxios(config).contractApi(() => {
resolve(contractInstance)
})
})
}

/** Get a New Instant Wallet API */
export const getWalletApi = (config: Omit<Config, 'onInit'>) => {
return new Promise<WalletManager>((resolve) => {
const walletInstance = new naxios(config).walletApi(() => {
resolve(walletInstance)
})
})
}

/** Naxios API */
export default naxios

0 comments on commit ed41f97

Please sign in to comment.