Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
domechn committed Nov 18, 2023
1 parent 583adf9 commit 1dc103c
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions src/components/configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,29 @@ const App = ({ onConfigurationSave }: { onConfigurationSave?: () => void }) => {
markFormChanged();
}

function validateExchangeConfig(cfg: {
type: string;
apiKey: string;
secret: string;
password?: string;
alias?: string;
}) {
const ana = new CexAnalyzer({
exchanges: [
{
name: cfg.type,
initParams: {
apiKey: cfg.apiKey,
secret: cfg.secret,
password: cfg.password,
},
},
],
});

return ana.verifyConfigs();
}

// submit button clicked in add exchange form
function onAddExchangeFormSubmit() {
if (
Expand All @@ -607,23 +630,9 @@ const App = ({ onConfigurationSave }: { onConfigurationSave?: () => void }) => {
return;
}

const ana = new CexAnalyzer({
exchanges: [
{
name: addExchangeConfig.type,
initParams: {
apiKey: addExchangeConfig.apiKey,
secret: addExchangeConfig.secret,
password: addExchangeConfig.password,
},
},
],
});

setSaveCexConfigLoading(true);

ana
.verifyConfigs()
validateExchangeConfig(addExchangeConfig)
.then((valid) => {
if (!valid) {
toast({
Expand All @@ -647,10 +656,11 @@ const App = ({ onConfigurationSave }: { onConfigurationSave?: () => void }) => {
.finally(() => setSaveCexConfigLoading(false));
}

async function validateWalletAddress(
type: string,
address: string
): Promise<boolean> {
async function validateWalletAddress(cfg: {
type: string;
address: string;
}): Promise<boolean> {
const { type, address } = cfg;
if (!supportCoins.includes(type)) {
throw new Error("Unsupported wallet type");
}
Expand Down Expand Up @@ -836,7 +846,7 @@ const App = ({ onConfigurationSave }: { onConfigurationSave?: () => void }) => {
return;
}
setSaveWalletConfigLoading(true);
validateWalletAddress(addWalletConfig.type, addWalletConfig.address)
validateWalletAddress(addWalletConfig)
.then((valid) => {
if (!valid) {
toast({
Expand Down

0 comments on commit 1dc103c

Please sign in to comment.