diff --git a/app/glove-test.ts b/app/glove-test.ts new file mode 100644 index 0000000..81785ee --- /dev/null +++ b/app/glove-test.ts @@ -0,0 +1,55 @@ +import './style.css'; +import { web3Accounts, web3Enable, web3FromSource } from '@polkadot/extension-dapp'; +import { ApiPromise, WsProvider } from '@polkadot/api'; +import { InjectedAccountWithMeta } from '@polkadot/extension-inject/types'; +import { APP_NAME } from '@/lib/consts'; + +const ROCOCO_WS_PROVIDER = 'wss://rococo-rpc.polkadot.io'; +let injectedAccounts: InjectedAccountWithMeta[] = []; + +if (typeof window !== 'undefined') { + document + .querySelector('#hero-connect-accounts')! + .addEventListener('click', async () => { + // returns an array of all the injected sources + // (this needs to be called first, before other requests) + const allInjected = await web3Enable('example-dapp'); + const allAccounts = await web3Accounts(); + console.log('glove-test', { allInjected, allAccounts }); + }); +} + +// document.querySelector('#send-tx')!.addEventListener('click', async () => { +// const provider = new WsProvider(ROCOCO_WS_PROVIDER); +// const api = await ApiPromise.create({ provider }); + +// // Initialise the provider to connect to the local node +// const account = injectedAccounts[0]; + +// if (injectedAccounts.length === 0) { +// console.error('No injected account'); +// return; +// } + +// const amount = document.querySelector('#amount-input')?.value; + +// const transferExtrinsic = api.tx.balances.transferKeepAlive(account.address, amount); +// const injector = await web3FromSource(account.meta.source); + +// transferExtrinsic +// .signAndSend(account.address, { signer: injector.signer }, ({ events, txHash, status }) => { +// document.querySelector('#tx-hash')!.innerHTML = txHash.toString(); + +// if (status.isInBlock) { +// events.forEach(({ event: { method, section } }) => { +// const li = document.createElement('li'); +// li.innerHTML = `${ section }.${ method }`; +// document.querySelector('#tx-events')!.appendChild(li); +// }); +// } +// }) +// .catch((error: any) => { +// document.querySelector('#tx-error')!.innerHTML = error; +// console.log(':( transaction failed', error); +// }); +// }); \ No newline at end of file diff --git a/app/layout.tsx b/app/layout.tsx index 3db389b..1461046 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -18,6 +18,8 @@ import dynamic from 'next/dynamic'; import AccountSelector from '@/components/account-selector'; import VoteHistory from '@/components/vote-history'; import VerifyVote from '@/components/verify-vote'; +import GloveTest from '@/components/__tests__/e2e/glove-test'; +import Script from 'next/script'; // import ConfirmVote from '@/components/confirm-vote'; interface LayoutProps { @@ -76,6 +78,9 @@ export default function Layout({ children }: LayoutProps) {