Organize shared code across web, mobile, and SDK UI projects

Centralized common code into shared/ folder to eliminate duplication and
improve maintainability across all three frontend projects (web, mobile,
pezkuwi-sdk-ui).

Changes:
- Added token types and constants to shared/types/tokens.ts
  - TokenInfo, PoolInfo, SwapQuote, and other DEX types
  - KNOWN_TOKENS with HEZ, PEZ, wUSDT definitions
  - Token logos (🟡🟣💵)

- Added Kurdistan color palette to shared/constants/
  - Kesk, Sor, Zer, Spî, Reş color definitions

- Added TOKEN_DISPLAY_SYMBOLS mapping (USDT vs wUSDT)

- Updated blockchain configuration in shared/blockchain/polkadot.ts
  - Added beta testnet endpoint (wss://beta-rpc.pezkuwi.art)
  - Defined DEFAULT_ENDPOINT constant

- Moved i18n to shared/i18n/
  - Centralized translation files for 6 languages (EN, TR, KMR, CKB, AR, FA)
  - Added LANGUAGES configuration with RTL support
  - Created isRTL() helper function

- Updated web and mobile to import from shared
  - web/src/types/dex.ts now re-exports from shared
  - web/src/contexts/PolkadotContext.tsx uses DEFAULT_ENDPOINT
  - mobile/src/i18n/index.ts uses shared translations
  - mobile/src/contexts/PolkadotContext.tsx uses DEFAULT_ENDPOINT

- Updated shared/README.md with comprehensive documentation

This architecture reduces code duplication and ensures consistency across
all frontend projects.
This commit is contained in:
Claude
2025-11-14 19:48:43 +00:00
parent 9c6b10a502
commit 81fe0e8ab7
17 changed files with 684 additions and 147 deletions
+2 -1
View File
@@ -4,6 +4,7 @@ import { Keyring } from '@polkadot/keyring';
import { KeyringPair } from '@polkadot/keyring/types';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { cryptoWaitReady } from '@polkadot/util-crypto';
import { DEFAULT_ENDPOINT } from '../../../shared/blockchain/polkadot';
interface Account {
address: string;
@@ -39,7 +40,7 @@ interface PolkadotProviderProps {
export const PolkadotProvider: React.FC<PolkadotProviderProps> = ({
children,
endpoint = 'wss://beta-rpc.pezkuwi.art', // Beta testnet RPC
endpoint = DEFAULT_ENDPOINT, // Beta testnet RPC from shared config
}) => {
const [api, setApi] = useState<ApiPromise | null>(null);
const [isApiReady, setIsApiReady] = useState(false);
+21 -28
View File
@@ -2,31 +2,25 @@ import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import AsyncStorage from '@react-native-async-storage/async-storage';
// Import all translations
import en from './locales/en.json';
import tr from './locales/tr.json';
import kmr from './locales/kmr.json';
import ckb from './locales/ckb.json';
import ar from './locales/ar.json';
import fa from './locales/fa.json';
// Import shared translations and language configurations
import {
translations,
LANGUAGES,
DEFAULT_LANGUAGE,
LANGUAGE_STORAGE_KEY,
isRTL as checkIsRTL,
} from '../../../shared/i18n';
// Language storage key
export const LANGUAGE_KEY = '@pezkuwi_language';
// Language storage key (re-export for compatibility)
export const LANGUAGE_KEY = LANGUAGE_STORAGE_KEY;
// Available languages
export const languages = [
{ code: 'en', name: 'English', nativeName: 'English', rtl: false },
{ code: 'tr', name: 'Turkish', nativeName: 'Türkçe', rtl: false },
{ code: 'kmr', name: 'Kurdish (Kurmanji)', nativeName: 'Kurmancî', rtl: false },
{ code: 'ckb', name: 'Kurdish (Sorani)', nativeName: 'سۆرانی', rtl: true },
{ code: 'ar', name: 'Arabic', nativeName: 'العربية', rtl: true },
{ code: 'fa', name: 'Persian', nativeName: 'فارسی', rtl: true },
];
// Available languages (re-export for compatibility)
export const languages = LANGUAGES;
// Initialize i18n
const initializeI18n = async () => {
// Try to get saved language
let savedLanguage = 'en'; // Default fallback
let savedLanguage = DEFAULT_LANGUAGE;
try {
const stored = await AsyncStorage.getItem(LANGUAGE_KEY);
if (stored) {
@@ -40,15 +34,15 @@ const initializeI18n = async () => {
.use(initReactI18next)
.init({
resources: {
en: { translation: en },
tr: { translation: tr },
kmr: { translation: kmr },
ckb: { translation: ckb },
ar: { translation: ar },
fa: { translation: fa },
en: { translation: translations.en },
tr: { translation: translations.tr },
kmr: { translation: translations.kmr },
ckb: { translation: translations.ckb },
ar: { translation: translations.ar },
fa: { translation: translations.fa },
},
lng: savedLanguage,
fallbackLng: 'en',
fallbackLng: DEFAULT_LANGUAGE,
compatibilityJSON: 'v3',
interpolation: {
escapeValue: false,
@@ -74,8 +68,7 @@ export const getCurrentLanguage = () => i18n.language;
// Check if language is RTL
export const isRTL = (languageCode?: string) => {
const code = languageCode || i18n.language;
const lang = languages.find(l => l.code === code);
return lang?.rtl || false;
return checkIsRTL(code);
};
export { initializeI18n };