Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ALEPH-80] feat/refactor: simplify instance creation chain switching #105

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5c67f69
fix: switch blockchain connection on instance tier switch
gmolki Oct 15, 2024
314feaa
feat/refactor: simplify instance creation modals
gmolki Oct 15, 2024
4a00379
feat/refactor: create ResponsiveTooltip component
gmolki Oct 24, 2024
e6be0b0
feat: Checkout Summary allow Tooltip for disabled buttons
gmolki Oct 24, 2024
2ef9342
feat/refactor: Simplify instance instance creation modals v2
gmolki Oct 24, 2024
0f1c971
refactor: tooltip messages
gmolki Oct 24, 2024
413b89b
refactor: confirm connection modal
gmolki Oct 29, 2024
0b12923
refactor: disabled create instance message
gmolki Oct 29, 2024
544853a
refactor: disabled buttons + tooltips
gmolki Oct 29, 2024
39cdeea
refactor: remove deprecated comment from ResponsiveTooltip
gmolki Oct 29, 2024
19c086e
refactor: use control field directly to get selected payment method
gmolki Oct 29, 2024
d18f679
refactor: Remove duplicated ref on SelectPaymentMethod
gmolki Oct 29, 2024
38e4b04
refactor: memo CheckoutButton
gmolki Oct 29, 2024
156ac4d
refactor: Move node calculation to useMemo
gmolki Oct 29, 2024
3d2e69f
fix/refactor: PAYG config when accessing from url and crn set
gmolki Oct 30, 2024
b3a0f24
refactor: tooltips styles
gmolki Oct 30, 2024
add4580
refactor: simplify and unify tooltip content
gmolki Oct 30, 2024
7075e40
refactor: Remove all modals and simplify logic
gmolki Oct 31, 2024
aec93cf
fix: tooltips for create instance
gmolki Oct 31, 2024
efa717c
refactor: create instance button title
gmolki Oct 31, 2024
1f172ae
refactor: disabled messages
gmolki Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/components/common/InfoTooltipButton/cmp.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { memo, useEffect, useRef, useState } from 'react'
import { StyledInfoTooltipButton } from './styles'
import { InfoTooltipButtonProps } from './types'
import { Icon, Tooltip, useResponsiveMax } from '@aleph-front/core'
import { Icon } from '@aleph-front/core'
import tw from 'twin.macro'
import { TwStyle } from 'twin.macro'
import ResponsiveTooltip from '../ResponsiveTooltip'

