-
Notifications
You must be signed in to change notification settings - Fork 55
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
1 parent
0ec6676
commit e0e2a1e
Showing
28 changed files
with
1,181 additions
and
11 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
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,21 @@ | ||
# Logs | ||
logs | ||
*.log | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
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,4 @@ | ||
# Have Questions? | ||
|
||
For any questions about building front end applications with [useink](https://use.ink/frontend/overview/), join the [Element chat](https://matrix.to/#/%23useink:parity.io). | ||
|
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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/logo.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>ink! Examples</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
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,30 @@ | ||
{ | ||
"name": "basic_contract_caller", | ||
"private": true, | ||
"version": "0.1.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"ui": "workspace:ui@*" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.0.37", | ||
"@types/react-dom": "^18.0.11", | ||
"@typescript-eslint/eslint-plugin": "^5.59.0", | ||
"@typescript-eslint/parser": "^5.59.0", | ||
"@vitejs/plugin-react": "^4.0.0", | ||
"autoprefixer": "^10.4.14", | ||
"eslint": "^8.38.0", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-react-refresh": "^0.3.4", | ||
"postcss": "^8.4.24", | ||
"tailwindcss": "^3.3.2", | ||
"typescript": "^5.0.2", | ||
"vite": "^4.3.9" | ||
} | ||
} |
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,6 @@ | ||
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,61 @@ | ||
import { Other } from './Other'; | ||
import basicContractMetadata from './assets/basic_contract_caller.json'; | ||
import { BASIC_CONTRACT_ROCOCO_ADDRESS } from './constants'; | ||
import { useEffect } from 'react'; | ||
import { Button, Card, ConnectButton, InkLayout } from 'ui'; | ||
import { useCall, useContract, useTx, useWallet } from 'useink'; | ||
import { useTxNotifications } from 'useink/notifications'; | ||
import { isPendingSignature, pickDecoded, shouldDisable } from 'useink/utils'; | ||
|
||
function App() { | ||
const { account } = useWallet(); | ||
const basicContract = useContract( | ||
BASIC_CONTRACT_ROCOCO_ADDRESS, | ||
basicContractMetadata, | ||
); | ||
const flipAndGet = useTx<boolean>(basicContract, 'flipAndGet'); | ||
useTxNotifications(flipAndGet); | ||
|
||
const other = useCall<string>(basicContract, 'other'); | ||
|
||
useEffect(() => { | ||
other?.send([], { defaultCaller: true }); | ||
}, [other.send]); | ||
|
||
const otherAddress = pickDecoded(other.result); | ||
|
||
return ( | ||
<InkLayout | ||
className='md:py-12 md:p-6 p-4 h-screen flex items-center justify-center' | ||
animationSrc='https://raw.githubusercontent.com/paritytech/ink-workshop/d819d10a35b2ac3d2bff4f77a96701a527b3ad3a/frontend/public/dark-sea-creatures.json' | ||
> | ||
<div className='flex flex-col md:flex-row md:justify-center justify-start items-stretch gap-3'> | ||
<Card className='p-6 flex flex-col w-full max-w-md backdrop-blur-sm bg-opacity-70'> | ||
<h1 className='text-2xl font-bold'> | ||
{basicContractMetadata.contract.name.toUpperCase()} | ||
</h1> | ||
|
||
{account ? ( | ||
<Button | ||
disabled={shouldDisable(flipAndGet)} | ||
onClick={() => flipAndGet.signAndSend()} | ||
className='mt-6' | ||
> | ||
{isPendingSignature(flipAndGet) | ||
? 'Please sign transaction...' | ||
: shouldDisable(flipAndGet) | ||
? 'Flipping...' | ||
: 'Flip Other Contract'} | ||
</Button> | ||
) : ( | ||
<ConnectButton className='mt-6' /> | ||
)} | ||
</Card> | ||
|
||
{otherAddress && <Other address={otherAddress} />} | ||
</div> | ||
</InkLayout> | ||
); | ||
} | ||
|
||
export default App; |
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,7 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
body { | ||
background-color: #1A1452; | ||
} |
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,30 @@ | ||
import otherContractMetadata from './assets/other_contract.json'; | ||
import { Card } from 'ui'; | ||
import { useCallSubscription, useContract } from 'useink'; | ||
import { pickDecoded } from 'useink/utils'; | ||
|
||
interface Props { | ||
address: string; | ||
} | ||
|
||
export const Other: React.FC<Props> = ({ address }) => { | ||
const otherContract = useContract(address, otherContractMetadata); | ||
const getOtherSub = useCallSubscription<boolean>(otherContract, 'get', [], { | ||
defaultCaller: true, | ||
}); | ||
|
||
return ( | ||
<Card className='p-6 flex flex-col w-full max-w-md backdrop-blur-sm bg-opacity-70'> | ||
<h1 className='text-2xl font-bold'> | ||
{otherContractMetadata.contract.name.toUpperCase()} | ||
</h1> | ||
|
||
<p className='mt-6'> | ||
Flipped:{' '} | ||
<b className='uppercase'> | ||
{pickDecoded(getOtherSub.result)?.toString()} | ||
</b> | ||
</p> | ||
</Card> | ||
); | ||
}; |
Oops, something went wrong.