Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fiat onboarding #21

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions src/apiServices/assetApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import log from '../lib/log';
import {
showFiatAssets,
showCryptoAssets,
getPurchaseDetailByPurchaseId,
submitPurchase,
getPurchaseHistory,
getPurchaseDetails,
getPurchaseDetailsSelectedAsset,
createPurchase,
getPurchaseStatus,
getProviders
} from '../services/assetService';

async function getFiatAssets(req, res) {
try {
const value = await showFiatAssets();
res.json(value);
} catch (error) {
log.error(error);
res.sendStatus(404);

Check warning on line 21 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L20-L21

Added lines #L20 - L21 were not covered by tests
}
}

async function getCryptoAssets(req, res) {
try {
const value = await showCryptoAssets();
res.json(value);
} catch (error) {
log.error(error);
res.sendStatus(404);

Check warning on line 31 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L30-L31

Added lines #L30 - L31 were not covered by tests
}
}

async function getAssetProviders(req, res) {
try {
const value = await getProviders();
res.json(value);

Check warning on line 38 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L37-L38

Added lines #L37 - L38 were not covered by tests
} catch (error) {
log.error(error);
res.sendStatus(404);

Check warning on line 41 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L40-L41

Added lines #L40 - L41 were not covered by tests
}
}

async function getPurchaseDetailsByPurchaseId(req, res) {
try {
let { purchaseid } = req.params;
purchaseid = purchaseid ?? req.query.purchaseid;
const value = await getPurchaseDetailByPurchaseId(purchaseid);
res.json(value);
} catch (error) {
log.error(error);
res.sendStatus(404);

Check warning on line 53 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L52-L53

Added lines #L52 - L53 were not covered by tests
}
}

async function sendPurchase(req, res) {
try {
let { purchaseid } = req.params;
purchaseid = purchaseid ?? req.query.purchaseid;

let { providerid } = req.params;
providerid = providerid ?? req.query.providerid;

const value = await submitPurchase(purchaseid, providerid);
res.json(value);
} catch (error) {
log.error(error);
res.sendStatus(404);

Check warning on line 69 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L68-L69

Added lines #L68 - L69 were not covered by tests
}
}

async function getAllPurchase(req, res) {
try {
let { zelid } = req.params;
zelid = zelid ?? req.query.zelid;

const value = await getPurchaseHistory(zelid);
res.json(value);
} catch (error) {
log.error(error);
res.sendStatus(404);

Check warning on line 82 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L81-L82

Added lines #L81 - L82 were not covered by tests
}
}

async function getAllPurchaseDetails(req, res) {
try {
let body = '';
await req.on('data', (data) => {
body += data;

Check warning on line 90 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L90

Added line #L90 was not covered by tests
});
const value = await getPurchaseDetails(body);
res.json(value);
} catch (error) {
log.error(error);
res.sendStatus(404);

Check warning on line 96 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L95-L96

Added lines #L95 - L96 were not covered by tests
}
}

async function getPurchaseDetailsOnSelectedAsset(req, res) {
try {
let body = '';
await req.on('data', (data) => {
body += data;

Check warning on line 104 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L104

Added line #L104 was not covered by tests
});
const value = await getPurchaseDetailsSelectedAsset(body);
res.json(value);
} catch (error) {
log.error(error);
res.sendStatus(404);

Check warning on line 110 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L109-L110

Added lines #L109 - L110 were not covered by tests
}
}

async function createPurchaseDetails(req, res) {
try {
let body = '';
await req.on('data', (data) => {
body += data;

Check warning on line 118 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L118

Added line #L118 was not covered by tests
});

let { zelid } = req.params;
zelid = zelid ?? req.query.zelid;

const value = await createPurchase(body, zelid);
res.json(value);
} catch (error) {
log.error(error);
res.sendStatus(404);

Check warning on line 128 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L127-L128

Added lines #L127 - L128 were not covered by tests
}
}

