UNPKG

@rize-labs/banana-wallet-sdk-astar-test

Version:

Smart contract wallet sdk package by Banana Wallet

124 lines 4.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getUsernameFromSessionId = exports.checkIsWalletNameExist = exports.checkInitCodeStatus = exports.setUserCredentials = exports.getUserCredentials = void 0; const axios_1 = require("axios"); const constructUserUniqueIdentifier_1 = require("./utils/constructUserUniqueIdentifier"); const routes_1 = require("./routes"); const Constants_1 = require("./Constants"); axios_1.default.defaults.baseURL = ''; const getUserCredentials = async (walletIdentifier) => { try { console.log("Wallet Identifier: ", walletIdentifier); const identifier = (0, constructUserUniqueIdentifier_1.default)(walletIdentifier, window.location.hostname); const walletCredentials = await (0, axios_1.default)({ url: routes_1.SERVER_URL + routes_1.GET_WALLETCRED_ROUTE, method: 'get', params: { uniqueIdentifier: identifier } }); console.log("Wallet Metadata: ", walletCredentials); if (walletCredentials.data.data !== '') { return JSON.parse(walletCredentials.data.data); } return ''; } catch (err) { console.log(err); throw err; } }; exports.getUserCredentials = getUserCredentials; const setUserCredentials = async (userIdentifier, userCredentialObject) => { try { console.log("Wallet Identifier: ", userIdentifier); console.log("Wallet Metadata: ", userCredentialObject); const identifier = (0, constructUserUniqueIdentifier_1.default)(userIdentifier, window.location.hostname); const updateUserCredentialStatus = await (0, axios_1.default)({ url: routes_1.SERVER_URL + routes_1.ADD_WALLETCRED_ROUTE, method: 'post', data: { uniqueIdentifier: identifier, userCredentials: userCredentialObject } }); if (updateUserCredentialStatus) return { success: true }; return { success: false }; } catch (err) { console.log(err); throw err; } }; exports.setUserCredentials = setUserCredentials; const checkInitCodeStatus = async (walletIdentifier) => { try { const initCodeStatus = await (0, axios_1.default)({ url: routes_1.SERVER_URL + routes_1.CHECK_INITCODE_ROUTE, method: 'get', params: { uniqueIdentifier: walletIdentifier } }); if (initCodeStatus.data.isInitCode) { return { isInitCode: true }; } return { isInitCode: false }; } catch (err) { console.log(err); throw err; } }; exports.checkInitCodeStatus = checkInitCodeStatus; const checkIsWalletNameExist = async (walletName) => { try { const identifier = (0, constructUserUniqueIdentifier_1.default)(walletName, window.location.hostname); const isWalletUnique = await (0, axios_1.default)({ url: routes_1.SERVER_URL + routes_1.IS_WALLETNAME_UNIQUE_ROUTE, method: 'post', data: { walletName: identifier } }); if (isWalletUnique.data.isUnique) { return true; } return false; } catch (err) { console.log(err); throw err; } }; exports.checkIsWalletNameExist = checkIsWalletNameExist; const getUsernameFromSessionId = async (sessionId) => { try { // console.log("Session id ", sessionId); const usernameResponse = await (0, axios_1.default)({ url: Constants_1.BANANA_SERVER + '/connect', method: 'get', params: { sessionId: sessionId } }); // console.log("Username response ", usernameResponse); //@ts-ignore return usernameResponse.data.data; } catch (err) { console.log(err); throw err; } }; exports.getUsernameFromSessionId = getUsernameFromSessionId; //# sourceMappingURL=Controller.js.map