Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
LukassF committed Nov 8, 2024
1 parent b0cf294 commit 57ca731
Show file tree
Hide file tree
Showing 14 changed files with 300 additions and 292 deletions.
8 changes: 4 additions & 4 deletions sdk/apps/modal-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"@nightlylabs/nightly-connect-polkadot": "0.0.16",
"@nightlylabs/nightly-connect-solana": "0.0.30",
"@nightlylabs/nightly-connect-sui": "0.1.0",
"@nightlylabs/wallet-selector-aptos": "^0.1.12",
"@nightlylabs/wallet-selector-aptos": "^0.1.13",
"@nightlylabs/wallet-selector-base": "^0.4.3",
"@nightlylabs/wallet-selector-polkadot": "0.2.7",
"@nightlylabs/wallet-selector-solana": "0.3.9",
"@nightlylabs/wallet-selector-sui": "0.4.0",
"@nightlylabs/wallet-selector-polkadot": "0.2.8",
"@nightlylabs/wallet-selector-solana": "0.3.10",
"@nightlylabs/wallet-selector-sui": "0.4.1",
"@polkadot/api": "^10.10.1",
"@polkadot/extension-inject": "^0.46.5",
"@solana/web3.js": "^1.77.2",
Expand Down
135 changes: 64 additions & 71 deletions sdk/apps/modal-example/src/routes/aleph.tsx
Original file line number Diff line number Diff line change
@@ -1,65 +1,64 @@
import {
getPolkadotWallets,
NightlyConnectAdapter,
} from "@nightlylabs/wallet-selector-polkadot";
import { ApiPromise, WsProvider } from "@polkadot/api";
import { createEffect, createSignal, onMount, Show } from "solid-js";
import { Title } from "@solidjs/meta";
import toast from "solid-toast";
import { Signer } from "@polkadot/api/types";
import { getPolkadotWallets, NightlyConnectAdapter } from '@nightlylabs/wallet-selector-polkadot'
import { ApiPromise, WsProvider } from '@polkadot/api'
import { createEffect, createSignal, onMount, Show } from 'solid-js'
import { Title } from '@solidjs/meta'
import toast from 'solid-toast'
import { Signer } from '@polkadot/api/types'

const RECEIVER = "5CFRopxy991HCJj1HYtUQjaaBMw9iRLE9jxPndBsgdCjeJj5";
const RECEIVER = '5CFRopxy991HCJj1HYtUQjaaBMw9iRLE9jxPndBsgdCjeJj5'

export default function Polkadot() {
const [adapter, setAdapter] = createSignal<NightlyConnectAdapter>();
const [eager, setEager] = createSignal(false);
const [publicKey, setPublicKey] = createSignal<string>();
const [api, setApi] = createSignal<ApiPromise>();
const provider = new WsProvider("wss://ws.test.azero.dev/");
const [adapter, setAdapter] = createSignal<NightlyConnectAdapter>()
const [eager, setEager] = createSignal(false)
const [publicKey, setPublicKey] = createSignal<string>()
const [api, setApi] = createSignal<ApiPromise>()
const provider = new WsProvider('wss://ws.test.azero.dev/')

onMount(async () => {
const adapter = NightlyConnectAdapter.buildLazy(
onMount(() => {
NightlyConnectAdapter.build(
{
appMetadata: {
name: "NC TEST AlephZero",
description: "Nightly Connect Test",
icon: "https://docs.nightly.app/img/logo.png",
additionalInfo: "Courtesy of Nightly Connect team",
name: 'NC TEST AlephZero',
description: 'Nightly Connect Test',
icon: 'https://docs.nightly.app/img/logo.png',
additionalInfo: 'Courtesy of Nightly Connect team'
},
network: "AlephZero",
persistent: true,
network: 'AlephZero'
},
{ initOnConnect: false, disableModal: false, disableEagerConnect: false }
);
{},
document.getElementById('modalAnchor')
).then((adapter) => {
adapter.canEagerConnect().then((canEagerConnect) => {
setEager(canEagerConnect)
})

adapter.canEagerConnect().then((canEagerConnect: boolean) => {
setEager(canEagerConnect);
});
setAdapter(adapter);
setAdapter(adapter)

ApiPromise.create({
provider
}).then((api) => {
setApi(api)
})
})
})

ApiPromise.create({
provider,
}).then((api) => {
setApi(api);
});
});
createEffect(() => {
if (eager()) {
adapter()
?.connect()
.then(
async () => {
const accounts = await adapter()!.accounts.get();
console.log(accounts);
setPublicKey(accounts[0].address);
console.log("connect resolved successfully");
const accounts = await adapter()!.accounts.get()
console.log(accounts)
setPublicKey(accounts[0].address)
console.log('connect resolved successfully')
},
() => {
console.log("connect rejected");
console.log('connect rejected')
}
);
)
}
});
})

