-
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.
β»οΈ π Transfer as example (#180)
* π β»οΈ 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
1 parent
e37dbf6
commit 8f8a9a7
Showing
29 changed files
with
419 additions
and
153 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 was deleted.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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> | ||
); | ||
}; |
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 |
---|---|---|
|
@@ -24,3 +24,8 @@ a { | |
background: black; | ||
} | ||
} | ||
|
||
button { | ||
padding: 10px 50px; | ||
margin: 10px 10px 0 0; | ||
} |
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
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,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_'; |
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,3 +1,4 @@ | ||
export * from './constants'; | ||
export * from './graphql/index'; | ||
export * from './api/index'; | ||
export * from './graphql/index'; | ||
export * from './types'; |
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
Oops, something went wrong.