Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions src/problem1/problem1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var sum_to_n_a = function (n) {
return n * (n + 2);
};

var sum_to_n_b = function (n) {
let sum = 0;

for (let i = 0; i <= n; i++) {
sum += i;
}

return sum;
};

var sum_to_n_c = function (n) {
if (n <= 1) {
return n;
} else {
return n + sum_to_n_c(n - 1);
}
};
24 changes: 24 additions & 0 deletions src/problem2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
189 changes: 189 additions & 0 deletions src/problem2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# Currency Swap Exchange

A modern, real-time currency exchange application built with React, TypeScript, and Tailwind CSS. Swap between global currencies with up-to-date exchange rates.

![React](https://img.shields.io/badge/React-19.2.0-61DAFB?logo=react)
![TypeScript](https://img.shields.io/badge/TypeScript-5.9.3-3178C6?logo=typescript)
![Vite](https://img.shields.io/badge/Vite-7.2.4-646CFF?logo=vite)
![TailwindCSS](https://img.shields.io/badge/TailwindCSS-4.1.18-38B2AC?logo=tailwind-css)

## Features

- **Real-time Currency Conversion** - Instant conversion between multiple cryptocurrencies
- **Modern UI/UX** - Beautiful glassmorphism design with smooth animations
- **Live Exchange Rates** - Fetches real-time prices from Switcheo API
- **Smart Validation** - Prevents same-token swaps and enforces maximum limits
- **Responsive Design** - Works seamlessly on desktop and mobile devices
- **Maximum Amount Control** - Set maximum exchange limit (100,000)
- **Toast Notifications** - User-friendly feedback for all actions
- **Icon Fallback System** - Graceful handling of missing token icons
- **Duplicate Token Filtering** - Removes duplicate tokens from the list
- **Fast & Lightweight** - Built with Vite for optimal performance

## Getting Started

### Prerequisites

- Node.js (v18 or higher)
- npm or yarn package manager

### Installation

1. **Clone the repository**

```bash
git clone <repository-url>
cd problem2
```

2. **Install dependencies**

```bash
npm install
```

3. **Start the development server**

```bash
npm run dev
```

4. **Open your browser**

```
Navigate to http://localhost:5173
```

5. **Live Demo**

```
Navigate to https://code-challenge-from-99tech.vercel.app/
```

## Available Scripts

| Script | Description |
| ----------------- | ------------------------ |
| `npm run dev` | Start development server |
| `npm run build` | Build for production |
| `npm run preview` | Preview production build |
| `npm run lint` | Run ESLint |

## Tech Stack

### Core

- **React 19.2.0** - UI library
- **TypeScript 5.9.3** - Type-safe JavaScript
- **Vite 7.2.4** - Build tool and dev server

### UI & Styling

- **Tailwind CSS 4.1.18** - Utility-first CSS framework
- **Radix UI** - Accessible UI components
- Select
- Label
- Separator
- **Lucide React** - Icon library
- **Sonner** - Toast notifications

### API & Data

- **Axios 1.13.4** - HTTP client
- **Switcheo API** - Real-time token prices

## Project Structure

```
currency-swap/
├── src/
│ ├── api/
│ │ └── token.ts # API calls and data fetching
│ ├── components/
│ │ ├── CurrencySwap.tsx # Main swap component
│ │ ├── SwapInput.tsx # Reusable input component
│ │ └── ui/ # UI components (Radix)
│ ├── types/
│ │ └── currency.d.ts # TypeScript interfaces
│ ├── lib/
│ │ └── utils.ts # Utility functions
│ ├── App.tsx # Root component
│ ├── main.tsx # App entry point
│ └── index.css # Global styles
├── public/ # Static assets
├── package.json # Dependencies
├── tsconfig.json # TypeScript config
├── vite.config.ts # Vite config
├── tailwind.config.js # Tailwind config
└── README.md # You are here!
```

## Key Features Explained

### 1. Real-time Currency Conversion

The app fetches live token prices from the Switcheo API and calculates conversion rates in real-time as you type.

### 2. Maximum Amount Limit

Users can exchange up to **100,000 units** per transaction. The app provides:

- Quick "Max" button to set maximum amount
- Visual warning when exceeding limit
- Disabled swap button for invalid amounts

### 3. Icon Fallback System

If a token icon fails to load or is unavailable, the app displays a fallback avatar with:

- Token's first letter
- Gradient background
- Consistent styling

### 4. Duplicate Token Removal

The app automatically filters out duplicate tokens (e.g., multiple USDC entries) keeping only the first occurrence.

### 5. Swap Token Feature

Users can quickly reverse the exchange direction with a single click on the swap button.

## UI Components

### CurrencySwap

Main component that manages:

- Token state
- Amount state
- Exchange rate calculations
- Swap functionality
- Validation logic

### SwapInput

Reusable input component with:

- Token selection dropdown
- Amount input field
- Icon display with fallback
- Max button integration

## Usage Example

1. **Select Source Token** - Choose the currency you want to send
2. **Enter Amount** - Type the amount or click "Max" for maximum
3. **Select Target Token** - Choose the currency you want to receive
4. **View Exchange Rate** - See the real-time conversion rate
5. **Click "Swap Now"** - Execute the exchange (simulated)

## Future Enhancements

- [ ] Transaction history
- [ ] Multiple currency pairs
- [ ] Price charts
- [ ] Wallet integration
- [ ] Dark/Light theme toggle
- [ ] More token networks
- [ ] Advanced filtering
- [ ] Favorite tokens
22 changes: 22 additions & 0 deletions src/problem2/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "",
"css": "src/index.css",
"baseColor": "neutral",
"cssVariables": true,
"prefix": ""
},
"iconLibrary": "lucide",
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"registries": {}
}
23 changes: 23 additions & 0 deletions src/problem2/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config'

export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
])
38 changes: 12 additions & 26 deletions src/problem2/index.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fancy Form</title>

<!-- You may add more stuff here -->
<link href="style.css" rel="stylesheet" />
</head>

<body>

<!-- You may reorganise the whole HTML, as long as your form achieves the same effect. -->
<form onsubmit="return !1">
<h5>Swap</h5>
<label for="input-amount">Amount to send</label>
<input id="input-amount" />

<label for="output-amount">Amount to receive</label>
<input id="output-amount" />

<button>CONFIRM SWAP</button>
</form>
<script src="script.js"></script>
</body>

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Currency Swap</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading