|
1 | 1 | <template> |
2 | 2 | <PageTitle>Buy crypto</PageTitle> |
3 | | - <Transition v-bind="TransitionOpacity()" class="relative" as="div"> |
4 | | - <ActiveTransactionsAlert v-if="step === 'buy'" class="absolute" /> |
5 | | - </Transition> |
6 | | - <Transition tag="div" class="relative mt-5 flex flex-wrap items-center justify-center"> |
| 3 | + <CommonHeightTransition :opened="step === 'buy' || step === 'quotes'"> |
| 4 | + <ActiveTransactionsAlert class="mb-5" /> |
| 5 | + </CommonHeightTransition> |
| 6 | + <Transition tag="div" class="relative flex flex-wrap items-center justify-center"> |
7 | 7 | <CompletedView v-if="step === 'complete'" /> |
8 | 8 | <TransactionsView v-else-if="step === 'transactions'" /> |
9 | 9 | <div v-else-if="step === 'buy' || step === 'quotes' || step === 'processing'" class="isolate"> |
@@ -40,66 +40,52 @@ import TransactionsView from "@/views/on-ramp/TransactionsView.vue"; |
40 | 40 | import type { Address } from "viem"; |
41 | 41 | import type { ConfigResponse } from "zksync-easy-onramp"; |
42 | 42 |
|
43 | | -const middlePanelView = ref("initial"); |
| 43 | +const DEFAULT_FIAT_AMOUNT = "100"; |
44 | 44 |
|
45 | | -const { step, middlePanelHeight } = storeToRefs(useOnRampStore()); |
| 45 | +const { step } = storeToRefs(useOnRampStore()); |
46 | 46 | const { reset } = useOnRampStore(); |
47 | 47 | const { account, isConnected } = storeToRefs(useOnboardStore()); |
48 | 48 | const { reset: resetQuotes } = useQuotesStore(); |
49 | 49 | onMounted(() => { |
50 | 50 | reset(); |
51 | 51 | resetQuotes(); |
52 | 52 | }); |
| 53 | +
|
| 54 | +const middlePanelView = ref("initial"); |
| 55 | +watch(isConnected, (connected) => { |
| 56 | + if (!connected) { |
| 57 | + middlePanelView.value = "connect"; |
| 58 | + } |
| 59 | +}); |
| 60 | +
|
53 | 61 | watch(step, () => { |
54 | 62 | if (step.value === "buy") { |
55 | | - fiatAmount.value = ""; |
| 63 | + fiatAmount.value = DEFAULT_FIAT_AMOUNT; |
56 | 64 | resetQuotes(); |
57 | 65 | middlePanelView.value = "initial"; |
58 | | - middlePanelHeight.value = 0; |
| 66 | + fetch(); |
59 | 67 | } |
60 | 68 | }); |
61 | 69 |
|
62 | | -const fiatAmount = ref(""); |
| 70 | +const fiatAmount = ref(DEFAULT_FIAT_AMOUNT); |
63 | 71 | const token = ref<ConfigResponse["tokens"][0] | null>(null); |
64 | 72 |
|
65 | 73 | const selectTokenUpdate = (selectedToken: ConfigResponse["tokens"][0]) => { |
66 | 74 | token.value = selectedToken; |
67 | 75 | }; |
68 | 76 |
|
69 | 77 | watchDebounced( |
70 | | - fiatAmount, |
71 | | - (value) => { |
72 | | - if (!isConnected.value) { |
73 | | - middlePanelView.value = "connect"; |
74 | | - return; |
75 | | - } |
76 | | -
|
77 | | - if (value && token.value) { |
78 | | - fetch(); |
79 | | - } |
| 78 | + [fiatAmount, token, computed(() => account.value.address)], |
| 79 | + () => { |
| 80 | + fetch(); |
80 | 81 | }, |
81 | | - { debounce: 750, maxWait: 5000 } |
| 82 | + { debounce: 750, maxWait: 5000, immediate: true } |
82 | 83 | ); |
83 | | -watchDebounced(token, (value) => { |
84 | | - if (!isConnected.value) { |
85 | | - middlePanelView.value = "connect"; |
86 | | - return; |
87 | | - } |
88 | | -
|
89 | | - if (fiatAmount.value && value) { |
90 | | - fetch(); |
91 | | - } |
92 | | -}); |
93 | | -
|
94 | | -watch(isConnected, () => { |
95 | | - if (isConnected.value && !!fiatAmount.value && +fiatAmount.value > 0 && token.value) { |
96 | | - fetch(); |
97 | | - } |
98 | | -}); |
99 | 84 |
|
100 | 85 | const { fetchQuotes } = useOnRampStore(); |
101 | 86 | const { onRampChainId } = useOnRampStore(); |
102 | 87 | const fetch = () => { |
| 88 | + if (!isConnected.value || !token.value || !fiatAmount.value || +fiatAmount.value <= 0) return; |
103 | 89 | fetchQuotes({ |
104 | 90 | fiatAmount: +fiatAmount.value, |
105 | 91 | toToken: token.value!.address as Address, |
|
0 commit comments