Skip to content

Commit

Permalink
Updating 0.1.50 in gh
Browse files Browse the repository at this point in the history
  • Loading branch information
hide-on-bush-x committed Aug 15, 2022
1 parent 9c66ba8 commit 1897bf8
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@masa-finance/tools",
"version": "0.1.43",
"version": "0.1.50",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
49 changes: 44 additions & 5 deletions src/common/helpers/rest-calls/index.ts
Expand Up @@ -3,7 +3,7 @@ import { useAxios, useLazyAxios } from 'use-axios-client';
import { MethodMetadata } from '../../rest';
import { URL } from '../axios';
import { useToken } from '../get-token';
import { useQuery } from 'react-query';
import { useMutation, useQuery } from 'react-query';
import { MASA_TOOLS_CONTEXT } from '../provider';

export interface RestCallProps {
Expand All @@ -21,7 +21,7 @@ export const useRestCall = ({
const fullPath = useMemo(() => {
let newPath = metadata.name;
if (pathParameters) {
Object.keys(pathParameters).forEach(key => {
Object.keys(pathParameters).forEach((key) => {
//@ts-ignore
newPath = newPath.replace(':' + key, [pathParameters[key]]);
});
Expand Down Expand Up @@ -61,7 +61,7 @@ export const useSimpleRestCall = ({
const fullPath = useMemo(() => {
let newPath = metadata.name;
if (pathParameters) {
Object.keys(pathParameters).forEach(key => {
Object.keys(pathParameters).forEach((key) => {
//@ts-ignore
newPath = newPath.replace(':' + key, [pathParameters[key]]);
});
Expand Down Expand Up @@ -94,7 +94,7 @@ export const useMasaQuery = (
const fullPath = useMemo(() => {
let newPath = metadata.name;
if (pathParameters) {
Object.keys(pathParameters).forEach(key => {
Object.keys(pathParameters).forEach((key) => {
//@ts-ignore
newPath = newPath.replace(':' + key, [pathParameters[key]]);
});
Expand All @@ -115,7 +115,46 @@ export const useMasaQuery = (
method: metadata.method,
mode: 'cors',
body: JSON.stringify(body),
}).then(res => res.json()),
}).then((res) => res.json()),
{ ...settings, enabled: !token ? false : !!settings?.enabled }
);

return query;
};

export const useMasaMutation = (
name: string,
{ pathParameters, metadata, headers, body }: RestCallProps,
settings?: any
) => {
const { apiURL } = useContext(MASA_TOOLS_CONTEXT);

const fullPath = useMemo(() => {
let newPath = metadata.name;
if (pathParameters) {
Object.keys(pathParameters).forEach((key) => {
//@ts-ignore
newPath = newPath.replace(':' + key, [pathParameters[key]]);
});
}
return newPath;
}, [pathParameters, metadata]);

const { token } = useToken();

const query = useMutation(
name,
(newBody: any) =>
fetch(`${URL(apiURL)}${fullPath}`, {
headers: {
...headers,
Authorization: token ? `Bearer ${token}` : undefined,
'Content-Type': 'application/json',
},
method: metadata.method,
mode: 'cors',
body: JSON.stringify(newBody ? newBody : body),
}).then((res) => res.json()),
{ ...settings, enabled: !token ? false : !!settings?.enabled }
);

Expand Down
16 changes: 15 additions & 1 deletion src/common/rest/contracts-mint/index.ts
@@ -1,5 +1,5 @@
import { MethodMetadata, Parameter } from '..';
import { useRestCall } from '../../helpers/rest-calls';
import { useMasaMutation, useRestCall } from '../../helpers/rest-calls';

const path = 'contracts/mint';

Expand All @@ -13,6 +13,20 @@ export function useMethod({ body }: any) {
return { data, error, loading, getData };
}

export function useSimpleMethod({ pathParameters, body, settings }: any) {
const masaQuery = useMasaMutation(
'mint-soulname',
{
pathParameters,
headers: Headers,
body,
metadata,
},
settings
);
return masaQuery;
}

const parameters: Parameter[] = [
{
key: 1,
Expand Down
28 changes: 28 additions & 0 deletions src/common/rest/get-identity/index.ts
@@ -0,0 +1,28 @@
import { MethodMetadata, Parameter } from '..';
import { useMasaQuery } from '../../helpers/rest-calls';

const path = '/sbt/:profileId';

export function useSimpleMethod({ pathParameters, body, settings }: any) {
const masaQuery = useMasaQuery(
'get-identity',
{
pathParameters,
headers: Headers,
body,
metadata,
},
settings
);
return masaQuery;
}
const parameters: Parameter[] = [];

export const metadata: MethodMetadata = {
author: 'Hide on bush',
authorPicture: '',
description: 'Gets user identity',
name: path,
method: 'GET',
parameters: parameters,
};
3 changes: 3 additions & 0 deletions src/common/rest/index.ts
Expand Up @@ -31,6 +31,8 @@ import * as getProductInterests from './get-product-interests';

import * as balances from './balances';

import * as getIdentity from './get-identity';

export interface Parameter {
key: number;
name: string;
Expand Down Expand Up @@ -76,4 +78,5 @@ export const masaRestClient = {
balances,
getNodeOperators,
postNodeOperators,
getIdentity,
};

0 comments on commit 1897bf8

Please sign in to comment.