|
1 | 1 | <script lang="typescript"> |
2 | 2 | import { localize } from '@core/i18n' |
3 | 3 | import { resetLedgerPreparedOutput, resetShowInternalVerificationPopup } from '@core/ledger' |
4 | | - import { resetNewTransactionDetails } from '@core/wallet' |
| 4 | + import { resetNewTransactionDetails, selectedSendOptionIndex } from '@core/wallet' |
5 | 5 | import { openPopup } from '@lib/popup' |
6 | | - import { OnboardingButton } from 'shared/components/atoms' |
| 6 | + import { appSettings } from '@core/app' |
| 7 | + import { Text, FontWeight, TextType, Icon, Modal } from 'shared/components' |
| 8 | + import { Icon as IconEnum } from '@auxiliary/icon' |
| 9 | + import features from '@features/features' |
| 10 | +
|
| 11 | + let modal: Modal = undefined |
| 12 | + let isModalOpened: boolean = false |
| 13 | +
|
| 14 | + $: darkModeEnabled = $appSettings.darkMode |
| 15 | + $: selectedOption = buttonOptions[$selectedSendOptionIndex] |
| 16 | + $: hasMultipleOptions = buttonOptions.length > 1 |
| 17 | +
|
| 18 | + const buttonOptions = [ |
| 19 | + { |
| 20 | + title: localize('general.sendFunds'), |
| 21 | + description: localize('general.sendTokensToAddress'), |
| 22 | + action: onL1SendClick, |
| 23 | + }, |
| 24 | + ...(features.wallet.sendAndReceive.nft.enabled |
| 25 | + ? [ |
| 26 | + { |
| 27 | + title: localize('general.sendNft'), |
| 28 | + description: localize('general.sendNftToAddress'), |
| 29 | + action: onNftSendClick, |
| 30 | + }, |
| 31 | + ] |
| 32 | + : []), |
| 33 | + ] |
| 34 | +
|
| 35 | + function openModal(): void { |
| 36 | + isModalOpened = true |
| 37 | + modal?.open() |
| 38 | + } |
| 39 | +
|
| 40 | + function onSelection(index: number): void { |
| 41 | + $selectedSendOptionIndex = index |
| 42 | + isModalOpened = false |
| 43 | + modal?.close() |
| 44 | + } |
7 | 45 |
|
8 | 46 | function onSendClick(): void { |
| 47 | + selectedOption.action() |
| 48 | + } |
| 49 | +
|
| 50 | + function onL1SendClick(): void { |
| 51 | + resetNewTransactionDetails() |
| 52 | + resetLedgerPreparedOutput() |
| 53 | + resetShowInternalVerificationPopup() |
| 54 | + openPopup({ |
| 55 | + type: 'sendForm', |
| 56 | + overflow: true, |
| 57 | + }) |
| 58 | + } |
| 59 | +
|
| 60 | + function onNftSendClick(): void { |
9 | 61 | resetNewTransactionDetails() |
10 | 62 | resetLedgerPreparedOutput() |
11 | 63 | resetShowInternalVerificationPopup() |
|
16 | 68 | } |
17 | 69 | </script> |
18 | 70 |
|
19 | | -<OnboardingButton |
20 | | - primaryText={localize('general.sendFunds')} |
21 | | - secondaryText={localize('general.sendTokensToAddress')} |
22 | | - onClick={onSendClick} |
23 | | -/> |
| 71 | +<div class="relative"> |
| 72 | + <div class="button-container flex flex-row justify-between rounded-xl" class:darkmode={darkModeEnabled}> |
| 73 | + <button |
| 74 | + class="px-4 py-3.5 text-center flex flex-row justify-between w-full" |
| 75 | + on:click|stopPropagation={onSendClick} |
| 76 | + > |
| 77 | + <span class="flex flex-col justify-center items-start"> |
| 78 | + <Text |
| 79 | + type={TextType.p} |
| 80 | + color="gray-800" |
| 81 | + darkColor="white" |
| 82 | + fontSize="14" |
| 83 | + fontWeight={FontWeight.semibold} |
| 84 | + lineHeight="5" |
| 85 | + >{selectedOption.title} |
| 86 | + </Text> |
| 87 | + <Text |
| 88 | + type={TextType.p} |
| 89 | + color="gray-600" |
| 90 | + darkColor="gray-400" |
| 91 | + fontSize="12" |
| 92 | + fontWeight={FontWeight.normal} |
| 93 | + lineHeight="3.5" |
| 94 | + >{selectedOption.description} |
| 95 | + </Text> |
| 96 | + </span> |
| 97 | + {#if !hasMultipleOptions} |
| 98 | + <Icon icon={IconEnum.ChevronRight} classes="text-gray-500 h-full" /> |
| 99 | + {/if} |
| 100 | + </button> |
| 101 | + {#if hasMultipleOptions} |
| 102 | + <button class="p-4" on:click={openModal}> |
| 103 | + <Icon |
| 104 | + icon={isModalOpened ? IconEnum.ChevronUp : IconEnum.ChevronDown} |
| 105 | + classes={isModalOpened ? 'text-blue-500' : 'text-gray-500'} |
| 106 | + /> |
| 107 | + </button> |
| 108 | + {/if} |
| 109 | + </div> |
| 110 | + |
| 111 | + <Modal |
| 112 | + bind:this={modal} |
| 113 | + position={{ left: '0', top: 'calc(100% + 8px)' }} |
| 114 | + classes="w-full" |
| 115 | + on:close={() => (isModalOpened = false)} |
| 116 | + > |
| 117 | + <action-picker-modal class="max-h-64 flex flex-col space-y-1 scrollable-y"> |
| 118 | + {#each buttonOptions as option, index} |
| 119 | + <button |
| 120 | + on:click={() => onSelection(index)} |
| 121 | + class="w-full flex flex-row flex-1 justify-between items-center px-2 py-3 space-x-2 rounded-lg hover:bg-blue-50 dark:hover:bg-gray-800 dark:hover:bg-opacity-20" |
| 122 | + > |
| 123 | + <div class="flex w-4 justify-center items-center"> |
| 124 | + {#if $selectedSendOptionIndex === index} |
| 125 | + <Icon icon={IconEnum.Checkmark} classes="text-blue-500" width="16" height="16" /> |
| 126 | + {/if} |
| 127 | + </div> |
| 128 | + <Text type={TextType.p} fontWeight={FontWeight.medium} color="gray-800" classes="w-full text-left" |
| 129 | + >{option.title}</Text |
| 130 | + > |
| 131 | + </button> |
| 132 | + {/each} |
| 133 | + </action-picker-modal> |
| 134 | + </Modal> |
| 135 | +</div> |
| 136 | + |
| 137 | +<style type="text/scss"> |
| 138 | + .button-container { |
| 139 | + min-width: 200px; |
| 140 | + @apply border; |
| 141 | + @apply border-solid; |
| 142 | + @apply border-gray-300; |
| 143 | + @apply bg-white; |
| 144 | + @apply text-left; |
| 145 | + span { |
| 146 | + min-height: 36px; |
| 147 | + } |
| 148 | + &.darkmode { |
| 149 | + @apply border-gray-700; |
| 150 | + @apply bg-transparent; |
| 151 | +
|
| 152 | + button { |
| 153 | + &:hover, |
| 154 | + &:focus, |
| 155 | + &:active { |
| 156 | + @apply bg-gray-700; |
| 157 | + @apply bg-opacity-20; |
| 158 | + @apply border-opacity-50; |
| 159 | + } |
| 160 | + &:disabled { |
| 161 | + @apply bg-gray-700; |
| 162 | + @apply bg-opacity-10; |
| 163 | + @apply border-gray-700; |
| 164 | + @apply border-opacity-10; |
| 165 | + } |
| 166 | +
|
| 167 | + &:last-child { |
| 168 | + @apply border-gray-700; |
| 169 | + } |
| 170 | + } |
| 171 | + } |
| 172 | +
|
| 173 | + button { |
| 174 | + &:hover { |
| 175 | + @apply bg-blue-50; |
| 176 | + @apply border-gray-500; |
| 177 | + } |
| 178 | +
|
| 179 | + &:active, |
| 180 | + &:focus { |
| 181 | + @apply bg-blue-100; |
| 182 | + @apply border-blue-400; |
| 183 | + } |
| 184 | + &:disabled { |
| 185 | + :global(svg) { |
| 186 | + @apply text-gray-500; |
| 187 | + } |
| 188 | + @apply pointer-events-none; |
| 189 | + @apply bg-gray-50; |
| 190 | + } |
| 191 | +
|
| 192 | + &:first-child { |
| 193 | + border-top-left-radius: 0.75rem; |
| 194 | + border-bottom-left-radius: 0.75rem; |
| 195 | + } |
| 196 | +
|
| 197 | + &:last-child { |
| 198 | + border-left: 1px solid; |
| 199 | + @apply border-gray-300; |
| 200 | + border-top-right-radius: 0.75rem; |
| 201 | + border-bottom-right-radius: 0.75rem; |
| 202 | + } |
| 203 | + } |
| 204 | + } |
| 205 | +</style> |
0 commit comments