Skip to content

Commit ce26f48

Browse files
committed
wip: update
1 parent a70de02 commit ce26f48

File tree

2 files changed

+83
-3
lines changed

2 files changed

+83
-3
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { useTranslation } from "react-i18next"
2+
import { PerunRequest as PerunRequestSubject } from 'services/subjects'
3+
import { useState as useGlobalState } from 'states'
4+
import { channelIdToString, channelIdFromString } from '@ckb-connect/perun-wallet-wrapper/dist/translator'
5+
import * as wire from '@ckb-connect/perun-wallet-wrapper/dist/wire'
6+
import { getParticipantByAddressAndPubkey, isSuccessResponse } from "utils"
7+
import { perunServiceAction } from "services/remote"
8+
import { useEffect } from "react"
9+
10+
const accountFrom = {
11+
address: "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvujnwcyyexhcsddzu74yks6ytchq26y0svu4675",
12+
pubKey: "0x02372431f7ce5e18e100e56d6d8e74145ec00ad59878887a353aca8ca52e64119c",
13+
payload: {
14+
type: null,
15+
amout: 100,
16+
}
17+
}
18+
19+
const accountTo = {
20+
address: "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqd4a33y7unx66rqh03vwngh3e4t0x6yrhcd9sfns",
21+
pubKey: "0x02a5b7bb6196db5edcd38c55de70ae61d4bc52cd8b1195cfa6278ca43c11a35ab3",
22+
payload: {
23+
type: null,
24+
amout: 100,
25+
}
26+
}
27+
28+
29+
export default function PaymentChannelDemo() {
30+
const { wallet } = useGlobalState()
31+
const [t, _] = useTranslation()
32+
33+
useEffect(() => {
34+
const { unsubscribe } = PerunRequestSubject.subscribe(requests => {
35+
console.log("[Perun] on request subscribe", { requests })
36+
})
37+
return unsubscribe;
38+
}, [])
39+
40+
useEffect(() => {
41+
getChannels()
42+
.then(channels => {
43+
console.log("[Perun] channles", channels)
44+
})
45+
}, [])
46+
47+
48+
49+
return (
50+
<>
51+
????
52+
<div style={{ marginBlock: 8, height: 2, width: "100%", backgroundColor: "#333" }}></div>
53+
</>
54+
);
55+
}
56+
57+
58+
59+
async function getChannels() {
60+
const requester = getParticipantByAddressAndPubkey(accountFrom.address, accountFrom.pubKey);
61+
const actionRes = await perunServiceAction({
62+
type: 'get',
63+
payload: {
64+
requester,
65+
},
66+
})
67+
if (!isSuccessResponse(actionRes) || !actionRes?.result) {
68+
console.log("get channles failed:", actionRes)
69+
return
70+
}
71+
console.log("get channles success:", actionRes.result)
72+
73+
return actionRes.result.channels
74+
}
75+
// todo restore channel
76+
// todo update channel
77+
// todo close channel
78+
// todo sign tx

packages/neuron-ui/src/components/PaymentChannel/index_o.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,22 @@ import { PasswordDialog } from 'components/SignAndVerify'
4242
import { State } from '@ckb-connect/perun-wallet-wrapper/dist/wire'
4343
import TextField from 'widgets/TextField'
4444
import styles from './perun.module.scss'
45+
import PaymentChannelDemo from './demo'
4546

4647
const Perun = () => {
4748
const { wallet } = useGlobalState()
4849
const [t, _] = useTranslation()
4950
const [amount, setAmount] = useState<number>(100)
5051
const [updateAmount, setUpdateAmount] = useState<number>(100)
5152
const [peerAddress, setPeerAddress] = useState(
52-
'ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq2jyhhmdq7ujffqla0n3jtt6l0yy0hflycvakuds'
53+
'ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqd4a33y7unx66rqh03vwngh3e4t0x6yrhcd9sfns'
5354
)
54-
const peerPubKey = '0x0260065151b232cb34bcd62447b46c3683480e4de1ce95b63212187a1ff36cc0da'
55+
const peerPubKey = '0x02a5b7bb6196db5edcd38c55de70ae61d4bc52cd8b1195cfa6278ca43c11a35ab3'
5556
const [peerAmount, setPeerAmount] = useState<number>(100)
5657
const [challengeDuration, setChallengeDuration] = useState<number>(10000)
5758
const [validInputs, setValidInputs] = useState(false)
5859
const [channels] = useState(new Map<string, State>())
59-
const [showRejectionModal, setShowRejectionModal] = useState(true)
60+
const [showRejectionModal, setShowRejectionModal] = useState(false)
6061
const [rejectionReason, setRejectionReason] = useState('')
6162
const [updateChannelDialog, setUpdateChannelDialog] = useState(false)
6263
const [channelID, setChannelID] = useState<Uint8Array>()
@@ -554,6 +555,7 @@ const Perun = () => {
554555
</div>
555556
}
556557
>
558+
<PaymentChannelDemo />
557559
<div className={styles.header}>
558560
<div className={styles.daoContainer}>
559561
<Dialog show={showPrompt} showFooter={false}>

0 commit comments

Comments
 (0)