Skip to content

Commit

Permalink
frontend/electrum: use api functions instead of apiGet/apiPost
Browse files Browse the repository at this point in the history
  • Loading branch information
benma committed Oct 25, 2022
1 parent 95eddbd commit a6f9cc4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions frontends/web/src/api/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@ export const isMoonpayBuySupported = (code: string) => {
return apiGet(`exchange/moonpay/buy-supported/${code}`);
};
};

export const getDefaultConfig = (): Promise<any> => {
return apiGet('config/default');
};

export const getConfig = (): Promise<any> => {
return apiGet('config');
};

export const setConfig = (config: any): Promise<null> => {
return apiPost('config', config);
};
10 changes: 5 additions & 5 deletions frontends/web/src/routes/settings/electrum-servers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { Component } from 'react';
import { withTranslation } from 'react-i18next';
import { ElectrumServer } from './electrum-server';
import { apiGet, apiPost } from '../../utils/request';
import { getConfig, getDefaultConfig, setConfig } from '../../api/backend';
import { confirmation } from '../../components/confirm/Confirm';
import style from './electrum.module.css';
import A from '../../components/anchor/anchor';
Expand All @@ -29,15 +29,15 @@ class ElectrumServersClass extends Component {
};

componentDidMount() {
apiGet('config').then(config => {
getConfig().then(config => {
this.setState({ electrumServers: config.backend[this.props.coin].electrumServers });
});
}

save = () => {
apiGet('config').then(config => {
getConfig().then(config => {
config.backend[this.props.coin].electrumServers = this.state.electrumServers;
apiPost('config', config);
setConfig(config);
});
};

Expand All @@ -58,7 +58,7 @@ class ElectrumServersClass extends Component {
resetToDefault = () => {
confirmation(this.props.t('settings.electrum.resetConfirm'), response => {
if (response) {
apiGet('config/default').then(config => {
getDefaultConfig().then(config => {
this.setState({ electrumServers: config.backend[this.props.coin].electrumServers });
this.save();
});
Expand Down

0 comments on commit a6f9cc4

Please sign in to comment.