Skip to content

Commit

Permalink
fixes + demo
Browse files Browse the repository at this point in the history
  • Loading branch information
NorbertBodziony committed Dec 4, 2023
1 parent 6ea8423 commit 9489f89
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 130 deletions.
4 changes: 1 addition & 3 deletions sdk/apps/aptos/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ export class AppAptos extends EventEmitter<SuiAppEvents> {
sessionId: string
base: BaseApp
initData: AppAptosInitialize
url = 'https://nightly.app'
providerName?: string
provider: any

constructor(base: BaseApp, initData: AppAptosInitialize) {
super()
this.initData = initData
Expand Down
4 changes: 3 additions & 1 deletion sdk/apps/modal-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"@mysten/sui.js": "^0.42.0",
"@mysten/wallet-adapter-wallet-standard": "^0.8.0",
"@nightlylabs/wallet-selector-solana": "0.2.6",
"@nightlylabs/wallet-selector-aptos": "0.0.1",
"aptos": "^1.20.0",
"@nightlylabs/nightly-connect-solana": "0.0.28",
"@nightlylabs/nightly-connect-sui": "0.0.28",
"@nightlylabs/wallet-selector-sui": "0.2.6",
Expand All @@ -38,4 +40,4 @@
"engines": {
"node": ">=16.8"
}
}
}
131 changes: 131 additions & 0 deletions sdk/apps/modal-example/src/routes/aptos.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { createEffect, createSignal, onMount, Show } from 'solid-js'
import { Title } from 'solid-start'
import { NightlyConnectAptosAdapter } from '@nightlylabs/wallet-selector-aptos'
import toast from 'solid-toast'
import { AptosClient } from 'aptos'
// Create an AptosClient to interact with devnet.
const client = new AptosClient('https://fullnode.devnet.aptoslabs.com/v1')
export default function Aptos() {
const [adapter, setAdapter] = createSignal<NightlyConnectAptosAdapter>()
const [eager, setEager] = createSignal(false)
const [publicKey, setPublicKey] = createSignal<string>()
onMount(async () => {
NightlyConnectAptosAdapter.build(
{
appMetadata: {
name: 'NCTestAptos',
description: 'Nightly Connect Test',
icon: 'https://docs.nightly.app/img/logo.png',
additionalInfo: 'Courtesy of Nightly Connect team'
}
},
true,
document.getElementById('modalAnchor')
).then(async (adapter) => {
adapter.canEagerConnect().then((canEagerConnect) => {
setEager(canEagerConnect)
})

setAdapter(adapter)
})
})

createEffect(() => {
if (eager()) {
adapter()
?.connect()
.then(
async () => {
const accounts = await adapter()!.account()
setPublicKey(accounts.address)
console.log('connect resolved successfully')
},
() => {
console.log('connect rejected')
}
)
}
})

return (
<main>
<Title>Aptos Example</Title>
<div id="modalAnchor" />
<Show
when={!!publicKey()}
fallback={
<button
onClick={() => {
adapter()
?.connect()
.then(
async () => {
const accounts = await adapter()!.account()
setPublicKey(accounts.address)
console.log('connect resolved successfully')
},
() => {
console.log('connect rejected')
}
)
}}>
Connect
</button>
}>
<h1>Current address: {publicKey()}</h1>
<button
onClick={async () => {
try {
// const transactionBlock = new TransactionBlock()
// const coin = transactionBlock.splitCoins(transactionBlock.gas, [
// transactionBlock.pure(50000000)
// ])
// transactionBlock.transferObjects(
// [coin],
// transactionBlock.pure(
// '0xd85c7ad90905e0bd49b72420deb5f4077cab62840fb3917ca2945e41d8854013'
// )
// )
// const accounts = await adapter()!.account()
// await adapter()!.signAndSubmitTransaction({
// transactionBlock,
// chain: 'sui:testnet',
// account: accounts
// })

toast.success('Transaction was signed and sent!')
} catch (e) {
toast.error("Error: couldn't sign and send transaction!")
console.log(e)
}
}}>
Send 0.005 Aptos
</button>
<button
onClick={async () => {
try {
const accounts = await adapter()!.account()
await adapter()!.signMessage!({
message: 'Hello world!',
nonce: '121'
})

toast.success('Message was signed!')
} catch (e) {
toast.error("Error: couldn't sign message!")
console.log(e)
}
}}>
Sign message
</button>
<button
onClick={() => {
adapter()?.disconnect()
setPublicKey(undefined)
}}>
Disconnect
</button>
</Show>
</main>
)
}
2 changes: 2 additions & 0 deletions sdk/build-only-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ pnpm build
cd ../selector-sui
pnpm build
cd ../selector-polkadot
pnpm build
cd ../selector-aptos
pnpm build
5 changes: 3 additions & 2 deletions sdk/packages/selector-aptos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/wallet-selector-aptos",
"version": "0.2.6",
"version": "0.0.1",
"description": "",
"type": "module",
"exports": {
Expand Down Expand Up @@ -31,7 +31,8 @@
"events": "^3.3.0",
"@aptos-labs/wallet-adapter-core": "^3.0.0",
"aptos": "^1.20.0",
"@nightlylabs/nightly-connect-base": "^0.0.27"
"@nightlylabs/nightly-connect-base": "^0.0.27",
"@nightlylabs/aptos-wallet-standard": "^0.0.3"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.0",
Expand Down
Loading

0 comments on commit 9489f89

Please sign in to comment.