Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

chore: upgrade capi to gamma.1 #217

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 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
3 changes: 1 addition & 2 deletions nets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { net } from "capi"
import { net } from "capi/nets"

export const westend = net.ws({
url: "wss://westend-rpc.polkadot.io/",
version: "v0.9.42",
})
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@headlessui/react": "^1.7.15",
"@preact/signals": "^1.1.3",
"@talisman-connect/wallets": "^1.1.3",
"capi": "0.1.0-beta.42",
"capi": "0.1.0-gamma.1",
"dotenv": "^16.1.4",
"preact": "^10.15.1",
"react-hook-form": "^7.44.3",
Expand Down Expand Up @@ -41,6 +41,6 @@
"start:docker": "sudo docker-compose up --build --abort-on-container-exit",
"start:docker:db": "docker-compose up --build --abort-on-container-exit dynamodb",
"clean:docker": "docker-compose down --rmi all",
"sync": "capi sync node --runtime-config package.json --server https://capi.dev"
"sync": "capi sync node --server https://capi.dev"
peetzweg marked this conversation as resolved.
Show resolved Hide resolved
peetzweg marked this conversation as resolved.
Show resolved Hide resolved
}
}
213 changes: 106 additions & 107 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

77 changes: 43 additions & 34 deletions server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,23 @@ wsServer.on("connection", (ws, _req) => {
channels[decoded.channel] = new Set()
}
channels[decoded.channel]?.add(ws)
ws.send($result.encode({
type: "subscribe",
channel: decoded.channel,
result: "ok",
}))
ws.send(
$result.encode({
type: "subscribe",
channel: decoded.channel,
result: "ok",
}),
)
break
case "unsubscribe":
if (channels[decoded.channel]?.delete(ws)) {
ws.send($result.encode({
type: "unsubscribe",
channel: decoded.channel,
result: "ok",
}))
ws.send(
$result.encode({
type: "unsubscribe",
channel: decoded.channel,
result: "ok",
}),
)
}
break
case "submit":
Expand All @@ -79,19 +83,18 @@ async function handleSubmit(ws: ws.WebSocket, submit: Submit): Promise<void> {
channels[submit.channel]?.forEach((ws) => ws.send(data))
}

await SignedExtrinsicRune.fromHex(
westend,
submit.signedExtrinsic,
)
await SignedExtrinsicRune.fromHex(westend, submit.signedExtrinsic)
.sent()
.dbgStatus("tx status")
.transactionStatuses((txStatus) => {
if (typeof txStatus === "string") {
send($result.encode({
type: "submit",
channel: submit.channel,
result: { status: txStatus },
}))
send(
$result.encode({
type: "submit",
channel: submit.channel,
result: { status: txStatus },
}),
)
} else {
const status = Object.keys(txStatus)[0]!
switch (status) {
Expand All @@ -104,19 +107,23 @@ async function handleSubmit(ws: ws.WebSocket, submit: Submit): Promise<void> {
case "usurped":
case "dropped":
case "invalid":
send($result.encode({
type: "submit",
channel: submit.channel,
result: { status },
}))
send(
$result.encode({
type: "submit",
channel: submit.channel,
result: { status },
}),
)
break
case "finalized":
const hash: string = txStatus["finalized"]! as string
send($result.encode({
type: "submit",
channel: submit.channel,
result: { status, hash },
}))
send(
$result.encode({
type: "submit",
channel: submit.channel,
result: { status, hash },
}),
)
break
}
}
Expand All @@ -125,11 +132,13 @@ async function handleSubmit(ws: ws.WebSocket, submit: Submit): Promise<void> {
})
.run()
} catch (err) {
ws.send($result.encode({
type: "submit",
channel: submit.channel,
result: { status: "failed" },
}))
ws.send(
$result.encode({
type: "submit",
channel: submit.channel,
result: { status: "failed" },
}),
)
handleError(err)
}
}
1 change: 0 additions & 1 deletion server/scripts/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions server/scripts/create-user.ts

This file was deleted.

45 changes: 0 additions & 45 deletions server/scripts/send-transfer.ts

This file was deleted.

3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"noEmit": true
},
"files": [],
"references": [{ "path": "www" }, { "path": "server" }, { "path": "common" }]
}
1 change: 1 addition & 0 deletions www/src/components/Setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { accounts, defaultAccount, defaultSender } from "../signals/accounts.js"
import { formatBalance } from "../util/balance.js"
import { toMultiAddressIdRune, toMultisigRune } from "../util/capi-helpers.js"
import { filterEvents, handleException } from "../util/events.js"

