Skip to content

Commit

Permalink
add custom icon and name selection (#192)
Browse files Browse the repository at this point in the history
* add custom icon and name selection

* add change icon

* bump versions and add networkDataOverride aptos
  • Loading branch information
LukassF authored Jul 24, 2024
1 parent fda4bc4 commit 96390e3
Show file tree
Hide file tree
Showing 11 changed files with 10,012 additions and 9,685 deletions.
6 changes: 3 additions & 3 deletions sdk/apps/modal-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"@nightlylabs/nightly-connect-polkadot": "0.0.16",
"@nightlylabs/nightly-connect-solana": "0.0.29",
"@nightlylabs/nightly-connect-sui": "0.0.29",
"@nightlylabs/wallet-selector-aptos": "0.1.4",
"@nightlylabs/wallet-selector-aptos": "0.1.6",
"@nightlylabs/wallet-selector-base": "^0.4.1",
"@nightlylabs/wallet-selector-polkadot": "0.2.6",
"@nightlylabs/wallet-selector-polkadot": "0.2.7",
"@nightlylabs/wallet-selector-solana": "0.3.2",
"@nightlylabs/wallet-selector-sui": "0.3.2",
"@polkadot/api": "^10.10.1",
Expand All @@ -44,4 +44,4 @@
"engines": {
"node": ">=16.8"
}
}
}
4 changes: 4 additions & 0 deletions sdk/apps/modal-example/src/routes/alephCustom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export default function Polkadot() {
dotsOptions: {
color: 'gold'
}
},
networkDataOverride: {
name: 'Custom name',
icon: 'https://cdn.pixabay.com/photo/2016/04/01/00/28/face-1298202_640.png'
}
}
)
Expand Down
1 change: 1 addition & 0 deletions sdk/apps/modal-example/src/routes/aptos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function AptosPage() {
}
},
{},

document.getElementById('modalAnchor')
).then(async (adapter) => {
adapter.canEagerConnect().then((canEagerConnect) => {
Expand Down
223 changes: 223 additions & 0 deletions sdk/apps/modal-example/src/routes/aptosCustom.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
import { AccountAuthenticator, AccountAuthenticatorEd25519, Aptos } from '@aptos-labs/ts-sdk'
import { AccountInfo, AptosSignMessageInput, UserResponseStatus } from '@aptos-labs/wallet-standard'
import { NightlyConnectAptosAdapter } from '@nightlylabs/wallet-selector-aptos'
import { createEffect, createSignal, onMount, Show } from 'solid-js'
import { Title } from '@solidjs/meta'
import toast from 'solid-toast'

const aptos = new Aptos() // default to devnet

export default function AptosPage() {
const [adapter, setAdapter] = createSignal<NightlyConnectAptosAdapter>()
const [eager, setEager] = createSignal(false)
const [accountInfo, setAccountInfo] = createSignal<AccountInfo>()
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'
}
},
{},

document.getElementById('modalAnchor'),
{
variablesOverride: {
'--nc-color-primary': 'white',
'--nc-img-logo': 'url(https://alephzero.org/aleph-design/brand-elements/logo-day.svg)'
},
stylesOverride: `
.nc_headerWrapper {
background-color: blue;
}
.nc_headerLogo {
width: 200px;
}
.nc_modalContent {
border-radius: 0;
border: 3px dashed var(--nc-color-primary);
}
`,
qrConfigOverride: {
dotsOptions: {
color: 'purple'
}
},
networkDataOverride: {
name: 'Custom name',
icon: 'https://cdn.pixabay.com/photo/2016/04/01/00/28/face-1298202_640.png'
}
}
).then(async (adapter) => {
adapter.canEagerConnect().then((canEagerConnect) => {
setEager(canEagerConnect)
})

adapter.on('connect', (accInfo) => {
setAccountInfo(accInfo)
})

adapter.on('disconnect', () => {
setAccountInfo(undefined)
console.log('adapter disconnected')
})

adapter.on('accountChange', (accInfo) => {
setAccountInfo(accInfo)
})

setAdapter(adapter)
})
})
createEffect(() => {
if (eager()) {
adapter()
?.connect()
.then(
() => {
console.log('connect resolved successfully')
},
() => {
console.log('connect rejected')
}
)
}
})

