Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: connect to wallet without node (wip) #1398

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils/aepp-wallet-communication/rpc/aepp-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export default Ae.compose({
}
return this.rpcClient.request(
METHODS.sign,
{ onAccount: opt.onAccount, tx, returnSigned: false, networkId: this.getNetworkId() }
{ onAccount: opt.onAccount, tx, returnSigned: false, networkId: this.getNetworkId(opt) }
)
}
}
Expand Down
63 changes: 63 additions & 0 deletions test/environment/aepp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SDK test in browser</title>
</head>
<body>
Open developer console
<script src="../../dist/aepp-sdk.browser-script.js"></script>
<script type="text/javascript">
const { RpcAepp, WalletDetector, BrowserWindowMessageConnection, Node, Universal, MemoryAccount } = Ae;

(async () => {
async function scanForWallets (sdk) {
const handleWallets = async function ({ wallets, newWallet }) {
newWallet = newWallet || Object.values(wallets)[0]
if (confirm(`Do you want to connect to wallet ${newWallet.name} with id ${newWallet.id}`)) {
console.log('newWallet', newWallet)
detector.stopScan()

await sdk.connectToWallet(await newWallet.getConnection())
console.log('walletConnected')
const { address: { current } } = await sdk.subscribeAddress('subscribe', 'connected')
console.log('address', Object.keys(current)[0])
onConnection()
}
}

const scannerConnection = await BrowserWindowMessageConnection({
connectionInfo: { id: 'spy' }
})
const detector = await WalletDetector({ connection: scannerConnection })
detector.scan(handleWallets.bind(this))
}

const sdk = await RpcAepp({
name: 'Simple æpp',
nodes: [],
onNetworkChange: ({ networkId }) => {
const [{ name }] = sdk.getNodesInPool()
.filter(node => node.nodeNetworkId === networkId)
sdk.selectNode(name)
console.log('networkId', networkId)
},
onAddressChange: ({ current }) => console.log('address', Object.keys(current)[0]),
onDisconnect: () => alert('Aepp is disconnected')
})

await scanForWallets(sdk)

async function onConnection() {
console.log('spending')
await sdk.spend(
1,
'ak_gvxNbZf5CuxYVfcUFoKAP4geZatWaC2Yy4jpx5vZoCKank4Gc',
{ nonce: 198, networkId: 'ae_mainnet' }
)
console.log('done')
}
})()
</script>
</body>
</html>