return (
<main>
Expand All @@ -71,41 +70,36 @@ export default function Polkadot() {
<button
onClick={async () => {
try {
console.log(getPolkadotWallets());
await adapter()!.connect();
const accounts = await adapter()!.accounts.get();
console.log(accounts);
setPublicKey(accounts[0].address);
console.log("adapter", adapter());
console.log(getPolkadotWallets())

await adapter()!.connect()
const accounts = await adapter()!.accounts.get()
console.log(accounts)
setPublicKey(accounts[0].address)
console.log('adapter', adapter())
} catch (err) {
console.log(err);
console.log(err)
}
}}
>
}}>
Connect
</button>
}
>
}>
<h1>Current address: {publicKey()}</h1>
<button
onClick={async () => {
try {
const payload = api()!.tx.balances.transfer(
RECEIVER,
5000000000000
);
const payload = api()!.tx.balances.transfer(RECEIVER, 5000000000000)
const signed = await payload.signAsync(publicKey()!, {
signer: adapter()!.signer as Signer,
});
console.log({ signed });
await signed.send();
toast.success("Transaction was signed and sent!");
signer: adapter()!.signer as Signer
})
console.log({ signed })
await signed.send()
toast.success('Transaction was signed and sent!')
} catch (e) {
toast.error("Error: couldn't sign and send transaction!");
console.log(e);
toast.error("Error: couldn't sign and send transaction!")
console.log(e)
}
}}
>
}}>
Sign test transfer
</button>
{/* <button
Expand All @@ -128,12 +122,11 @@ export default function Polkadot() {
</Show>
<button
onClick={() => {
adapter()?.disconnect();
setPublicKey(undefined);
}}
>
adapter()?.disconnect()
setPublicKey(undefined)
}}>
Disconnect
</button>
</main>
);
)
}
2 changes: 1 addition & 1 deletion sdk/apps/modal-example/src/routes/solana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function Solana() {
const [adapter, setAdapter] = createSignal<NightlyConnectAdapter>()
const [eager, setEager] = createSignal(false)
const [publicKey, setPublicKey] = createSignal<PublicKey>()
onMount(async () => {
onMount(() => {
NightlyConnectAdapter.build(
{
appMetadata: {
Expand Down
4 changes: 2 additions & 2 deletions sdk/apps/modal-example/src/routes/sui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function Sui() {
const [adapter, setAdapter] = createSignal<NightlyConnectSuiAdapter>()
const [eager, setEager] = createSignal(false)
const [publicKey, setPublicKey] = createSignal<string>()
onMount(async () => {
onMount(() => {
NightlyConnectSuiAdapter.build(
{
appMetadata: {
Expand All @@ -20,7 +20,7 @@ export default function Sui() {
},
{},
document.getElementById('modalAnchor')
).then(async (adapter) => {
).then((adapter) => {
adapter.canEagerConnect().then((canEagerConnect) => {
setEager(canEagerConnect)
})
Expand Down
2 changes: 1 addition & 1 deletion 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.12",
"version": "0.1.13",
"description": "",
"type": "module",
"exports": {
Expand Down
109 changes: 57 additions & 52 deletions sdk/packages/selector-aptos/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,68 +160,73 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
}
) => {
const adapter = new NightlyConnectAptosAdapter(appInitData, connectionOptions)
const network = appInitData.network ?? APTOS_NETWORK
adapter._network = network
adapter.walletsList = getAptosWalletsList(
[],
getRecentWalletForNetwork(network)?.walletName ?? undefined
)

if (!adapter._connectionOptions.disableModal)
adapter._modal = new NightlyConnectSelectorModal(
adapter.walletsList,
appInitData.url ?? 'https://nc2.nightly.app',
{
name: uiOverrides?.networkDataOverride?.name ?? network,
icon:
uiOverrides?.networkDataOverride?.icon ??
'https://registry.nightly.app/networks/aptos.png'
},
anchorRef,
uiOverrides?.variablesOverride,
uiOverrides?.stylesOverride,
uiOverrides?.qrConfigOverride
try {
const network = appInitData.network ?? APTOS_NETWORK
adapter._network = network
adapter.walletsList = getAptosWalletsList(
[],
getRecentWalletForNetwork(network)?.walletName ?? undefined
)

const [app, metadataWallets] = await NightlyConnectAptosAdapter.initApp({
...appInitData,
network
})
if (!adapter._connectionOptions.disableModal)
adapter._modal = new NightlyConnectSelectorModal(
adapter.walletsList,
appInitData.url ?? 'https://nc2.nightly.app',
{
name: uiOverrides?.networkDataOverride?.name ?? network,
icon:
uiOverrides?.networkDataOverride?.icon ??
'https://registry.nightly.app/networks/aptos.png'
},
anchorRef,
uiOverrides?.variablesOverride,
uiOverrides?.stylesOverride,
uiOverrides?.qrConfigOverride
)

adapter._app = app
adapter._metadataWallets = metadataWallets
const [app, metadataWallets] = await NightlyConnectAptosAdapter.initApp({
...appInitData,
network
})

adapter.walletsList = getAptosWalletsList(
metadataWallets,
getRecentWalletForNetwork(network)?.walletName ?? undefined
)
adapter._app = app
adapter._metadataWallets = metadataWallets

adapter.checkForArrivingWallets(metadataWallets)
adapter.walletsList = getAptosWalletsList(
metadataWallets,
getRecentWalletForNetwork(network)?.walletName ?? undefined
)

// Add event listener for userConnected
app.on('userConnected', async (accountInfo, networkInfo) => {
try {
persistRecentWalletForNetwork(network, {
walletName: adapter._chosenMobileWalletName || '',
walletType: ConnectionType.Nightly
})
adapter.checkForArrivingWallets(metadataWallets)

// Add event listener for userConnected
app.on('userConnected', async (accountInfo, networkInfo) => {
try {
persistRecentWalletForNetwork(network, {
walletName: adapter._chosenMobileWalletName || '',
walletType: ConnectionType.Nightly
})

if (!adapter._app || adapter._app.connectedPublicKeys.length <= 0) {
adapter._connected = false
// If user does not pass any accounts, we should disconnect
if (!adapter._app || adapter._app.connectedPublicKeys.length <= 0) {
adapter._connected = false
// If user does not pass any accounts, we should disconnect
adapter.disconnect()
return
}
adapter.setSelectedWallet({ isRemote: true })
adapter._accountInfo = accountInfo
adapter._networkInfo = networkInfo
adapter._connected = true
adapter._connectionType = ConnectionType.Nightly
adapter.emit('connect', accountInfo)
} catch {
adapter.disconnect()
return
}
adapter.setSelectedWallet({ isRemote: true })
adapter._accountInfo = accountInfo
adapter._networkInfo = networkInfo
adapter._connected = true
adapter._connectionType = ConnectionType.Nightly
adapter.emit('connect', accountInfo)
} catch {
adapter.disconnect()
}
})
})
} catch {
console.log('Error building adapter')
}

return adapter
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/packages/selector-polkadot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/wallet-selector-polkadot",
"version": "0.2.7",
"version": "0.2.8",
"description": "",
"type": "module",
"exports": {
Expand Down
Loading

0 comments on commit 57ca731

Please sign in to comment.