return (
<main>
<Title>Aptos Example</Title>
<div id="modalAnchor" />
<Show
when={!!accountInfo()}
fallback={
<button
onClick={() => {
adapter()
?.connect()
.then(
() => {
console.log('connect resolved successfully')
},
() => {
console.log('connect rejected')
}
)
}}>
Connect
</button>
}>
<h1>Current address: {accountInfo()?.address.toString()}</h1>
<button
onClick={async () => {
try {
const transaction = await aptos.transaction.build.simple({
sender: accountInfo()!.address.toString(),
data: {
function: '0x1::coin::transfer',
typeArguments: ['0x1::aptos_coin::AptosCoin'],
functionArguments: [
'0x960dbc655b847cad38b6dd056913086e5e0475abc27152b81570fd302cb10c38',
100
]
}
})
const signedTx = await adapter()!.signAndSubmitTransaction({
rawTransaction: transaction.rawTransaction
})
// Verify the transaction was signed
if (signedTx.status !== UserResponseStatus.APPROVED) {
toast.error('Transaction was not approved')
return
}
console.log('signedTx', signedTx)
toast.success('Transaction was signed!')
} catch (e) {
toast.error("Error: couldn't sign and send transaction!")
console.log(e)
}
}}>
sign and submit tx
</button>
<button
onClick={async () => {
try {
const transaction = await aptos.transaction.build.simple({
sender: accountInfo()!.address.toString(),
data: {
function: '0x1::coin::transfer',
typeArguments: ['0x1::aptos_coin::AptosCoin'],
functionArguments: [
'0x960dbc655b847cad38b6dd056913086e5e0475abc27152b81570fd302cb10c38',
100
]
}
})
const signedTx = await adapter()!.signTransaction(transaction)
// Verify the transaction was signed
if (signedTx.status !== UserResponseStatus.APPROVED) {
toast.error('Transaction was not approved')
return
}
console.log('signedTx', signedTx)
console.log(signedTx.args instanceof AccountAuthenticatorEd25519)
console.log(signedTx.args.isEd25519())
// @ts-expect-error sdsdsd
console.log(signedTx.args.public_key)
// @ts-expect-error sdsdsd
console.log(signedTx.args.signature)
const sig = new AccountAuthenticatorEd25519(
// @ts-expect-error sdsdsd
signedTx.args.public_key,
// @ts-expect-error sdsdsd
signedTx.args.signature
)
console.log(sig)
await aptos.transaction.submit.simple({
senderAuthenticator: sig,
transaction: transaction
})
toast.success('Transaction was signed!')
} catch (e) {
toast.error("Error: couldn't sign and send transaction!")
console.log(e)
}
}}>
sign tx
</button>
<button
onClick={async () => {
try {
const msgToSign: AptosSignMessageInput = {
message: 'I love Nightly',
address: true,
nonce: 'YOLO'
}
const signed = await adapter()!.signMessage(msgToSign)
if (signed.status !== UserResponseStatus.APPROVED) {
throw new Error('Message was not approved')
}
toast.success('Message was signed!')
} catch (e) {
toast.error("Error: couldn't sign message!")
console.log(e)
}
}}>
Sign message
</button>
<button
onClick={() => {
adapter()?.disconnect()
setAccountInfo(undefined)
}}>
Disconnect
</button>
</Show>
</main>
)
}
3 changes: 3 additions & 0 deletions sdk/apps/modal-example/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export default function Home() {
<A href="/aptos">
<button>Aptos</button>
</A>
<A href="/aptosCustom">
<button>Aptos custom</button>
</A>
</main>
)
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Meta, StoryObj } from '@storybook/web-components'
import { useArgs } from '@storybook/client-api'
import { Meta, StoryObj } from '@storybook/web-components'
import { html } from 'lit'
import { NightlySelector } from './nightly-selector'
import './nightly-selector'
import Phantom from '../../static/svg/PhantomIcon.svg'
import MetaMask from '../../static/svg/MetaMaskIcon.svg'
import Binance from '../../static/svg/BinanceIcon.svg'
import ChainIcon from '../../static/svg/ChainIcon.svg'
import Coinbase from '../../static/svg/CoinbaseIcon.svg'
import Glow from '../../static/svg/GlowIcon.svg'
import ZenGO from '../../static/svg/ZenGOIcon.svg'
import Trust from '../../static/svg/TrustIcon.svg'
import Binance from '../../static/svg/BinanceIcon.svg'
import Sollet from '../../static/svg/SolletIcon.svg'
import MetaMask from '../../static/svg/MetaMaskIcon.svg'
import NightlyIcon from '../../static/svg/NightlyIcon.svg'
import ChainIcon from '../../static/svg/ChainIcon.svg'
import Phantom from '../../static/svg/PhantomIcon.svg'
import Sollet from '../../static/svg/SolletIcon.svg'
import Trust from '../../static/svg/TrustIcon.svg'
import ZenGO from '../../static/svg/ZenGOIcon.svg'
import { WalletSelectorItem } from '../../utils/types'
import './nightly-selector'
import { NightlySelector } from './nightly-selector'

const meta = {
title: 'nightly-selector',
Expand Down Expand Up @@ -179,3 +179,33 @@ export const Error: Story = (args: NightlyModalArgs) => {
}

Error.args = { ...rest }

export const CustomBlockchain: Story = (args: NightlyModalArgs) => {
const [{ open }, updateArgs] = useArgs()

const handleClose = () => {
updateArgs({ open: false })
args.onClose()
}

return open
? html`
<nightly-selector
.onClose=${handleClose}
.selectorItems=${args.selectorItems}
.onWalletClick=${args.onWalletClick}
.chainIcon=${args.chainIcon}
.chainName=${args.chainName}
.sessionId=${args.sessionId}
?connecting=${args.connecting}
.relay=${args.relay}
></nightly-selector>
`
: html``
}

CustomBlockchain.args = {
...rest,
chainIcon: 'https://cdn.pixabay.com/photo/2016/04/01/00/28/face-1298202_640.png',
chainName: 'Custom name'
}
4 changes: 2 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.1.5",
"version": "0.1.6",
"description": "",
"type": "module",
"exports": {
Expand Down Expand Up @@ -41,4 +41,4 @@
"tslib": "^2.5.3",
"typescript": "^5.1.3"
}
}
}
Loading

0 comments on commit 96390e3

Please sign in to comment.