Skip to content

Commit

Permalink
Merge branch 'main' of github.com:aleph-im/aleph-sdk-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
amalcaraz committed Jan 25, 2024
2 parents b50ccab + 48546ff commit c876543
Show file tree
Hide file tree
Showing 50 changed files with 35,506 additions and 17,082 deletions.
15 changes: 10 additions & 5 deletions examples/toolshed/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { useReducer } from 'react'

import { initState, reducer } from './reducer'

import SelectProvider from './components/SelectProvider'
import KeypairConfig from './components/KeypairConfig'
import WalletConfig from './components/WalletConfig'
import MessageConfig from './components/MessageConfig'
import SelectProvider from './components/SelectProvider';
import KeypairConfig from './components/KeypairConfig';
import WalletConfig from './components/WalletConfig';
import MessageConfig from './components/MessageConfig';
import WebSocket from './components/WebSocket';
import EncryptionConfig from "./components/EncryptionConfig";
import HardwareConfig from "./components/HardwareConfig";
import {ECIESAccount} from "../../../src/accounts/account";
Expand Down Expand Up @@ -63,13 +64,17 @@ function App() {
state.account &&
<MessageConfig state={state} />
}

<section style={{marginTop: '6em', borderStyle: 'solid', borderBottom: '0px', borderColor: 'lightgray', borderLeft: '0px', borderRight: '0px'}}>
<h2>WebSocket</h2>
<WebSocket />
</section>
{
state.account && state.account instanceof ECIESAccount &&
<EncryptionConfig state={state} />
}
</div>


</main>
)
}
Expand Down
1 change: 1 addition & 0 deletions examples/toolshed/src/components/SelectProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const availableKeypairs: Option[] = [
]

export const availableWallets: Option[] = [
{ label: 'PolkaDot (via Polka.js)', value: WalletChains.Substrate },
{ label: 'Ethereum (via Metamask)', value: WalletChains.Ethereum },
{ label: 'Solana (via Phantom)', value: WalletChains.Solana },
]
Expand Down
17 changes: 9 additions & 8 deletions examples/toolshed/src/components/WalletConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { avalanche, ethereum, solana } from '../../../../src/accounts'
import { solana, ethereum, avalanche, substrate } from '../../../../src/accounts'
import { WalletChains } from '../model/chains'
import { dispatchAndConsume } from '../model/componentProps'
import { Actions } from '../reducer'
import { RpcChainType } from "../../../../src/accounts/providers/JsonRPCWallet";
import { RpcId } from "../../../../src/accounts/providers/JsonRPCWallet";
import Select, { SingleValue } from "react-select";
import { useState } from "react";

Expand All @@ -13,17 +13,18 @@ type Option = {
}

const availableChains: Option[] = [
{ label: 'Ethereum Mainnet', value: RpcChainType.ETH },
{ label: 'Ethereum Mainnet (FLASHBOT)', value: RpcChainType.ETH_FLASHBOTS },
{ label: 'Avalanche Mainnet', value: RpcChainType.AVAX },
{ label: 'Polygon Mainnet', value: RpcChainType.POLYGON },
{ label: 'BSC Mainnet', value: RpcChainType.BSC },
{ label: 'Ethereum Mainnet', value: RpcId.ETH },
{ label: 'Ethereum Mainnet (FLASHBOT)', value: RpcId.ETH_FLASHBOTS },
{ label: 'Avalanche Mainnet', value: RpcId.AVAX },
{ label: 'Polygon Mainnet', value: RpcId.POLYGON },
{ label: 'BSC Mainnet', value: RpcId.BSC },
]

function WalletConfig({ dispatch, state } : dispatchAndConsume) {
const [customEndpoint, setCustomEndpoint] = useState<RpcChainType>(availableChains[0].value)
const [customEndpoint, setCustomEndpoint] = useState<RpcId>(availableChains[0].value)
const getAccountClass = () => (
state.selectedChain === WalletChains.Avalanche ? [avalanche, window.ethereum]
: state.selectedChain === WalletChains.Substrate ? [substrate, null]
: state.selectedChain === WalletChains.Ethereum ? [ethereum, window.ethereum]
: state.selectedChain === WalletChains.Solana ? [solana, window.phantom?.solana]
: [null, null]
Expand Down
66 changes: 66 additions & 0 deletions examples/toolshed/src/components/WebSocket.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { useState } from "react";
import { GetMessagesSocket } from "../../../../src/messages/any";
import {AlephSocket, SocketResponse} from "../../../../src/messages/any/getMessagesSocket";

function WebSocket() {
const [socket, setSocket] = useState<AlephSocket | undefined>()
const [data, setData] = useState<SocketResponse[]>([]);

const startSocket = async () => {
const newSocket = GetMessagesSocket({});

setSocket(newSocket);
}

const displayContent = async () => {
if (!socket) return;
setData([...socket.getData()]);
}

const clearSocket = async () => {
socket?.clearData();
await displayContent();
}

const closeSocket = async () => {
socket?.closeSocket()
setSocket(undefined);
}

return (
<>
<div style={{display: 'flex', flexWrap:'wrap', gap: '6px'}}>
<button onClick={startSocket} disabled={!!socket}>Open WebSocket</button>
<button onClick={displayContent} disabled={!socket}>Display</button>
<button onClick={clearSocket} disabled={!socket}>Clear Data</button>
<button onClick={closeSocket} disabled={!socket}>Close Socket</button>
</div>

<p>Total: {data.length}</p>
<div>
{ !!socket ? (<table style={{marginTop: '2em'}}>
<thead>
<tr>
<th>Sender</th>
<th>Chain</th>
<th>Hash</th>
</tr>
</thead>
<tbody>
{data.map((line, id) => {
return (
<tr key={id}>
<td>{`${line.sender.substring(0, 6,)}...${line.sender.substring(line.sender.length - 4,)}`}</td>
<td>{line.chain}</td>
<td>{line.item_hash}</td>
</tr>
)
})}
</tbody>
</table>) : (<p>Socket is closed</p>)}
</div>
</>
)
}

export default WebSocket
1 change: 1 addition & 0 deletions examples/toolshed/src/model/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum HardwareChains {

export enum WalletChains {
Avalanche = "AVAX",
Substrate = "DOT",
Ethereum = "ETH",
Solana = "SOL",
}
Expand Down
Loading

0 comments on commit c876543

Please sign in to comment.