async function getAllPurchaseStatus(req, res) {
try {
let body = '';
await req.on('data', (data) => {
body += data;

Check warning on line 136 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L136

Added line #L136 was not covered by tests
});
const value = await getPurchaseStatus(body);
res.json(value);
} catch (error) {
log.error(error);
res.sendStatus(404);

Check warning on line 142 in src/apiServices/assetApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/assetApi.ts#L141-L142

Added lines #L141 - L142 were not covered by tests
}
}


export default {
getFiatAssets,
getCryptoAssets,
getPurchaseDetailsByPurchaseId,
sendPurchase,
getAllPurchase,
getAllPurchaseDetails,
getPurchaseDetailsOnSelectedAsset,
createPurchaseDetails,
getAllPurchaseStatus,
getAssetProviders
}
40 changes: 40 additions & 0 deletions src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ratesApi from './apiServices/ratesApi';
import ticketsApi from './apiServices/ticketsApi';
import feeService from './services/networkFeesService';
import tokenApi from './apiServices/tokenApi';
import assetApi from './apiServices/assetApi';

export default (app) => {
// return sync data
Expand Down Expand Up @@ -40,4 +41,43 @@ export default (app) => {
app.get('/v1/tokeninfo/:network?/:address?', (req, res) => {
tokenApi.getTokenInfo(req, res);
});
// get fiat assets
app.get('/v1/assetinfo/assets/fiat', (req, res) => {
assetApi.getFiatAssets(req, res);
});
// get crypto assets
app.get('/v1/assetinfo/assets/crypto', (req, res) => {
assetApi.getCryptoAssets(req, res);
});
// get asset providers
app.get('/v1/assetinfo/assets/providers', (req, res) => {
assetApi.getAssetProviders(req, res);
});
// get purchase by id
app.get('/v1/assetinfo/purchase/id/:purchaseid?', (req, res) => {
assetApi.getPurchaseDetailsByPurchaseId(req, res);
});
// send purchase
app.get('/v1/assetinfo/purchase/send/:purchaseid?/:providerid?', (req, res) => {
assetApi.sendPurchase(req, res);
});
// get purchase history
app.get('/v1/assetinfo/purchase/history/:zelid?', (req, res) => {
assetApi.getAllPurchase(req, res);
});
app.post('/v1/assetinfo/purchase/details', (req, res) => {
assetApi.getAllPurchaseDetails(req, res);
});
// send purchase
app.post('/v1/assetinfo/purchase/details/assets', (req, res) => {
assetApi.getPurchaseDetailsOnSelectedAsset(req, res);
});
// get purchase history
app.post('/v1/assetinfo/purchase/create/:zelid?', (req, res) => {
assetApi.createPurchaseDetails(req, res);
});
// get purchase history
app.post('/v1/assetinfo/purchase/status', (req, res) => {
assetApi.getAllPurchaseStatus(req, res);
});
};
123 changes: 123 additions & 0 deletions src/services/assetService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import axios from 'axios';

export async function showFiatAssets () {
try {
const response = await axios.get('https://abe.zelcore.io/v1/purchase/sellassets');
return response.data;
} catch(error) {
console.log(error);
return {message: "Error occured in processing"};

Check warning on line 9 in src/services/assetService.ts

View check run for this annotation

Codecov / codecov/patch

src/services/assetService.ts#L8-L9

Added lines #L8 - L9 were not covered by tests
};
}

export async function showCryptoAssets () {
try {
const response = await axios.get('https://abe.zelcore.io/v1/purchase/buyassets');
return response.data;
} catch(error) {
console.log(error);
return {message: "Error occured in processing"};

Check warning on line 19 in src/services/assetService.ts

View check run for this annotation

Codecov / codecov/patch

src/services/assetService.ts#L18-L19

Added lines #L18 - L19 were not covered by tests
};
}

export async function getPurchaseDetailByPurchaseId (purchaseid: string) {
try {
const response = await axios.get(`https://abe.zelcore.io/v1/purchase/detail?purchaseid=${purchaseid}`);
return response.data;
} catch(error) {
console.log(error);
return {message: "Error occured in processing"};

Check warning on line 29 in src/services/assetService.ts

View check run for this annotation

Codecov / codecov/patch

src/services/assetService.ts#L28-L29

Added lines #L28 - L29 were not covered by tests
};
}

export async function submitPurchase (purchaseid: string, providerid: string) {
try {
const response = await axios.get(`https://abe.zelcore.io/v1/purchase/submit?purchaseid=${purchaseid}&providerid=${providerid}`);
return response.data;
} catch(error) {
console.log(error);
return {message: "Error occured in processing"};

Check warning on line 39 in src/services/assetService.ts

View check run for this annotation

Codecov / codecov/patch

src/services/assetService.ts#L38-L39

Added lines #L38 - L39 were not covered by tests
};
}

export async function getPurchaseHistory (zelid: string) {
try {
const response = await axios.get(`https://abe.zelcore.io/v1/offramp/user/history?zelid=${zelid}`);
return response.data;
} catch(error) {
console.log(error);
return {message: "Error occured in processing"};

Check warning on line 49 in src/services/assetService.ts

View check run for this annotation

Codecov / codecov/patch

src/services/assetService.ts#L48-L49

Added lines #L48 - L49 were not covered by tests
};
}

export async function getPurchaseDetails (data: any) {
try {
const response = await axios.post(`https://abe.zelcore.io/v1/purchase/pairdetails`, data, {
headers: {
'Content-Type' : 'application/json'
}
});
return response.data;
} catch(error) {
console.log(error);
return {message: "Error occured in processing"};

Check warning on line 63 in src/services/assetService.ts

View check run for this annotation

Codecov / codecov/patch

src/services/assetService.ts#L62-L63

Added lines #L62 - L63 were not covered by tests
};
}

export async function getPurchaseDetailsSelectedAsset (data: any) {
try {
const response = await axios.post(`https://abe.zelcore.io/v1/purchase/pairdetailssellamount`, data, {
headers: {
'Content-Type' : 'application/json'
}
});
return response.data;
} catch(error) {
console.log(error);
return {message: "Error occured in processing"};

Check warning on line 77 in src/services/assetService.ts

View check run for this annotation

Codecov / codecov/patch

src/services/assetService.ts#L76-L77

Added lines #L76 - L77 were not covered by tests
};
}

export async function createPurchase (data: any, zelid: string) {
try {
const response = await axios.post(`https://abe.zelcore.io/v1/purchase/createpurchase`, data, {
headers: {
'Content-Type' : 'application/json',
'zedid': zelid
}
});
return response.data;
} catch(error) {
console.log(error);
return {message: "Error occured in processing"};

Check warning on line 92 in src/services/assetService.ts

View check run for this annotation

Codecov / codecov/patch

src/services/assetService.ts#L91-L92

Added lines #L91 - L92 were not covered by tests
};
}

export async function getPurchaseStatus (data: any) {
try {
const response = await axios.post(`https://abe.zelcore.io/v1/purchase/status`, data, {
headers: {
'Content-Type' : 'application/json'
}
});
return response.data;
} catch(error) {
console.log(error);
return {};

Check warning on line 106 in src/services/assetService.ts

View check run for this annotation

Codecov / codecov/patch

src/services/assetService.ts#L105-L106

Added lines #L105 - L106 were not covered by tests
};
}

export async function getProviders () {
try {
const response = await axios.get('https://abe.zelcore.io/v1/purchases');
return response.data;

Check warning on line 113 in src/services/assetService.ts

View check run for this annotation

Codecov / codecov/patch

src/services/assetService.ts#L112-L113

Added lines #L112 - L113 were not covered by tests
} catch(error) {
console.log(error);
return {message: "Error occured in processing"};

Check warning on line 116 in src/services/assetService.ts

View check run for this annotation

Codecov / codecov/patch

src/services/assetService.ts#L115-L116

Added lines #L115 - L116 were not covered by tests
};
}





Loading