Skip to content

Commit

Permalink
refactor(app): simulation results
Browse files Browse the repository at this point in the history
  • Loading branch information
hbriese committed Aug 6, 2024
1 parent 9d4ba4e commit f154d7b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 65 deletions.
81 changes: 49 additions & 32 deletions app/src/components/transaction/OperationsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ const Transaction = graphql`
operations {
...OperationSection_operation
}
simulation {
result {
__typename
id
success
responses
response
... on Failure {
reason
}
}
...OperationSection_transaction
}
Expand All @@ -36,23 +39,10 @@ export function OperationsSection(props: OperationsSectionProps) {
const { styles } = useStyles(stylesheet);
const p = useFragment(Transaction, props.transaction);

const simulatedErrorSelector =
p.simulation?.responses.length &&
bytesize(p.simulation.responses[0]) >= 4 &&
slice(p.simulation.responses[0], 0, 4);

const expectedFailureItem = p.simulation?.success === false && (
<ListItem
leading={<AlertIcon size={ICON_SIZE.medium} color={styles.error.color} />}
headline={({ Text }) => <Text style={styles.error}>Expected to fail</Text>}
supporting={
simulatedErrorSelector
? `Error: ${simulatedErrorSelector}`
: 'No error message was provided'
}
trailing={simulatedErrorSelector ? SearchIcon : undefined}
/>
);
const errorSelector =
p.result?.__typename === 'SimulatedFailure' &&
bytesize(p.result.response) >= 4 &&
slice(p.result.response, 0, 4);

return (
<>
Expand All @@ -62,18 +52,45 @@ export function OperationsSection(props: OperationsSectionProps) {
<OperationSection key={i} transaction={p} operation={operation} />
))}

{expectedFailureItem &&
(simulatedErrorSelector ? (
<Link
asChild
href={`https://openchain.xyz/signatures?query=${simulatedErrorSelector}`}
target="_blank"
>
{expectedFailureItem}
</Link>
) : (
expectedFailureItem
))}
{p.result?.__typename.includes('Failure') && (
<>
{p.result?.reason && (
<ListItem
leading={<AlertIcon size={ICON_SIZE.medium} color={styles.error.color} />}
headline={({ Text }) => <Text style={styles.error}>Expected to fail</Text>}
supporting={p.result.reason}
/>
)}

{errorSelector ? (
<Link
asChild
href={`https://openchain.xyz/signatures?query=${errorSelector}`}
target="_blank"
>
<ListItem
leading={<AlertIcon size={ICON_SIZE.medium} color={styles.error.color} />}
headline={({ Text }) => <Text style={styles.error}>Expected to fail</Text>}
supporting={`Error: ${errorSelector}`}
trailing={SearchIcon}
/>
</Link>
) : (
<ListItem
leading={<AlertIcon size={ICON_SIZE.medium} color={styles.error.color} />}
headline={({ Text }) => <Text style={styles.error}>Expected to fail</Text>}
supporting="No error message was provided"
/>
)}

<ListItem
leading={<AlertIcon size={ICON_SIZE.medium} color={styles.error.color} />}
headline={({ Text }) => <Text style={styles.error}>Expected to fail</Text>}
supporting={errorSelector ? `Error: ${errorSelector}` : 'No error message was provided'}
trailing={errorSelector ? SearchIcon : undefined}
/>
</>
)}
</>
);
}
Expand Down
7 changes: 4 additions & 3 deletions app/src/components/transaction/TransactionActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const Transaction = graphql`
validationErrors {
reason
}
simulation {
result {
__typename
id
success
}
systx {
id
Expand Down Expand Up @@ -77,7 +77,8 @@ export const TransactionActions = (props: TransactionActionsProps) => {
});

const blockExplorer = CHAINS[p.account.chain].blockExplorers?.default;
const showForceExecute = p.status === 'Pending' && p.executable && !p.simulation?.success;
const showForceExecute =
p.status === 'Pending' && p.executable && p.result?.__typename === 'SimulatedFailure';

return (
<Actions>
Expand Down
12 changes: 1 addition & 11 deletions app/src/components/transaction/TransactionValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ const Transaction = graphql`
isFeeTransfer
}
}
simulation {
id
transfers {
id
value
isFeeTransfer
}
}
}
`;

Expand All @@ -34,9 +26,7 @@ export interface TransactionValueProps {
export function TransactionValue(props: TransactionValueProps) {
const p = useFragment(Transaction, props.transaction);

const transfers = [...(p.result?.transfers ?? p.simulation?.transfers ?? [])].filter(
(t) => !t.isFeeTransfer,
);
const transfers = (p.result?.transfers ?? []).filter((t) => !t.isFeeTransfer);

const value = Decimal.sum(0, ...transfers.map((t) => t.value ?? 0));

Expand Down
20 changes: 1 addition & 19 deletions app/src/components/transaction/TransfersSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,6 @@ const Transaction = graphql`
isFeeTransfer
}
}
simulation {
id
transfers {
__typename
id
tokenAddress
token {
id
balance(input: { transaction: $transaction })
...TokenItem_token
...TokenAmount_token
}
amount
from
to
isFeeTransfer
}
}
...TransactionValue_transaction
}
`;
Expand All @@ -64,7 +46,7 @@ export function TransfersSection(props: TransfersSectionProps) {
const { styles } = useStyles(stylesheet);
const p = useFragment(Transaction, props.transaction);

const transfers = (p.result ?? p.simulation)?.transfers.filter((t) => !t.isFeeTransfer); // Ignore fee transfers, this is shown by FeeToken
const transfers = p.result?.transfers.filter((t) => !t.isFeeTransfer); // Ignore fee transfers, this is shown by FeeToken

if (!transfers?.length) return null;

Expand Down

0 comments on commit f154d7b

Please sign in to comment.