Skip to content

Commit

Permalink
fix rendering of an ScVec that contains BigInt - stringify was failing
Browse files Browse the repository at this point in the history
add a number of previously unrendered effects and 1 op
  • Loading branch information
chatch committed Sep 17, 2023
1 parent f6f6c2c commit 2265bc1
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 7 deletions.
84 changes: 84 additions & 0 deletions app/components/Effect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import RelativeTime from "./shared/RelativeTime"
import TransactionHash from "./shared/TransactionHash"

import { base64Decode } from "../lib/utils"
import Unrecognized from "./operations/Unrecognized"

export type EffectProps = ServerApi.EffectRecord & { op?: ServerApi.OperationRecord }

Expand Down Expand Up @@ -209,6 +210,63 @@ const Thresholds = ({ lowThreshold, medThreshold, highThreshold }: any) => (
</span>
)

const ClaimableBalanceCreated = ({ account, amount, asset }: any) => {
const [assetCode, assetIssuer] = asset.split(':')
return (
<span>
<AccountLink account={account} /> created balance for {amount} <Asset code={assetCode} issuer={assetIssuer} type="unknown" /></span>
)
}

const ClaimableBalanceClaimed = ({ account, amount, asset }: any) => {
const [assetCode, assetIssuer] = asset.split(':')
return (
<span>
<AccountLink account={account} /> claimed {amount} <Asset code={assetCode} issuer={assetIssuer} type="unknown" /></span>
)
}

const ClaimableBalanceClaimantCreated = ({ account, amount, asset, predicate }: any) => {
const [assetCode, assetIssuer] = asset.split(':')
return (
<span>
<AccountLink account={account} /> sponsored for {amount} <Asset code={assetCode} issuer={assetIssuer} type="unknown" /></span>
)
}

const ClaimableBalanceSponsorshipCreated = ({ sponsor }: any) => (
<span>
<AccountLink account={sponsor} /> created claimable balance sponsorship
</span>
)

const ClaimableBalanceSponsorshipRemoved = ({ account, formerSponsor }: any) => (
<span>
<AccountLink account={formerSponsor} /> revoked sponsored balance from <AccountLink account={account} />
</span>
)

const LiquidityPoolTrade = ({ account, bought, sold }: any) => {
const [boughtCode, boughtIssuer] = bought.asset.split(':')
const [soldCode, soldIssuer] = sold.asset.split(':')

return (
<span>
<AccountLink account={account} /> bought {bought.amount}&nbsp;
<Asset code={boughtCode} issuer={boughtIssuer} type="unknown" /> for&nbsp;
{sold.amount}&nbsp;
<Asset code={soldCode} issuer={soldIssuer} type="unknown" />
</span>
)
}

const Fallback = (props: any) => (
<span>
Not handled, keys are:
{Object.keys(props).join(',')}
</span>
)

