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(demo): add basic avm-provider #36

Merged
merged 3 commits into from
Aug 28, 2024
Merged
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
126 changes: 125 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sites/dapp-ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
Expand Down
4 changes: 3 additions & 1 deletion sites/dapp-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
"lint": "eslint \"{src,apps,libs,test}/**/*.{ts,tsx}\" --fix"
},
"dependencies": {
"@algorandfoundation/liquid-client": "github:algorandfoundation/liquid-auth-js#chore/switch-request-id-to-uuid",
"@algorandfoundation/provider": "github:algorandfoundation/wallet-provider-ts",
"@algorandfoundation/liquid-client": "github:algorandfoundation/liquid-auth-js",
"@emotion/react": "^11.11.3",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.15.4",
"@mui/material": "^5.15.4",
"@tanstack/react-query": "^5.20.5",
"@tanstack/react-query-devtools": "^5.20.5",
"cbor-x": "^1.6.0",
"qr-code-styling": "^1.6.0-rc.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion sites/dapp-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Algodv2 } from 'algosdk';
import { AlgodContext } from '@/hooks';
import { SignalClientContext } from '@/hooks/useSignalClient.ts';
import { LinkMessage, SignalClient } from '@algorandfoundation/liquid-client';
import { useAddressStore } from '@/store';
import { useAddressStore } from '@/store.ts';
const queryClient = new QueryClient();

const algod = new Algodv2(
Expand Down
24 changes: 24 additions & 0 deletions sites/dapp-ui/src/components/ArcMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { MessageState } from "@/store.ts";
import Card from "@mui/material/Card";
import { CardHeader } from "@mui/material";
import Typography from "@mui/material/Typography";
import CardContent from "@mui/material/CardContent";

export function ArcMessage(state: MessageState) {
return (
<Card sx={{ flex: 1, margin: 1.25 }} raised>
<CardHeader
title={state.message.reference}
subheader={state.message.id}
/>
<CardContent>
<Typography variant="h5" color="text.secondary">
{state.status}
</Typography>
<Typography variant="body1" color="text.secondary">
{JSON.stringify(state.message)}
</Typography>
</CardContent>
</Card>
);
}
46 changes: 0 additions & 46 deletions sites/dapp-ui/src/components/MessageCard.tsx

This file was deleted.

40 changes: 0 additions & 40 deletions sites/dapp-ui/src/components/TransactionCard.tsx

This file was deleted.

1 change: 0 additions & 1 deletion sites/dapp-ui/src/entry-main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import './index.css';
import * as ReactDOM from 'react-dom/client';
// import { StrictMode } from 'react';
import App from './App.tsx';

ReactDOM.createRoot(document.getElementById('root')!).render(
// <StrictMode>
<App />,
Expand Down
7 changes: 6 additions & 1 deletion sites/dapp-ui/src/hooks/useDataChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
*/
export function useDataChannel(onMessage?: (event: MessageEvent) => void) {
const { dataChannel } = useContext(SignalClientContext);
function onError(...args: any[]) {

Check warning on line 10 in sites/dapp-ui/src/hooks/useDataChannel.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 10 in sites/dapp-ui/src/hooks/useDataChannel.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type
console.error('Data channel error', args);
}
useEffect(() => {
if (!dataChannel || !onMessage) return;
dataChannel.addEventListener('message', onMessage);
dataChannel.addEventListener('error', onError)
return () => {
dataChannel.removeEventListener('message', onMessage);
};
dataChannel.removeEventListener('error', onError);
}
}, [dataChannel, onMessage]);

return dataChannel;
Expand Down
2 changes: 2 additions & 0 deletions sites/dapp-ui/src/hooks/useSignalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type SignalClientState = {
setStatus: (_: 'connected' | 'disconnected') => void;
dataChannel: RTCDataChannel | null;
setDataChannel: (_: RTCDataChannel | null) => void;
loading: boolean;
setLoading: (_: boolean) => void;
};
export const SignalClientContext = createContext({
client: null,
Expand Down
21 changes: 21 additions & 0 deletions sites/dapp-ui/src/lib/provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {decode} from 'cbor-x'
import { decodeUnsignedTransaction } from "algosdk";
import { IARC0001Transaction, ResponseMessage, Results, fromBase64Url } from "@algorandfoundation/provider";

export function attachEncodedSignature(address: string, txn: string, signature: string){
return decodeUnsignedTransaction(fromBase64Url(txn))
.attachSignature(address, fromBase64Url(signature));
}

export function attachSignedTransactionsFromResult(address: string, result: Results, txns: IARC0001Transaction[]){
let stxns = [];
for(let i = 0; i < txns.length; i++){
stxns.push(attachEncodedSignature(address, txns[i].txn, result.stxns[i]!!))
}
return stxns
}

export function fromResult(result: string): ResponseMessage {
return decode(fromBase64Url(result)) as ResponseMessage
}

Loading
Loading