Skip to content

Commit

Permalink
chore: added EvmTxFollower component
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Sep 2, 2023
1 parent 987c4d5 commit b9fc0ad
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 5 deletions.
128 changes: 128 additions & 0 deletions src/components/evm-tx-follower/index.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<script lang="ts">
import type {ChainConfig} from '~/config'
import type {Checksum256Type} from '@greymass/eosio'
import {Checksum256} from '@greymass/eosio'
import {router} from 'tinro'
import Icon from '~/components/elements/icon.svelte'
import Button from '~/components/elements/button.svelte'
import Card from '~/components/elements/card.svelte'
import type { ethers } from 'ethers'
/** The chain where the transaction was submitted */
export let chain: ChainConfig
/** Title, e.g. Tokens sent */
export let title = 'Transaction sent'
/** The EVM transaction result */
export let evmTransactResult: ethers.providers.TransactionResponse | undefined
/** The text of the primary button at the bottom of the page */
export let primaryButtonText = 'Done'
/** The function to call when the primary button is clicked */
export let handlePrimaryButtonClick: () => void = () => {
router.goto('/')
}
$: console.log({ evmTransactResult })
let txId: Checksum256
$: {
try {
txId = Checksum256.from(evmTransactResult?.hash || '')
} catch (error) {
console.warn('Invalid transaction id passed to TxFollower', error)
txId = Checksum256.from(
'0000000000000000000000000000000000000000000000000000000000000000'
)
}
}
const blockExplorerUrl = 'https://explorer.evm.eosnetwork.com/tx/'
const blockExplorerTransactionUrl = `${blockExplorerUrl}${evmTransactResult?.hash}`
</script>

<style type="scss">
header {
text-align: center;
h1 {
font-size: 24px;
letter-spacing: -0.47px;
padding: 15px 0 24px;
}
:global(.icon) {
color: var(--main-green);
}
a {
text-decoration: none;
text-overflow: ellipsis;
overflow: hidden;
display: block;
color: var(--main-blue);
&:visited {
color: var(--main-blue);
}
}
nav {
margin-top: 30px;
border-bottom: 1px solid var(--divider-grey);
ul {
display: flex;
justify-content: center;
a {
display: block;
border-bottom: 3px solid transparent;
padding: 10px 9px;
text-transform: uppercase;
font-size: 10px;
font-weight: bold;
margin: 0 21px;
&.active {
color: var(--main-black);
border-bottom-color: var(--main-blue);
}
}
}
}
}
footer {
margin-top: 48px;
display: flex;
div {
width: 100%;
&:first-child {
margin-right: 10px;
}
}
@media (max-width: 600px) {
display: block;
div:first-child {
margin: 0 0 10px;
}
}
}
</style>

<Card>
<header>
<Icon size="massive" name="check-circle" />
<h1>{title}</h1>
<a target="_blank" href={blockExplorerTransactionUrl}>{txId}</a>
</header>
<footer>
<div>
<slot name="done">
<Button style="primary" fluid size="large" on:action={handlePrimaryButtonClick}
>{primaryButtonText}</Button
>
</slot>
</div>
<div>
<Button fluid size="large" href={blockExplorerTransactionUrl} target="_blank">
View on block explorer
</Button>
</div>
</footer>
</Card>
16 changes: 11 additions & 5 deletions src/components/tx-follower/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@
import Summary from './summary.svelte'
import Advanced from './advanced.svelte'
/** The transaction id to follow. */
/** The transaction id to follow */
export let id: Checksum256Type
/** The chain where the transaction was submitted. */
/** The chain where the transaction was submitted */
export let chain: ChainConfig
/** Title, e.g. Tokens sent. */
/** Title, e.g. Tokens sent */
export let title = 'Transaction sent'
/** The text of the primary button at the bottom of the page */
export let primaryButtonText = 'Done'
/** The function to call when the primary button is clicked */
export let handlePrimaryButtonClick: () => void = () => {
router.goto('/')
}
let txId: Checksum256
$: {
Expand Down Expand Up @@ -130,8 +136,8 @@
<footer>
<div>
<slot name="done">
<Button style="primary" fluid size="large" on:action={() => router.goto('/')}
>Done</Button
<Button style="primary" fluid size="large" on:action={handlePrimaryButtonClick}
>{primaryButtonText}</Button
>
</slot>
</div>
Expand Down

0 comments on commit b9fc0ad

Please sign in to comment.