export const InfoTooltipButton = ({
children,
Expand All @@ -23,12 +24,6 @@ export const InfoTooltipButton = ({

const targetRef = useRef<HTMLButtonElement>(null)

// @todo: Improve this using css
const isMobile = useResponsiveMax('md')
const mobileTw = isMobile
? tw`!fixed !left-0 !top-0 !transform-none m-6 !z-20 !w-[calc(100% - 3rem)] !h-[calc(100% - 3rem)] !max-w-full`
: tw``

const iconCss: (TwStyle | string)[] = []
switch (align) {
case 'left':
Expand Down Expand Up @@ -63,11 +58,10 @@ export const InfoTooltipButton = ({
</StyledInfoTooltipButton>
)}
{renderTooltip && (
<Tooltip
<ResponsiveTooltip
{...rest}
targetRef={targetRef}
content={tooltipContent}
css={mobileTw}
/>
)}
</>
Expand Down
15 changes: 15 additions & 0 deletions src/components/common/ResponsiveTooltip/cmp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { memo } from 'react'
import { Tooltip, TooltipProps, useResponsiveMax } from '@aleph-front/core'
import tw from 'twin.macro'

export const ResponsiveTooltip = (props: TooltipProps) => {
const isMobile = useResponsiveMax('md')
const css = isMobile
? tw`!fixed !left-0 !top-0 !transform-none m-6 !z-20 !w-[calc(100% - 3rem)] !h-[calc(100% - 3rem)] !max-w-full`
: ''

return <Tooltip {...props} css={css} />
}
ResponsiveTooltip.displayName = 'ResponsiveTooltip'

export default memo(ResponsiveTooltip) as typeof ResponsiveTooltip
1 change: 1 addition & 0 deletions src/components/common/ResponsiveTooltip/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './cmp'
20 changes: 20 additions & 0 deletions src/components/common/ResponsiveTooltip/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Tooltip } from '@aleph-front/core'
import styled from 'styled-components'
import tw from 'twin.macro'

export type StyledResponsiveTooltipProps = {
$isMobile: boolean
}

export const StyledResponsiveTooltip = styled(
Tooltip,
).attrs<StyledResponsiveTooltipProps>(({ $isMobile, ...tooltipProps }) => {
const css = $isMobile
? tw`!absolute !top-0 !left-0 !transform-none !z-50 !w-[calc(100% - 3rem)] !h-[calc(100% - 3rem)] !max-w-full !m-48`
: ''

return {
...tooltipProps,
css,
}
})<StyledResponsiveTooltipProps>``
5 changes: 4 additions & 1 deletion src/components/form/CheckoutSummary/cmp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,15 @@ export const CheckoutSummary = ({
domains,
description,
button: buttonNode,
footerButton = buttonNode,
control,
receiverAddress,
paymentMethod,
website,
mainRef,
isPersistent = type === EntityType.Instance,
disablePaymentMethod = true,
disabledStreamTooltip,
onSwitchPaymentMethod,
}: // streamDuration,
CheckoutSummaryProps) => {
Expand Down Expand Up @@ -289,6 +291,7 @@ CheckoutSummaryProps) => {
disabledHold={disabledHold}
disabledStream={disabledStream}
onSwitch={onSwitchPaymentMethod}
disabledStreamTooltip={disabledStreamTooltip}
/>
)

Expand All @@ -298,7 +301,7 @@ CheckoutSummaryProps) => {
<CheckoutSummaryFooter
{...{
paymentMethod,
submitButton: buttonNode,
submitButton: footerButton,
paymentMethodSwitch: paymentMethodSwitchNode,
mainRef,
totalCost: cost?.totalCost,
Expand Down
2 changes: 2 additions & 0 deletions src/components/form/CheckoutSummary/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ export type CheckoutSummaryProps = {
volumes?: VolumeField[]
domains?: DomainField[]
button?: ReactNode
footerButton?: ReactNode
description?: ReactNode
mainRef?: RefObject<HTMLElement>
paymentMethod: PaymentMethod
control?: Control
receiverAddress?: string
streamDuration?: StreamDurationField
disablePaymentMethod?: boolean
disabledStreamTooltip?: ReactNode
onSwitchPaymentMethod?: (e: PaymentMethod) => void
}

Expand Down
68 changes: 44 additions & 24 deletions src/components/form/SelectPaymentMethod/cmp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,62 @@ import { Switch } from '@aleph-front/core'
import { SelectPaymentMethodProps } from './types'
import { useSelectPaymentMethod } from '@/hooks/form/useSelectPaymentMethod'
import { StyledLabel } from './styles'
import { PaymentMethod } from '@/helpers/constants'
import ResponsiveTooltip from '@/components/common/ResponsiveTooltip'

export const SelectPaymentMethod = (props: SelectPaymentMethodProps) => {
const {
disabledHold,
disabledStream,
paymentMethodCtrl,
disabledStreamTooltip,
switchRef,
handleClickHold,
handleClickStream,
} = useSelectPaymentMethod(props)

return (
<div tw="flex items-center justify-center gap-4" className="tp-body3">
<StyledLabel
{...{
onClick: handleClickHold,
$disabled: disabledHold,
}}
<>
<div
tw="flex items-center justify-center gap-4"
className="tp-body3"
ref={switchRef}
gmolki marked this conversation as resolved.
Show resolved Hide resolved
>
Hold tokens
</StyledLabel>
<Switch
{...{
...paymentMethodCtrl.field,
...paymentMethodCtrl.fieldState,
disabled: disabledHold || disabledStream,
}}
/>
<StyledLabel
{...{
onClick: handleClickStream,
$disabled: disabledStream,
}}
>
Pay-as-you-go
</StyledLabel>
</div>
<StyledLabel
{...{
onClick: handleClickHold,
$selected: paymentMethodCtrl.field.value === PaymentMethod.Hold,
$disabled: disabledHold,
}}
>
Hold tokens
</StyledLabel>
<Switch
{...{
...paymentMethodCtrl.field,
...paymentMethodCtrl.fieldState,
disabled: disabledHold || disabledStream,
}}
/>
<StyledLabel
{...{
onClick: handleClickStream,
$selected: paymentMethodCtrl.field.value === PaymentMethod.Stream,
$disabled: disabledStream,
}}
>
Pay-as-you-go
</StyledLabel>
</div>
{disabledStream && (
<ResponsiveTooltip
my="bottom-left"
at="top-left"
targetRef={switchRef as React.RefObject<HTMLButtonElement>}
content={disabledStreamTooltip}
/>
)}
</>
)
}

Expand Down
9 changes: 3 additions & 6 deletions src/components/form/SelectPaymentMethod/styles.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import tw from 'twin.macro'
import styled, { css } from 'styled-components'

export type StyledLabelProps = { $disabled?: boolean }
export type StyledLabelProps = { $selected?: boolean; $disabled?: boolean }

export const StyledLabel = styled.label<StyledLabelProps>`
${({ $disabled = false }) => css`
/* ${tw`cursor-pointer`} */
/* @todo: fix it after supporting stream payment with automatic allocation or hold payment with manual allocation */
${tw`cursor-not-allowed`}

${({ $selected = false, $disabled = false }) => css`
${$disabled ? tw`cursor-not-allowed` : !$selected ? tw`cursor-pointer` : ''}
${$disabled &&
css`
${tw`opacity-40 cursor-not-allowed`}
Expand Down
Loading
Loading