Skip to content

Commit

Permalink
feat: show deposit status
Browse files Browse the repository at this point in the history
  • Loading branch information
JackHamer09 committed Jan 3, 2024
1 parent 4467973 commit 746cb8e
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
WALLET_CONNECT_PROJECT_ID=373a8744ceaac00934aec708a3fceea6
ANKR_TOKEN=
ANKR_TOKEN=d39966271ddadd0313304908744721c7c9c0c83e2785d73602990c8b46267f83
2 changes: 1 addition & 1 deletion components/common/button/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defineProps({
}
}
&light {
@apply bg-neutral-200 dark:bg-neutral-800;
@apply bg-neutral-200 transition disabled:opacity-70 dark:bg-neutral-800;
&:enabled,
&:is(a, label) {
&:not([aria-disabled="true"]) {
Expand Down
88 changes: 88 additions & 0 deletions components/transaction/TransactionHashButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<template>
<div class="w-max" ref="el">
<CommonButton
v-if="!explorerUrl"
size="xs"
variant="light"
:disabled="!transactionHash"
class="transaction-hash-button"
@click="copy()"
>
Copy hash
<CommonSpinner v-if="!transactionHash" class="transaction-hash-button-icon" aria-hidden="true" />
<DocumentDuplicateIcon v-else class="transaction-hash-button-icon" aria-hidden="true" />
</CommonButton>
<template v-else>
<CommonButton
v-if="!transactionHash"
size="xs"
variant="light"
target="_blank"
disabled
class="transaction-hash-button"
>
Explorer
<CommonSpinner class="transaction-hash-button-icon" aria-hidden="true" />
</CommonButton>
<CommonButton
v-else
size="xs"
variant="light"
as="a"
:href="`${explorerUrl}/tx/${transactionHash}`"
target="_blank"
class="transaction-hash-button"
>
Explorer
<ArrowTopRightOnSquareIcon class="transaction-hash-button-icon" aria-hidden="true" />
</CommonButton>
</template>
</div>
</template>

<script lang="ts" setup>
import { computed, ref, watch } from "vue";
import { useTippy } from "vue-tippy";
import { ArrowTopRightOnSquareIcon, DocumentDuplicateIcon } from "@heroicons/vue/24/outline";
import useCopy from "@/composables/useCopy";
const props = defineProps({
explorerUrl: {
type: String,
},
transactionHash: {
type: String,
},
});
const { copy, copied } = useCopy(computed(() => props.transactionHash || ""));
const el = ref<HTMLButtonElement | undefined>();
const a = useTippy(el, {
content: "Transaction hash copied!",
trigger: "manual",
hideOnClick: false,
});
watch(
copied,
(copied) => {
if (copied) {
a.show();
} else {
a.hide();
}
},
{ immediate: true }
);
</script>

<style lang="scss" scoped>
.transaction-hash-button {
@apply w-max;
.transaction-hash-button-icon {
@apply -mr-1 ml-2 h-6 w-6;
}
}
</style>
57 changes: 40 additions & 17 deletions components/transaction/TransactionProgress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,21 @@
</template>

<AnimationsTransactionProgress :completed="completed" class="transaction-animation" />

<div v-if="fromExplorerLink || fromTransactionHash" class="info-column bottom-left mt-block-gap-1/2">
<TransactionHashButton :explorer-url="fromExplorerLink" :transaction-hash="fromTransactionHash" />
</div>
<div v-if="toExplorerLink || toTransactionHash" class="info-column bottom-right mt-block-gap-1/2">
<TransactionHashButton :explorer-url="toExplorerLink" :transaction-hash="toTransactionHash" />
</div>
</div>
<CommonButton
size="xs"
variant="light"
as="a"
:href="transactionLink"
target="_blank"
class="mx-auto mt-block-gap w-max"
>
Explorer
<ArrowTopRightOnSquareIcon class="-mr-1 ml-2 h-6 w-6" aria-hidden="true" />
</CommonButton>
<TransactionHashButton
v-if="explorerLink || transactionHash"
:explorer-url="explorerLink"
:transaction-hash="transactionHash"
class="mx-auto mt-block-gap"
/>

<div class="mt-block-padding flex items-center justify-center">
<span class="text-neutral-400">Value:</span>
<span class="ml-1 flex items-center">
Expand All @@ -81,8 +84,6 @@
<script lang="ts" setup>
import { computed } from "vue";
import { ArrowTopRightOnSquareIcon } from "@heroicons/vue/24/outline";
import type { TransactionDestination } from "@/store/destinations";
import type { TokenAmount } from "@/types";
import type { PropType } from "vue";
Expand All @@ -104,9 +105,25 @@ const props = defineProps({
type: Object as PropType<TransactionDestination>,
required: true,
},
transactionLink: {
// left right buttons
fromExplorerLink: {
type: String,
},
fromTransactionHash: {
type: String,
},
toExplorerLink: {
type: String,
},
toTransactionHash: {
type: String,
},
// center button
explorerLink: {
type: String,
},
transactionHash: {
type: String,
required: true,
},
token: {
type: Object as PropType<TokenAmount>,
Expand All @@ -126,8 +143,8 @@ const isSameAddressDifferentDestination = computed(

<style lang="scss" scoped>
.transaction-progress {
@apply grid grid-cols-3 items-center gap-x-4 text-center;
grid-template-areas: "info-col-left divider info-col-right";
@apply grid grid-flow-row grid-cols-3 grid-rows-[max-content] items-center gap-x-4 text-center;
grid-template-areas: "info-col-left divider info-col-right" "info-col-bottom-left space info-col-bottom-right";
.info-column {
@apply flex flex-col items-center justify-center gap-2;
Expand All @@ -137,6 +154,12 @@ const isSameAddressDifferentDestination = computed(
&.right {
grid-area: info-col-right;
}
&.bottom-left {
grid-area: info-col-bottom-left;
}
&.bottom-right {
grid-area: info-col-bottom-right;
}
}
.transaction-animation {
grid-area: divider;
Expand Down
2 changes: 1 addition & 1 deletion components/transaction/lineItem/TransactionLineItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const props = defineProps({
},
});
const el = ref<{ $el?: HTMLButtonElement } | undefined>();
const { copy, copied } = useCopy(computed(() => props.transactionHash));
const el = ref<{ $el?: HTMLButtonElement } | undefined>();
const a = useTippy(
computed(() => el.value?.$el?.parentElement?.parentElement || undefined),
{
Expand Down
11 changes: 7 additions & 4 deletions components/transaction/summary/AddressEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="entry-text-info">
<div class="account-label">{{ accountLabel }}</div>
<div class="account-address">
{{ shortenAddress(address, 8) }}
{{ address }}
</div>
</div>
<AddressAvatar class="account-avatar" :address="address">
Expand All @@ -26,7 +26,6 @@ import type { TransactionDestination } from "@/store/destinations";
import type { PropType } from "vue";
import { useOnboardStore } from "@/store/onboard";
import { shortenAddress } from "@/utils/formatters";
const props = defineProps({
label: {
Expand Down Expand Up @@ -55,7 +54,7 @@ const accountLabel = computed(() => {

<style lang="scss" scoped>
.transaction-summary-address-entry {
@apply flex items-center;
@apply flex items-center gap-4;
.entry-label {
@apply font-bold;
Expand All @@ -65,9 +64,13 @@ const accountLabel = computed(() => {
.entry-text-info {
@apply text-right;
.account-address {
@apply break-all;
}
}
.account-avatar {
@apply h-12 w-12;
@apply h-12 w-12 shrink-0;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion composables/useInterval.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ref } from "vue";

export default <ResultType>(fn: () => ResultType, delay: number) => {
let interval: NodeJS.Timer | undefined = undefined;
let interval: ReturnType<typeof setInterval> | undefined = undefined;
const currentDelay = ref(delay);

function stop() {
Expand Down
39 changes: 26 additions & 13 deletions store/ethereumBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,32 @@ export const useEthereumBalanceStore = defineStore("ethereumBalance", () => {
walletAddress: account.value.address,
onlyWhitelisted: false,
});
return balances.assets
.filter((e) => e.contractAddress || e.tokenType === "NATIVE")
.map((e) => {
return {
address: e.tokenType === "NATIVE" ? ETH_TOKEN.l1Address : checksumAddress(e.contractAddress!),
symbol: e.tokenSymbol,
name: e.tokenName,
decimals: e.tokenDecimals,
iconUrl: e.thumbnail,
price: e.tokenPrice === "0" ? undefined : parseFloat(e.tokenPrice),
amount: e.balanceRawInteger,
} as TokenAmount;
});
return [
...balances.assets
.filter((e) => e.contractAddress || e.tokenType === "NATIVE")
.map((e) => {
return {
address: e.tokenType === "NATIVE" ? ETH_TOKEN.l1Address : checksumAddress(e.contractAddress!),
symbol: e.tokenSymbol,
name: e.tokenName,
decimals: e.tokenDecimals,
iconUrl: e.thumbnail,
price: e.tokenPrice === "0" ? undefined : parseFloat(e.tokenPrice),
amount: e.balanceRawInteger,
} as TokenAmount;
}),
...[
{
address: "0x63bfb2118771bd0da7A6936667A7BB705A06c1bA",
symbol: "Test",
name: "Test",
decimals: 4,
iconUrl: undefined,
price: 0,
amount: "100",
},
],
];
},
{ cache: false }
);
Expand Down
38 changes: 24 additions & 14 deletions views/transactions/Deposit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,28 @@
</CommonErrorBlock>
</template>
<template v-else-if="step === 'submitted'">
<h1 class="h1 mt-block-gap-1/2 text-center">Transaction submitted</h1>
<p class="text-center">
Your funds will be available after the transaction is committed on
<span class="font-medium">{{ destinations.ethereum.label }}</span> and then processed on
<span class="font-medium">{{ destination.label }}</span
>. This usually takes around 15 minutes. You are free to close this page.
</p>
<h1 class="h1 mt-block-gap-1/2 text-center">
{{ l2TransactionHash ? "Transaction completed" : "Transaction submitted" }}
</h1>
<CommonHeightTransition :opened="!l2TransactionHash">
<p class="mb-4 text-center">
Your funds will be available after the transaction is committed on
<span class="font-medium">{{ destinations.ethereum.label }}</span> and then processed on
<span class="font-medium">{{ destination.label }}</span
>. This usually takes around 15 minutes. You are free to close this page.
</p>
</CommonHeightTransition>
<TransactionProgress
:from-address="transaction!.from.address"
:from-destination="transaction!.from.destination"
:from-explorer-link="l1BlockExplorerUrl"
:from-transaction-hash="ethTransactionHash"
:to-address="transaction!.to.address"
:to-destination="transaction!.to.destination"
:transaction-link="`${l1BlockExplorerUrl}/tx/${ethTransactionHash}`"
:to-explorer-link="blockExplorerUrl"
:to-transaction-hash="l2TransactionHash"
:token="transaction!.token"
class="mt-block-gap"
:completed="!!l2TransactionHash"
/>

<EcosystemBlock v-if="eraNetwork.displaySettings?.showPartnerLinks" class="mt-block-gap" />
Expand Down Expand Up @@ -375,7 +382,7 @@ const providerStore = useZkSyncProviderStore();
const zkSyncEthereumBalance = useZkSyncEthereumBalanceStore();
const eraWalletStore = useZkSyncWalletStore();
const { account, isConnected } = storeToRefs(onboardStore);
const { eraNetwork } = storeToRefs(providerStore);
const { eraNetwork, blockExplorerUrl } = storeToRefs(providerStore);
const { destinations } = storeToRefs(useDestinationsStore());
const { l1BlockExplorerUrl } = storeToRefs(useNetworkStore());
const { l1Tokens, tokensRequestInProgress, tokensRequestError } = storeToRefs(tokensStore);
Expand Down Expand Up @@ -635,7 +642,7 @@ watch(step, (newStep) => {
}
});
const transactionCommitted = ref(false);
const l2TransactionHash = ref<string | undefined>();
const makeTransaction = async () => {
if (continueButtonDisabled.value) return;
Expand All @@ -658,15 +665,16 @@ const makeTransaction = async () => {
zkSyncEthereumBalance.deductBalance(feeToken.value!.address!, fee.value!);
zkSyncEthereumBalance.deductBalance(transaction.value!.token.address!, transaction.value!.token.amount);
tx.wait()
.then(async () => {
transactionCommitted.value = true;
.then(async (receipt) => {
console.log("Final receipt", receipt);
l2TransactionHash.value = receipt.transactionHash;
setTimeout(() => {
transfersHistoryStore.reloadRecentTransfers().catch(() => undefined);
eraWalletStore.requestBalance({ force: true }).catch(() => undefined);
}, 2000);
})
.catch((err) => {
transactionCommitted.value = false;
l2TransactionHash.value = undefined;
transactionError.value = err as Error;
transactionStatus.value = "not-started";
});
Expand All @@ -678,7 +686,9 @@ const resetForm = () => {
amount.value = "";
step.value = "form";
transactionStatus.value = "not-started";
l2TransactionHash.value = undefined;
resetSetAllowance();
requestAllowance();
};
const fetchBalances = async (force = false) => {
Expand Down
3 changes: 2 additions & 1 deletion views/transactions/Transfer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
:from-destination="transaction!.from.destination"
:to-address="transaction!.to.address"
:to-destination="transaction!.to.destination"
:transaction-link="`${blockExplorerUrl}/tx/${transactionHash}`"
:explorer-link="blockExplorerUrl"
:transaction-hash="transactionHash"
:token="transaction!.token"
:completed="transactionCommitted && type !== 'withdrawal'"
/>
Expand Down

0 comments on commit 746cb8e

Please sign in to comment.