const effectTypeComponentMap = {
account_created: AccountCreated,
account_removed: AccountRemoved,
Expand All @@ -235,6 +293,32 @@ const effectTypeComponentMap = {
data_updated: Data,
contract_credited: ContractDebitCredit,
contract_debited: ContractDebitCredit,

claimable_balance_created: ClaimableBalanceCreated,
claimable_balance_claimed: ClaimableBalanceClaimed,
claimable_balance_claimant_created: ClaimableBalanceClaimantCreated,
// account_sponsorship_created
// account_sponsorship_updated
// account_sponsorship_removed
// trustline_sponsorship_created
// trustline_sponsorship_updated
// trustline_sponsorship_removed
// data_sponsorship_created
// data_sponsorship_updated
// data_sponsorship_removed
claimable_balance_sponsorship_created: ClaimableBalanceSponsorshipCreated,
// claimable_balance_sponsorship_updated
claimable_balance_sponsorship_removed: ClaimableBalanceSponsorshipRemoved,
// signer_sponsorship_created
// signer_sponsorship_updated
// signer_sponsorship_removed

// - liquidity_pool_deposited
// - liquidity_pool_withdrew
liquidity_pool_trade: LiquidityPoolTrade,
// - liquidity_pool_created
// - liquidity_pool_removed
// - liquidity_pool_revoked
}

type EffectComponentMapKey = keyof typeof effectTypeComponentMap
Expand Down
12 changes: 12 additions & 0 deletions app/components/operations/ClaimableBalances.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import AccountLink from "../shared/AccountLink"
import Asset from "../shared/Asset"

const CreateClaimableBalanceOperation = ({ amount, sponsor, asset }: any) => {
const [assetCode, assetIssuer] = asset.split(':')
return (
<span>
<AccountLink account={sponsor} /> created claimable balance for {amount} <Asset code={assetCode} issuer={assetIssuer} type="unknown" /></span>
)
}

export { CreateClaimableBalanceOperation }
6 changes: 6 additions & 0 deletions app/components/operations/LiquidityPool.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import AccountLink from "../shared/AccountLink"
import Asset from "../shared/Asset"



// export { LiquidityPoolTradeOperation }
3 changes: 3 additions & 0 deletions app/components/operations/Operation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import AccountMerge from "./AccountMerge"
import AllowTrust, { AllowTrustProps } from "./AllowTrust"
import BumpSequence from "./BumpSequence"
import ChangeTrust from "./ChangeTrust"
import { CreateClaimableBalanceOperation } from "./ClaimableBalances"
import CreateAccount, { CreateAccountProps } from "./CreateAccount"
import Inflation from "./Inflation"
import InvokeHostFunction from "./InvokeHostFunction"
Expand All @@ -30,6 +31,8 @@ const OperationTypeToComponentMap = {
create_passive_sell_offer: Offer,
create_passive_offer: Offer, // < Protocol 11

create_claimable_balance: CreateClaimableBalanceOperation,

inflation: Inflation,

invoke_host_function: InvokeHostFunction,
Expand Down
16 changes: 10 additions & 6 deletions app/components/operations/Unrecognized.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { FormattedMessage } from 'react-intl'

const Unrecognized = ({ type }: { type: string }) => <FormattedMessage
id="operation.unrecognized"
values={{
type: type,
}}
/>
const Unrecognized = (props: any) => {
const { type }: { type: string } = props
console.log(JSON.stringify(props, null, 2))
return (<FormattedMessage
id="operation.unrecognized"
values={{
type: type,
}}
/>)
}

export default Unrecognized
2 changes: 1 addition & 1 deletion app/components/shared/Asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface AssetProps {
}

export default ({ code, issuer, type }: AssetProps) => {
const isLumens = type === 'native'
const isLumens = type === 'native' || code === 'native'
const propCode = isLumens ? 'XLM' : code
return (
<span>
Expand Down
2 changes: 2 additions & 0 deletions app/lib/stellar/xdr_scval_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const scValToString = (scVal: any) => {
return native
} else if (typeof native === 'bigint') {
return native.toString()
} else if (Array.isArray(native)) {
return native.map(val => typeof val === 'bigint' ? val.toString() : val)
} else {
return JSON.stringify(native)
}
Expand Down
60 changes: 60 additions & 0 deletions app/routes/effects.$opId.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { ServerApi } from "stellar-sdk"

import Card from 'react-bootstrap/Card'
import CardHeader from 'react-bootstrap/CardHeader'
import Container from 'react-bootstrap/Container'
import Row from 'react-bootstrap/Row'
import { FormattedMessage, useIntl } from 'react-intl'
import { requestToServer } from '~/lib/stellar/server'

import { LoaderArgs, json } from '@remix-run/node'
import { useLoaderData } from '@remix-run/react'

import EffectTable from '../components/EffectTable'
import { setTitle } from '../lib/utils'

import { effects } from '~/lib/stellar/server_request_utils'
import { EffectProps } from "~/components/Effect"
import { useEffect } from "react"

export const loader = ({ request, params }: LoaderArgs) => {
const server = requestToServer(request)
return effects(server, { operationId: params.opId }).then(effects =>
effects.map(
(effect: ServerApi.EffectRecord) => ({
...effect,
op: effect.operation ? effect.operation() : undefined
}) as EffectProps
)
).then(json)
}

export default function Effects() {
const records = useLoaderData<typeof loader>()

const { formatMessage } = useIntl()
useEffect(() => {
setTitle(formatMessage({ id: 'effects' }))
}, [])

return (
<Container>
<Row>
<Card>
<CardHeader>
<FormattedMessage id="effects" />
</CardHeader>
<Card.Body>
<EffectTable
records={records as ReadonlyArray<EffectProps>}
// showEffect
// showSource
// compact={false}
// limit={20}
/>
</Card.Body>
</Card>
</Row>
</Container>
)
}

0 comments on commit 2265bc1

Please sign in to comment.