Skip to content

Commit

Permalink
Merge branch 'cs-delegation-verify' into cs-delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosala committed Aug 21, 2024
2 parents 95e8318 + cf4a04f commit 1502747
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/actions/delegate/ChooseChain.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Link } from "react-router-dom"

const SUPPORTED_CHAINS = ["polkadot", "kusama"]
import { SUPPORTED_CHAINS } from "./utils"

export const ChooseChain = () => {
return (
Expand Down
33 changes: 25 additions & 8 deletions src/actions/delegate/ChooseDelegate.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { useStateObservable } from "@react-rxjs/core"
import { Link } from "react-router-dom"
import { routeChain$ } from "./delegate"
import { isChainValid } from "./utils"

const SUPPORTED_DELEGATES: Array<{ address: string; name: string }> = [
{
Expand All @@ -12,19 +15,33 @@ const SUPPORTED_DELEGATES: Array<{ address: string; name: string }> = [
]

export const ChooseDelegate = () => {
const chainData = useStateObservable(routeChain$)
return (
<div className="flex flex-col text-center items-center">
<h1 className="text-lg my-5 font-semibold">Choose delegate</h1>
{SUPPORTED_DELEGATES.map(({ address, name }) => (
<Link to={address}>
{isChainValid(chainData ?? "") ? (
<>
<h1 className="text-lg my-5 font-semibold">Choose delegate</h1>
{SUPPORTED_DELEGATES.map(({ address, name }) => (
<Link to={address}>
<div className="flex flex-col text-left border-[1px] border-gray-200 rounded-lg p-5">
<h2 className="text-lg font-semibold">{name}</h2>
<div className="flex flex-row justify-between gap-2">
Address: <div className="text-right">{address}</div>
</div>
</div>
</Link>
))}
</>
) : (
<Link to="..">
<h1 className="text-lg my-5 font-semibold">Chain not supported.</h1>
<div className="flex flex-col text-left border-[1px] border-gray-200 rounded-lg p-5">
<h2 className="text-lg font-semibold">{name}</h2>
<div className="flex flex-row justify-between gap-2">
Address: <div className="text-right">{address}</div>
</div>
<h2 className="text-lg font-semibold">
Click here to choose chain
</h2>
</div>
</Link>
))}
)}
</div>
)
}
2 changes: 1 addition & 1 deletion src/actions/delegate/DelegateAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const [convictionInput$, onConvictionInputChanges] = createSignal<
>()
const conviction$: StateObservable<0 | 1 | 2 | 3 | 4 | 5 | 6 | SUSPENSE> =
state(
combineLatest(routeChain$, delegateAccount$, selectedAccount$).pipe(
combineLatest([routeChain$, routeDelegateAccount$, selectedAccount$]).pipe(
switchMapSuspended(([, , account]) => {
if (!account) return EMPTY
return concat(
Expand Down
6 changes: 2 additions & 4 deletions src/actions/delegate/delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ export const routeChain$ = state(
routeMatch$(PATTERN_CHAIN).pipe(
map((routeData) => routeData?.params?.chain ?? null),
),
null,
)
routeChain$.subscribe()

export const delegateAccount$ = state(
export const routeDelegateAccount$ = state(
routeMatch$(PATTERN_ACCOUNT).pipe(
map((routeData) => routeData?.params?.account ?? null),
),
null,
)
delegateAccount$.subscribe()
routeDelegateAccount$.subscribe()
13 changes: 13 additions & 0 deletions src/actions/delegate/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getSs58AddressInfo } from "polkadot-api"

export const SUPPORTED_CHAINS = ["polkadot", "kusama"]

export const isChainValid = (chain: string) => SUPPORTED_CHAINS.includes(chain)

export const isAddressValid = (addr: string) => {
try {
return getSs58AddressInfo(addr).isValid
} catch {
return false
}
}
10 changes: 8 additions & 2 deletions src/api/delegation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Enum, SS58String } from "polkadot-api"
import { polkadotApi as api } from "./"
import { Binary, Enum, SS58String } from "polkadot-api"
import { polkadotApi as api, polkadotPeopleApi } from "./"
import { MultiAddress, VotingConviction } from "@polkadot-api/descriptors"

export const getOptimalAmount = async (
Expand Down Expand Up @@ -98,6 +98,12 @@ export const getTrackInfo = async (
)
}

export const getAddressName = async (addr: string): Promise<string> => {
const id = await polkadotPeopleApi.query.Identity.IdentityOf.getValue(addr)
if (id == null || id[0].info.display.value == null) return addr
return id[0].info.display.value.asText()
}

export const delegate = async (
from: SS58String,
target: SS58String,
Expand Down

0 comments on commit 1502747

Please sign in to comment.