import { AccountId } from "./AccountId.js"
import { Button } from "./Button.js"
import { CenteredCard } from "./CenteredCard.js"
Expand Down
14 changes: 8 additions & 6 deletions www/src/components/wizards/multisig/Fund.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { defaultSender } from "../../../signals/accounts.js"
import { toBalance } from "../../../util/balance.js"
import { toMultiAddressIdRune } from "../../../util/capi-helpers.js"
import { filterEvents, handleException } from "../../../util/events.js"

import { BalanceInput } from "../../BalanceInput.js"
import { Button } from "../../Button.js"
import { goNext } from "../Wizard.js"
Expand All @@ -25,7 +26,9 @@ export function MultisigFund() {
resolver: zodResolver(multisigFundSchema),
mode: "onChange",
})
const { value: { fundingAmount, stash } } = wizardData
const {
value: { fundingAmount, stash },
} = wizardData

const onSubmit = async (formDataNew: MultisigFundEntity) => {
try {
Expand All @@ -34,11 +37,10 @@ export function MultisigFund() {

if (!sender || !stash) return

const fundStashCall = westend.Balances
.transfer({
value: toBalance(fundingAmount),
dest: toMultiAddressIdRune(stash),
})
const fundStashCall = westend.Balances.transfer({
value: toBalance(fundingAmount),
dest: toMultiAddressIdRune(stash),
})
.signed(signature({ sender }))
.sent()
.dbgStatus("Transfer:")
Expand Down
12 changes: 6 additions & 6 deletions www/src/components/wizards/multisig/Members.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { MultiAddress, Westend, westend } from "@capi/westend"
import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js"
import { Rune, ss58 } from "capi"
import { MultisigRune } from "capi/patterns/multisig"
import { replaceDelegateCalls } from "capi/patterns/proxy"
import { signature } from "capi/patterns/signature/polkadot"
import {
filterPureCreatedEvents,
replaceDelegateCalls,
} from "capi/patterns/unstable/proxy"
import { Controller, useForm } from "react-hook-form"
import {
accounts,
Expand All @@ -16,12 +19,9 @@ import {
PROXY_DEPOSIT_BASE,
PROXY_DEPOSIT_FACTOR,
} from "../../../util/chain-constants.js"
import {
filterEvents,
filterPureCreatedEvents,
handleException,
} from "../../../util/events.js"
import { filterEvents, handleException } from "../../../util/events.js"
import { storeSetup } from "../../../util/local-storage.js"

import { AccountSelect } from "../../AccountSelect.js"
import { Button } from "../../Button.js"
import { IconChevronLeft } from "../../icons/IconChevronLeft.js"
Expand Down
23 changes: 10 additions & 13 deletions www/src/components/wizards/multisig/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Button } from "../../Button.js"
import { wizardData } from "./wizardData.js"

export function MultisigSummary() {
const { value: { name, fundingAmount, members } } = wizardData
const {
value: { name, fundingAmount, members },
} = wizardData

return (
<div>
Expand All @@ -12,30 +14,25 @@ export function MultisigSummary() {
<pre className="bg-gray-100 p-4 rounded-lg shadow-md overflow-x-auto space-y-2">
<div className="flex items-center">
<span className="font-bold text-gray-800">Multisig name:</span>
<span className="font-mono text-gray-900">
{name}
</span>
<span className="font-mono text-gray-900">{name}</span>
</div>
<div className=" items-center">
<div className="items-center">
<span className="font-bold text-gray-800">Multisig members:</span>
<ul className="font-mono text-gray-900">
{members.map((v, i)=><li key={i}>{v?.address}</li>)}
{members.map((v, i) => (
<li key={i}>{v?.address}</li>
))}
</ul>
</div>
<div className="flex items-center">
<span className="font-bold text-gray-800">Multisig fund:</span>
<span className="font-mono text-gray-900">
{fundingAmount}
</span>
<span className="font-mono text-gray-900">{fundingAmount}</span>
</div>
</pre>
<hr className="divide-x-0 divide-gray-300 mt-4 mb-2" />
<div className="flex justify-end">
<Link to="/">
<Button
type="submit"
variant="primary"
>
<Button type="submit" variant="primary">
Done
</Button>
</Link>
Expand Down
1 change: 1 addition & 0 deletions www/src/components/wizards/transaction/New.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useSearchParams } from "react-router-dom"
import { defaultAccount } from "../../../signals/accounts.js"
import { setups } from "../../../signals/setups.js"
import { formatBalance } from "../../../util/balance.js"

import { AccountId } from "../../AccountId.js"
import { AccountSelect } from "../../AccountSelect.js"
import { AddressInput } from "../../AddressInput.js"
Expand Down
1 change: 1 addition & 0 deletions www/src/components/wizards/transaction/Sign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useNavigate } from "react-router-dom"
import { toBalance } from "../../../util/balance.js"
import { filterEvents, handleException } from "../../../util/events.js"
import { storeCall } from "../../../util/local-storage.js"

import { AccountId } from "../../AccountId.js"
import { Button } from "../../Button.js"
import { IconTrash } from "../../icons/IconTrash.js"
Expand Down
1 change: 1 addition & 0 deletions www/src/components/wizards/transaction/signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MultiAddress, Westend, westend } from "@capi/westend"
import { effect, Signal, signal } from "@preact/signals"
import { ExtrinsicRune, ss58 } from "capi"
import { toBalance } from "../../../util/balance.js"

import { transactionData } from "./formData.js"

export const call = signal<ExtrinsicRune<Westend, never> | undefined>(undefined)
Expand Down
17 changes: 13 additions & 4 deletions www/src/signals/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { westend } from "@capi/westend"
import { computed, effect, signal } from "@preact/signals"
import { Westend, westend } from "@capi/westend"
import {
computed,
effect,
ReadonlySignal,
Signal,
signal,
} from "@preact/signals"
import { getWalletBySource, WalletAccount } from "@talisman-connect/wallets"
import { ExtrinsicSender, ValueRune } from "capi"
import { pjsSender } from "capi/patterns/compat/pjs_sender"
import { retrieveStored } from "../util/local-storage.js"
import { retry } from "../util/retry.js"
Expand All @@ -9,12 +16,14 @@ interface InjectedWindow extends Window {
injectedWeb3: unknown
}

const accounts = signal<WalletAccount[]>([])
const accounts: Signal<WalletAccount[]> = signal<WalletAccount[]>([])
const storedAccount = retrieveStored("defaultAccount")
const storedExtension = retrieveStored("defaultExtension")
const defaultAccount = signal(storedAccount)
const defaultExtension = signal(storedExtension)
const defaultSender = computed(() => {
const defaultSender: ReadonlySignal<
ValueRune<ExtrinsicSender<Westend>, never> | undefined
> = computed(() => {
const { signer } = defaultExtension.value || {}
const { address: userAddress } = defaultAccount.value || {}
if (!signer || !userAddress) return
Expand Down
4 changes: 3 additions & 1 deletion www/src/util/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export function toBalance(value: number, tokenDecimals = 12): bigint {

const [integer = "0", _ = "0"] = String(value).split(".")
const decimal = _.substring(0, tokenDecimals)
return BigInt(integer) * 10n ** BigInt(tokenDecimals)
return (
BigInt(integer) * 10n ** BigInt(tokenDecimals)
+ BigInt(decimal) * 10n ** BigInt(tokenDecimals - decimal.length)
)
}
Loading