All files / molecules/Account/mobile Account.native.tsx

92.85% Statements 26/28
88.88% Branches 32/36
81.81% Functions 9/11
92.85% Lines 26/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305                                              3x                         25x 25x 25x                             25x   25x 1x     25x       25x           25x 25x             25x                                                                                 25x                 25x   25x                         25x 25x             25x                       75x                                                       25x         18x 54x   54x                           18x                 25x                                                                                     1x                                                                                
import { FC, ReactNode } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import {
  AccountBodyProps,
  AccountFooterProps,
  AccountHeaderProps,
  AccountProps,
  FooterItemProps,
} from '../Account.types';
import { cn } from '@sb/libs';
import { formatCurrency } from '../utils';
import { accountStore } from '@sb/stores';
import {
  Card,
  CicrleCheckFill2,
  CircleCrossFill,
  EuroIcon,
  Gift,
  Globe,
} from '@sb/ui/components/atoms/Icons/index.native';
import { useThemeColors } from '@sb/hooks/Utilities/useThemeColors';
import { Button } from '@sb/ui/components/atoms/Button/index.native';
 
export const Account: FC<AccountProps> = ({
  id,
  wallet,
  onDeposit,
  className,
  onAccountClick,
  onWalletActivate,
  showFooter = true,
  showDepositButton = true,
  showActivateButton = true,
  showDefaultHighlighting = false,
  showActivateButtonFullText = true,
}) => {
  const { themedColors } = useThemeColors();
  const iconColor = themedColors.colorPrimary;
  const { minimumDepositAmount } = accountStore();
  const {
    _id,
    type,
    currency,
    isActive,
    isDefault,
    bonusBalance,
    totalBalance,
    isBettingAllowed,
    isCashoutAllowed,
    isPaymentAllowed,
    realMoneyBalance,
    accountDescription,
    customerCardBalance,
  } = wallet;
 
  const handleOnWalletActivate = (walletId: string) => {
    onWalletActivate?.(walletId);
  };
 
  const handleOnAccountClick = (accountId: string) => {
    onAccountClick?.(accountId);
  };
 
  const AccountHeader: FC<AccountHeaderProps> = ({
    iconColor,
    accountType,
    showActivateButton,
    accountDescription,
  }) => {
    const HeaderIcon = (): ReactNode => {
      return accountType === 'online' ? (
        <Globe size={20} color={iconColor} />
      ) : (
        <Card size={22} color={iconColor} />
      );
    };
 
    return (
      <View
        className={cn('flex min-h-[35px] flex-row items-start gap-2', {
          'items-center': !accountDescription,
        })}
      >
        <HeaderIcon />
        <View
          className={cn('flex flex-col gap-0.5', {
            'flex-1': !showActivateButton,
          })}
        >
          <Text
            ellipsizeMode="tail"
            numberOfLines={1}
            style={{ color: themedColors.colorPrimary }}
            className="leading-0 font-Bold text-[16px] capitalize"
          >{`${accountType}konto`}</Text>
          {accountDescription && (
            <View className="flex flex-row items-center pr-4">
              <Text style={{ color: themedColors.colorPrimary }} className="text-xs font-semibold">
                (
              </Text>
              <Text
                numberOfLines={1}
                ellipsizeMode="tail"
                className="text-xs font-normal"
                style={{ color: themedColors.colorPrimary }}
              >
                {accountDescription}
              </Text>
              <Text style={{ color: themedColors.colorPrimary }} className="text-xs font-semibold">
                )
              </Text>
            </View>
          )}
        </View>
      </View>
    );
  };
 
  const AccountBody: FC<AccountBodyProps> = ({
    total,
    actual,
    bonus,
    customerCard,
    canDeposit,
    onDeposit,
    iconColor,
  }) => {
    const iconSize = 17;
 
    const bodyData: { title: string; value: string | undefined; icon: ReactNode }[] = [
      {
        title: 'Echtgeld',
        value: actual,
        icon: <EuroIcon size={iconSize} color={iconColor} />,
      },
      {
        title: 'Bonus',
        value: bonus,
        icon: <Gift size={iconSize} color={iconColor} />,
      },
    ];
 
    Eif (customerCard) {
      bodyData.push({
        title: 'Kundenkarte',
        value: formatCurrency(parseInt(customerCard)),
        icon: <Card size={iconSize} color={iconColor} />,
      });
    }
 
    return (
      <View className="mt-2 gap-2">
        <Text
          className="font-Bold text-right text-2xl"
          style={{ color: themedColors.colorPrimary }}
          accessibilityLabel={`Total balance: ${total}`}
        >
          {total}
        </Text>
 
        <View className="gap-2">
          {bodyData.map((item, index) => (
            <View key={index} className="flex-row items-center justify-between">
              <View className="flex-row items-center gap-1">
                {item.icon}
                <Text style={{ color: themedColors.colorPrimary }} className="font-normal">
                  {item.title}:
                </Text>
              </View>
              <Text style={{ color: themedColors.colorPrimary }} className="text-right font-normal">
                {item.value}
              </Text>
            </View>
          ))}
        </View>
 
        {canDeposit && totalBalance > minimumDepositAmount && (
          <Button
            label="Einzahlen"
            variant="secondary"
            onPress={onDeposit}
            aria-label="Einzahlen"
            textStyle="uppercase text-xl font-Bold tracking-wider"
            className="mt-2 rounded py-2.5 text-lg font-medium uppercase"
          />
        )}
      </View>
    );
  };
 
  const AccountFooter: FC<AccountFooterProps> = ({
    canCashOut,
    canPlaceBet,
    canWithdrawDeposit,
  }) => {
    const FooterItem = ({ label, isActive }: FooterItemProps) => {
      const iconColor = isActive ? themedColors.colorStatus_Won : themedColors.colorStatus_Error;
 
      return (
        <View className="flex flex-row items-center gap-1">
          {isActive ? (
            <CicrleCheckFill2 size={17} color={iconColor} iconcolor="white" />
          ) : (
            <CircleCrossFill size={17} color={iconColor} iconcolor="white" />
          )}
          <Text style={{ color: themedColors.colorPrimary }} className="text-[13px] font-normal">
            {label}
          </Text>
        </View>
      );
    };
 
    return (
      <View className="flex w-full flex-row justify-between px-4">
        <FooterItem label="Cashout" isActive={canCashOut} />
        <FooterItem label="Wetten abgeben" isActive={canPlaceBet} />
        <FooterItem label="Ein- & Auszahlen" isActive={canWithdrawDeposit} />
      </View>
    );
  };
 
  return (
    <TouchableOpacity
      id={id ?? _id}
      className={cn(
        `rounded-xl py-4`,
        {
          'border-2': isDefault && showDefaultHighlighting,
          'pb-0': showFooter,
        },
        className
      )}
      activeOpacity={0.85}
      testID={`account-${id ?? _id}`}
      style={{
        borderColor: themedColors.colorAccent,
        backgroundColor: themedColors.colorText_Main,
      }}
      onPress={() => handleOnAccountClick(id)}
      // Accessibility
      accessible={true}
      accessibilityRole="combobox"
      accessibilityHint={!showActivateButton ? 'Press to select account' : ''}
      accessibilityLabel={`${type}-konto account. Current balance: ${totalBalance}€`}
    >
      {isDefault && showDefaultHighlighting && (
        <View className="absolute -right-3 -top-3">
          <CicrleCheckFill2 size={25} />
        </View>
      )}
 
      <View className="px-3">
        <View className="flex flex-row items-center justify-between">
          <AccountHeader
            accountType={type}
            iconColor={iconColor}
            showActivateButton={showActivateButton}
            accountDescription={accountDescription}
          />
          {!isActive && showActivateButton && (
            <Button
              size="small"
              variant="cyan"
              className="rounded-full px-3.5 py-0.5"
              onPress={() => handleOnWalletActivate?.(id)}
              textStyle="!text-[12px] font-normal uppercase"
              label={showActivateButtonFullText ? 'Aktives Konto' : 'Aktives'}
              // Accessibility
              accessibilityLabel={'Activate account button'}
            />
          )}
        </View>
 
        <View
          className="mt-2 border-b opacity-20"
          style={{ borderColor: themedColors.colorPrimary }}
        />
 
        <AccountBody
          total={formatCurrency(totalBalance)}
          actual={formatCurrency(realMoneyBalance)}
          bonus={formatCurrency(bonusBalance)}
          customerCard={customerCardBalance?.toString()}
          canDeposit={showDepositButton}
          onDeposit={onDeposit}
          iconColor={iconColor}
        />
      </View>
 
      {showFooter && (
        <View
          style={{ backgroundColor: themedColors.colorTag_Background }}
          className="mt-4 flex h-12 flex-row items-center justify-center rounded-b-lg"
        >
          <AccountFooter
            canCashOut={isCashoutAllowed}
            canPlaceBet={isBettingAllowed}
            canWithdrawDeposit={isPaymentAllowed}
          />
        </View>
      )}
    </TouchableOpacity>
  );
};