UNPKG

@oxyhq/services

Version:

Reusable OxyHQ module to handle authentication, user management, karma system, device-based session management and more 🚀

341 lines (340 loc) • 11.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = require("react"); var _reactNative = require("react-native"); var _OxyContext = require("../../context/OxyContext"); var _fonts = require("../../styles/fonts"); var _Avatar = _interopRequireDefault(require("../../components/Avatar")); var _vectorIcons = require("@expo/vector-icons"); var _useI18n = require("../../hooks/useI18n"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const KarmaCenterScreen = ({ theme, navigate, goBack }) => { const { user, oxyServices, isAuthenticated } = (0, _OxyContext.useOxy)(); const { t } = (0, _useI18n.useI18n)(); const [karmaTotal, setKarmaTotal] = (0, _react.useState)(null); const [karmaHistory, setKarmaHistory] = (0, _react.useState)([]); const [isLoading, setIsLoading] = (0, _react.useState)(true); const [error, setError] = (0, _react.useState)(null); const isDarkTheme = theme === 'dark'; const textColor = isDarkTheme ? '#FFFFFF' : '#000000'; const backgroundColor = isDarkTheme ? '#121212' : '#FFFFFF'; const secondaryBackgroundColor = isDarkTheme ? '#222222' : '#F5F5F5'; const borderColor = isDarkTheme ? '#444444' : '#E0E0E0'; const primaryColor = '#d169e5'; (0, _react.useEffect)(() => { if (!user) return; setIsLoading(true); setError(null); Promise.all([oxyServices.getUserKarmaTotal(user.id), oxyServices.getUserKarmaHistory(user.id, 20, 0)]).then(([totalRes, historyRes]) => { setKarmaTotal(totalRes.total); setKarmaHistory(Array.isArray(historyRes.history) ? historyRes.history : []); }).catch(err => { setError(err.message || 'Failed to load karma data'); }).finally(() => setIsLoading(false)); }, [user]); if (!isAuthenticated) { return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [styles.container, { backgroundColor }], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.message, { color: textColor }], children: t('common.status.notSignedIn') || 'Not signed in' }) }); } if (isLoading) { return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [styles.container, { backgroundColor, justifyContent: 'center' }], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, { size: "large", color: primaryColor }) }); } return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [styles.container, { backgroundColor }], children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.ScrollView, { style: styles.scrollView, contentContainerStyle: styles.scrollContainer, children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: styles.walletHeader, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, { uri: user?.avatar ? oxyServices.getFileDownloadUrl(user.avatar, 'thumb') : undefined, name: user?.username, size: 60, theme: theme, style: styles.avatar }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.karmaLabel, { color: isDarkTheme ? '#BBBBBB' : '#888888' }], children: t('karma.center.balance') || 'Karma Balance' }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.karmaAmount, { color: primaryColor }], children: karmaTotal ?? 0 }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: styles.actionRow, children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, { style: styles.actionIconWrapper, onPress: () => navigate && navigate('KarmaLeaderboard'), children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [styles.actionIcon, { backgroundColor: '#E0E0E0' }], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, { name: "trophy-outline", size: 28, color: "#888" }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: styles.actionLabel, children: t('karma.center.actions.leaderboard') || 'Leaderboard' })] }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, { style: styles.actionIconWrapper, onPress: () => navigate && navigate('KarmaRules'), children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [styles.actionIcon, { backgroundColor: '#E0E0E0' }], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, { name: "document-text-outline", size: 28, color: "#888" }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: styles.actionLabel, children: t('karma.center.actions.rules') || 'Rules' })] }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, { style: styles.actionIconWrapper, onPress: () => navigate && navigate('AboutKarma'), children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [styles.actionIcon, { backgroundColor: '#E0E0E0' }], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, { name: "star-outline", size: 28, color: "#888" }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: styles.actionLabel, children: t('karma.center.actions.about') || 'About' })] }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, { style: styles.actionIconWrapper, onPress: () => navigate && navigate('KarmaRewards'), children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [styles.actionIcon, { backgroundColor: '#E0E0E0' }], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, { name: "gift-outline", size: 28, color: "#888" }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: styles.actionLabel, children: t('karma.center.actions.rewards') || 'Rewards' })] }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, { style: styles.actionIconWrapper, onPress: () => navigate && navigate('KarmaFAQ'), children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [styles.actionIcon, { backgroundColor: '#E0E0E0' }], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, { name: "help-circle-outline", size: 28, color: "#888" }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: styles.actionLabel, children: t('karma.center.actions.faq') || 'FAQ' })] })] }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: styles.infoText, children: t('karma.center.info') || 'Karma can only be earned by positive actions in the Oxy Ecosystem. It cannot be sent or received directly.' })] }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.sectionTitle, { color: textColor }], children: t('karma.center.history') || 'Karma History' }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: styles.historyContainer, children: karmaHistory.length === 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: { color: textColor, textAlign: 'center', marginTop: 16 }, children: t('karma.center.noHistory') || 'No karma history yet.' }) : karmaHistory.map(entry => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: [styles.historyItem, { borderColor }], children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Text, { style: [styles.historyPoints, { color: entry.points > 0 ? primaryColor : '#D32F2F' }], children: [entry.points > 0 ? '+' : '', entry.points] }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.historyDesc, { color: textColor }], children: entry.reason || t('karma.center.noDescription') || 'No description' }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.historyDate, { color: isDarkTheme ? '#BBBBBB' : '#888888' }], children: entry.createdAt ? new Date(entry.createdAt).toLocaleString() : '' })] }, entry.id)) }), error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: { color: '#D32F2F', marginTop: 16, textAlign: 'center' }, children: error })] }) }); }; const styles = _reactNative.StyleSheet.create({ container: { flex: 1 }, scrollView: { flex: 1 }, scrollContainer: { padding: 0, alignItems: 'center' }, walletHeader: { alignItems: 'center', paddingTop: 36, paddingBottom: 24, width: '100%', backgroundColor: 'transparent' }, avatar: { marginBottom: 12 }, karmaLabel: { fontSize: 16, marginBottom: 4, fontFamily: _fonts.fontFamilies.phudu }, karmaAmount: { fontSize: 48, fontWeight: 'bold', marginBottom: 18, fontFamily: _fonts.fontFamilies.phuduBold }, actionRow: { flexDirection: 'row', justifyContent: 'center', marginBottom: 18, flexWrap: 'wrap', rowGap: 0, columnGap: 0 }, actionIconWrapper: { alignItems: 'center', marginHorizontal: 8, marginVertical: 4, width: 72 }, actionIcon: { width: 56, height: 56, borderRadius: 28, alignItems: 'center', justifyContent: 'center', marginBottom: 6, opacity: 0.5 }, actionIconText: { fontSize: 28 }, actionLabel: { fontSize: 13, color: '#888' }, infoText: { fontSize: 13, color: '#888', textAlign: 'center', marginTop: 8, marginBottom: 8, maxWidth: 320 }, sectionTitle: { fontSize: 18, fontWeight: '600', marginBottom: 12, marginTop: 8, alignSelf: 'flex-start', marginLeft: 24 }, historyContainer: { borderRadius: 15, overflow: 'hidden', marginBottom: 20, width: '100%', paddingHorizontal: 12 }, historyItem: { padding: 14, borderBottomWidth: 1 }, historyPoints: { fontSize: 16, fontWeight: '700' }, historyDesc: { fontSize: 15, marginTop: 2 }, historyDate: { fontSize: 13, marginTop: 2 }, message: { fontSize: 16, textAlign: 'center', marginTop: 24 } }); var _default = exports.default = KarmaCenterScreen; //# sourceMappingURL=KarmaCenterScreen.js.map