added more settings register function

This commit is contained in:
ue 2018-11-23 17:31:55 +03:00
parent 2d10cb4356
commit 90c15cdd92
5 changed files with 106 additions and 67 deletions

View File

@ -1,53 +1,56 @@
export default [
'BTC',
'USD',
'EUR',
'RUB',
'GBP',
'JPY',
'KRW',
'INR',
'CNY',
'UAH',
'SEK',
'TRY',
'CAD',
'CHF',
'AUD',
'NOK',
'PLN',
'PHP',
'IDR',
'ZAR',
'THB',
'PKR',
'VND',
'NGN'
];
export default ['BTC', 'USD'];
export const VALUE = [
'btc',
'usd',
'eur',
'rub',
'gbp',
'jpy',
'krw',
'inr',
'cny',
'uah',
'sek',
'try',
'cad',
'chf',
'aud',
'nok',
'pln',
'php',
'idr',
'zar',
'thb',
'pkr',
'vnd',
'ngn',
];
export const VALUE = ['btc', 'usd'];
// export default [
// 'BTC',
// 'USD',
// 'EUR',
// 'RUB',
// 'GBP',
// 'JPY',
// 'KRW',
// 'INR',
// 'CNY',
// 'UAH',
// 'SEK',
// 'TRY',
// 'CAD',
// 'CHF',
// 'AUD',
// 'NOK',
// 'PLN',
// 'PHP',
// 'IDR',
// 'ZAR',
// 'THB',
// 'PKR',
// 'VND',
// 'NGN'
// ];
// export const VALUE = [
// 'btc',
// 'usd',
// 'eur',
// 'rub',
// 'gbp',
// 'jpy',
// 'krw',
// 'inr',
// 'cny',
// 'uah',
// 'sek',
// 'try',
// 'cad',
// 'chf',
// 'aud',
// 'nok',
// 'pln',
// 'php',
// 'idr',
// 'zar',
// 'thb',
// 'pkr',
// 'vnd',
// 'ngn',
// ];

View File

@ -1,3 +1,5 @@
export default ['English', 'Turkish', 'German', 'Spanish', 'Italian', 'Duch', 'Russian'];
// export default ['English', 'Turkish', 'German', 'Spanish', 'Italian', 'Duch', 'Russian'];
export default ['English', 'Turkish'];
export const VALUE = ['en-US', 'tr-TR', 'gr', 'sp', 'it', 'dc', 'rs'];
export const VALUE = ['en-US', 'tr-TR'];
// export const VALUE = ['en-US', 'tr-TR', 'gr', 'sp', 'it', 'dc', 'rs'];

View File

@ -256,7 +256,6 @@ export const getPinCode = () => new Promise((resolve, reject) => {
export const setTheme = isDarkTheme => new Promise((resolve, reject) => {
try {
const settings = realm.objects(SETTINGS_SCHEMA);
realm.write(() => {
if (Array.from(settings).length > 0) {
settings[0].language = settings[0].language;
@ -283,7 +282,6 @@ export const setTheme = isDarkTheme => new Promise((resolve, reject) => {
export const getTheme = () => new Promise((resolve, reject) => {
try {
const settings = realm.objects(SETTINGS_SCHEMA);
if (settings[0]) {
resolve(settings[0].isDarkTheme);
} else {
@ -296,7 +294,6 @@ export const getTheme = () => new Promise((resolve, reject) => {
export const setLanguage = selectedLanguage => new Promise((resolve, reject) => {
try {
const settings = realm.objects(SETTINGS_SCHEMA);
realm.write(() => {
settings[0].language = selectedLanguage;
resolve(true);
@ -306,9 +303,41 @@ export const setLanguage = selectedLanguage => new Promise((resolve, reject) =>
}
});
export const setServer = selectedServer => new Promise((resolve, reject) => {
try {
realm.write(() => {
settings[0].server = selectedServer;
resolve(true);
});
} catch (error) {
reject(error);
}
});
export const setNotificationIsOpen = notificationIsOpen => new Promise((resolve, reject) => {
try {
realm.write(() => {
settings[0].notification = notificationIsOpen;
resolve(true);
});
} catch (error) {
reject(error);
}
});
export const setCurrency = selectedCurrency => new Promise((resolve, reject) => {
try {
realm.write(() => {
settings[0].curreny = selectedCurrency;
resolve(true);
});
} catch (error) {
reject(error);
}
});
export const getLanguage = () => new Promise((resolve, reject) => {
try {
const settings = realm.objects(SETTINGS_SCHEMA);
if (settings[0]) {
resolve(settings[0].language);
} else {
@ -321,7 +350,6 @@ export const getLanguage = () => new Promise((resolve, reject) => {
export const getSettings = () => new Promise((resolve, reject) => {
try {
const settings = realm.objects(SETTINGS_SCHEMA);
if (settings[0]) {
resolve(settings[0]);
} else {

View File

@ -2,7 +2,13 @@ import React, { Component } from 'react';
import { connect } from 'react-redux';
// Realm
import { setTheme, setLanguage as setLanguage2DB } from '../../../realm/realm';
import {
setTheme,
setLanguage as setLanguage2DB,
setCurrency as setCurrency2DB,
setServer,
setNotificationIsOpen,
} from '../../../realm/realm';
// Services and Actions
import {
@ -45,16 +51,17 @@ class SettingsContainer extends Component {
switch (actionType) {
case 'currency':
dispatch(setCurrency(CURRENCY_VALUE[action]));
setCurrency2DB(CURRENCY_VALUE[action]);
break;
case 'language':
dispatch(setLanguage(LANGUAGE_VALUE[action]));
// setLanguage2DB(LANGUAGE_VALUE[action]);
setLanguage2DB(LANGUAGE_VALUE[action]);
break;
case 'api':
dispatch(setApi(API_VALUE[action]));
setServer(API_VALUE[action]);
break;
default:
@ -68,11 +75,12 @@ class SettingsContainer extends Component {
switch (actionType) {
case 'notification':
dispatch(isNotificationOpen(action));
setNotificationIsOpen(action);
break;
case 'theme':
dispatch(isDarkTheme(action));
setTheme(true);
setTheme(action);
break;
default:
@ -101,10 +109,6 @@ class SettingsContainer extends Component {
}
};
// _handleThemeChange = () => {
// const { dispatch } = this.props;
// };
render() {
return <SettingsScreen handleOnChange={this._handleOnChange} {...this.props} />;
}

View File

@ -75,6 +75,8 @@ class SplashContainer extends Component {
response.isDarkTheme && dispatch(isDarkTheme(response.isDarkTheme));
response.language && dispatch(setLanguage(response.language));
response.currency && dispatch(setCurrency(response.currency));
response.notification && dispatch(isNotificationOpen(response.currency));
response.server && dispatch(setApi(response.currency));
}
});
};