Skip to content

Commit

Permalink
♻️ πŸ“„ Transfer as example (#180)
Browse files Browse the repository at this point in the history
* πŸ“ ♻️ Move transfer and tests, add docs

* βœ… Add app testing, refactor ownedTokens method

* πŸ€– npm publish version  0.0.4-transfer-as-example.0

* ♻️ Move transfer out, rename v1 to lessen diff

* πŸ§ͺ Comments on integration test, mv for clarity

* πŸ“ Add more docs to transfer method

* ✏️ Fix code example mistake in docs

* πŸ€– npm publish version  0.0.4-transfer-as-example.1

* πŸ”₯ Unused npmignore

* πŸ€– npm publish version  0.0.4-transfer-as-example.2

* πŸ‘· Try using deployments

* πŸ€– npm publish version  0.0.4-transfer-as-example.3

Co-authored-by: mintbaseteam <eng@mintbase.io>
  • Loading branch information
cif and mintbaseteam committed Nov 21, 2022
1 parent e37dbf6 commit 8f8a9a7
Show file tree
Hide file tree
Showing 29 changed files with 419 additions and 153 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Build and Publish Docs
name: SDK Gitbook Sync

on:
release:
types: [released, prereleased]
# Remove me: Going rapid fire today on full docs improvement, running each time.
# Remove me: Going rapid fire on full docs improvement until we launch
push:

jobs:
Expand Down
37 changes: 36 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Packages to NPM
name: SDK Check & Publish

on:
release:
Expand Down Expand Up @@ -28,9 +28,26 @@ jobs:
run: |
npm ci
npm run bootstrap
npm run lint
npm run build
npm run test
- name: Aggregate LCOV results
uses: RauliL/lerna-lcov-aggregate-action@master

- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Deployment Status
uses: altinukshini/deployment-action@releases/v1
id: deployment
with:
token: "${{ github.token }}"
target_url: https://www.npmjs.com/settings/mintbase-js/packages
environment: production

- name: Publish Push Prerelease
if: ${{ github.event.head_commit.message }}
run: |
Expand All @@ -50,3 +67,21 @@ jobs:
git commit -m "πŸ€– Release ${{ github.event.release.tag_name }}"
lerna publish from-package --yes --dist-tag ${{ github.event.action == 'released' && 'released' || 'prerelease'}}
git push
- name: Update deployment status (success)
if: success()
uses: altinukshini/deployment-status@releases/v1
with:
token: "${{ github.token }}"
target_url: https://www.npmjs.com/settings/mintbase-js/packages
state: "success"
deployment_id: ${{ steps.deployment.outputs.deployment_id }}

- name: Update deployment status (failure)
if: failure()
uses: altinukshini/deployment-status@releases/v1
with:
token: "${{ github.token }}"
target_url: https://www.npmjs.com/settings/mintbase-js/packages
state: "failure"
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
2 changes: 0 additions & 2 deletions .npmignore

This file was deleted.

2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": true,
"useWorkspaces": true,
"version": "0.0.4-publish-on-push.6",
"version": "0.0.4-transfer-as-example.3",
"packages": [
"packages/*"
]
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions packages/app/components/TransferTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { ReactElement, useState, useEffect, SetStateAction } from 'react';
import { useWallet } from '@mintbase-js/react';
import { ownedTokens, Token } from '@mintbase-js/data';
import { execute, transfer } from '@mintbase-js/sdk';
import type { FinalExecutionOutcome } from '@mintbase-js/sdk';

export const TransferTest = (): ReactElement => {
const { selector, activeAccountId } = useWallet();
const [isTransferring, setIsTransferring] = useState<boolean>(false);
const [transferResult, setTransferResult] = useState<FinalExecutionOutcome>(null);
const [token, setToken] = useState<Token>(null);
const [error, setError] = useState<Error>(null);

useEffect(() => {
(async function load(): Promise<void> {
const result = await ownedTokens(activeAccountId, { limit: 1 })
.catch((err: SetStateAction<Error>) => setError(err));
setToken(result[0]);
return;
})();
}, []);

const handleTransfer = async (): Promise<void> => {
setIsTransferring(true);
const wallet = await selector.wallet();
const result = await execute(
transfer({
nftContractId: token.contractId,
transfers: [{
receiverId: 'mb_carol.testnet',
tokenId: token.tokenId,
}],
}),
{ wallet },
);
setTransferResult(result as FinalExecutionOutcome);
};

if (!token) {
return <div>TokenTest Waiting for token owned by {activeAccountId}</div>;
}

return (
<div>
{error
? <p>{error.message}</p>
: null
}
{isTransferring
? <p>Transferring...</p>
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
: <button onClick={() => handleTransfer()}>
Transfer {token.tokenId} of {token.contractId} to mb_carol.testnet
</button>
}

{transferResult ? <div>{JSON.stringify(transferResult)}</div> : null}
</div>
);
};
4 changes: 2 additions & 2 deletions packages/app/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "mintbase-next-test-suite",
"version": "0.0.4-publish-on-push.6",
"version": "0.0.4-transfer-as-example.3",
"private": true,
"scripts": {
"dev": "next dev",
"lint": "eslint . --fix --ext ts --ext tsx"
},
"dependencies": {
"@mintbase-js/sdk": "^0.0.4-publish-on-push.6",
"@mintbase-js/sdk": "^0.0.4-transfer-as-example.3",
"next": "12.3.1",
"react": "18.2.0",
"react-dom": "18.2.0"
Expand Down
73 changes: 37 additions & 36 deletions packages/app/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useWallet } from '@mintbase-js/react';
import type { NextPage } from 'next';
import Head from 'next/head';
import { TransferTest } from '../components/TransferTest';
import styles from '../styles/Home.module.css';
import { callContractMethod, MAX_GAS, ONE_YOCTO } from '@mintbase-js/sdk';

const Home: NextPage = () => {
const {
connect,
Expand All @@ -11,6 +12,7 @@ const Home: NextPage = () => {
selector,
// isConnected,
isWaitingForConnection,
isWalletSelectorSetup,
signMessage,
} = useWallet();

Expand All @@ -22,22 +24,6 @@ const Home: NextPage = () => {
meta:JSON.stringify({ type: 'signature' }),
});
};

const callTransferTest = async (): Promise<void> => {
const result = await callContractMethod({
signerId: activeAccountId,
contractAddress: 'nobase.mintspace2.testnet',
methodName: 'nft_transfer',
args: {
'receiver_id': 'benipsen.testnet',
'token_id': '0',
},
gas: MAX_GAS,
deposit: ONE_YOCTO,
}, { wallet: await selector.wallet() });
console.log('got result!', result);
};

return (
<div className={styles.container}>
<Head>
Expand All @@ -58,30 +44,45 @@ const Home: NextPage = () => {
This is a test suite for development and testing with NextJS.<br />
</p>

{isWaitingForConnection ? <div>Waiting for connetcion to be established...</div> : null}
{isWaitingForConnection ? <div>Waiting for a wallet connection...</div> : null}

{activeAccountId ?
<div className={styles.description}>
<h2>You are logged in as {activeAccountId}</h2>
<button className={styles.button} onClick={callTransferTest}>
TRANSFER CALL
</button>
<button className={styles.button} onClick={disconnect}>
DISCONNECT
</button>
{isWalletSelectorSetup
?
<div>
{activeAccountId
?
<div className={styles.description}>
<h2>You are logged in as {activeAccountId}</h2>
<button className={styles.button} onClick={disconnect}>
DISCONNECT
</button>
</div>
:
<div className={styles.description}>
<h2>To continue, login with NEAR</h2>
<button className={styles.button} onClick={connect}>
CONNECT
</button>
</div>
}
</div>
:
<div className={styles.description}>
<h2>To continue, login with NEAR</h2>
<button className={styles.button} onClick={connect}>
CONNECT
</button>
</div>
<div>Waiting for wallet selector components...</div>
}

{activeAccountId && <button className={styles.button} onClick={signMessageTest}>
SIGN MESSAGE
</button>}

{activeAccountId ?
<button className={styles.button} onClick={signMessageTest}>
SIGN MESSAGE
</button>
: null
}

<h2>Test Components</h2>
{activeAccountId ?
<TransferTest />
: null
}

</main>

Expand Down
5 changes: 5 additions & 0 deletions packages/app/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ a {
background: black;
}
}

button {
padding: 10px 50px;
margin: 10px 10px 0 0;
}
4 changes: 2 additions & 2 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mintbase-js/auth",
"version": "0.0.4-publish-on-push.6",
"version": "0.0.4-transfer-as-example.3",
"description": "Wallet and auth functions for Mintbase JS SDK",
"main": "lib/index.js",
"scripts": {
Expand All @@ -19,7 +19,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@mintbase-js/sdk": "^0.0.4-publish-on-push.6",
"@mintbase-js/sdk": "^0.0.4-transfer-as-example.3",
"@near-wallet-selector/coin98-wallet": "^7.2.0",
"@near-wallet-selector/core": "^7.1.0",
"@near-wallet-selector/default-wallets": "^7.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mintbase-js/data",
"version": "0.0.4-publish-on-push.6",
"version": "0.0.4-transfer-as-example.3",
"description": "Query wrappers for Mintbase JS SDK",
"main": "lib/index.js",
"scripts": {
Expand Down
19 changes: 3 additions & 16 deletions packages/data/src/api/ownedTokens/ownedTokens.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
import { Pagination } from '../../types';
import { Pagination, Token } from '../../types';
import { fetchGraphQl } from '../../graphql/fetch';
import { ownedTokensQuery } from './ownedTokens.query';

export type OwnedTokens = {
lastTransferredAt: string;
tokenId: string;
contractId: string;
baseUri: string;
metadataId: string;
title: string;
minter: string;
media: string;
document: string;
animationUrl: string;
}

export type OwnedTokensQueryResult = {
tokens: OwnedTokens[];
tokens: Token[];
}

export const ownedTokens = async (
ownerId: string,
{ limit, offset = 0 }: Pagination,
): Promise<OwnedTokens[]> => {
): Promise<Token[]> => {
const { data, error } = await fetchGraphQl<OwnedTokensQueryResult>({
query: ownedTokensQuery,
variables: {
Expand Down
4 changes: 3 additions & 1 deletion packages/data/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type NearDataEnv = 'mainnet' | 'testnet' | 'sandbox';
export const NEAR_DATA_ENV = process.env.NEAR_DATA_ENV || 'mainnet';
export const NEAR_DATA_ENV = process.env.NEAR_DATA_ENV ||
process.env.NEXT_PUBLIC_NEAR_DATA_ENV ||
'mainnet';
export const GRAPHQL_ENDPOINT = `https://interop-${NEAR_DATA_ENV}.hasura.app/v1/graphql`;
export const QUERY_OPS_PREFIX = 'mintbase_js_data_';
3 changes: 2 additions & 1 deletion packages/data/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './constants';
export * from './graphql/index';
export * from './api/index';
export * from './graphql/index';
export * from './types';
13 changes: 13 additions & 0 deletions packages/data/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@ export type Pagination = {
limit: number;
offset?: number;
}

export type Token = {
lastTransferredAt: string;
tokenId: string;
contractId: string;
baseUri: string;
metadataId: string;
title: string;
minter: string;
media: string;
document: string;
animationUrl: string;
}
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mintbase-js/react",
"version": "0.0.4-publish-on-push.6",
"version": "0.0.4-transfer-as-example.3",
"description": "React app tools for Mintbase JS SDK",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit 8f8a9a7

Please sign in to comment.