Skip to content

Commit

Permalink
Merge pull request #12 from spknetwork/signup-onboard
Browse files Browse the repository at this point in the history
Signup onboard
  • Loading branch information
igormuba authored Nov 4, 2023
2 parents 34f3d81 + 51939fc commit a6d78fd
Show file tree
Hide file tree
Showing 24 changed files with 1,211 additions and 315 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"i18next": "^19.4.4",
"i18next-browser-languagedetector": "^4.2.0",
"immutability-helper": "^3.0.2",
"js-base64": "^3.7.5",
"js-cookie": "^2.2.1",
"medium-zoom": "^1.0.6",
"moment": "^2.26.0",
Expand Down
38 changes: 38 additions & 0 deletions src/common/api/breakaway.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import axios from "axios"

// const baUrl = "http://localhost:4000"
const baUrl = "https://breakaway-points-system-api.onrender.com"

export const createBreakawayUser = async (username: string, community: string, referral: string, email: string)=> {
try {
const data = {
username,
community,
referral,
email
}
const resp = await axios.post(`${baUrl}/signup-keychain`, data)
return resp;
} catch (err) {
console.log(err)
return err;
}
}

export const createSolanaUser = async (email: string, password: string, solanaWalletAddress: string) => {
try {
const data = {
email,
password,
solanaWalletAddress,
};

const resp = await axios.post(`${baUrl}/offchain-users/register`, data);

return resp.data;
} catch (err) {
console.log(err);

return { err }
}
};
1 change: 1 addition & 0 deletions src/common/api/hive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export const getAccounts = (usernames: string[]): Promise<FullAccount[]> => {
voting_manabar: x.voting_manabar,
voting_power: x.voting_power,
downvote_manabar: x.downvote_manabar,
pending_claimed_accounts: x.pending_claimed_accounts,
__loaded: true,
};

Expand Down
127 changes: 125 additions & 2 deletions src/common/api/operations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import hs from "hivesigner";

import {PrivateKey, Operation, TransactionConfirmation, AccountUpdateOperation, CustomJsonOperation} from '@hiveio/dhive';
import {PrivateKey, Operation, OperationName, TransactionConfirmation, AccountUpdateOperation, CustomJsonOperation} from '@hiveio/dhive';

import {Parameters} from 'hive-uri';

Expand All @@ -20,6 +20,7 @@ import {hotSign} from "../helper/hive-signer";

import {_t} from "../i18n";
import { TransactionType } from "../components/buy-sell-hive";
import { KeyTypes } from "../helper/onboard";

export interface MetaData {
links?: string[];
Expand Down Expand Up @@ -1088,4 +1089,126 @@ export const hiveNotifySetLastRead = (username: string): Promise<TransactionConf
return broadcastPostingOperations(username, opArray);
}

export const updatePassword = (update: AccountUpdateOperation[1], ownerKey: PrivateKey): Promise<TransactionConfirmation> => hiveClient.broadcast.updateAccount(update, ownerKey)
export const updatePassword = (
update: AccountUpdateOperation[1],
ownerKey: PrivateKey
): Promise<TransactionConfirmation> =>
hiveClient.broadcast.updateAccount(update, ownerKey);

export const createHiveAccount = async (data: any, creator_account: string) => {

try {
const { username, keys } = data;

const account = {
name: username,
...keys,
active: false
};
console.log(account)

const op_name: OperationName = "account_create";

const owner = {
weight_threshold: 1,
account_auths: [],
key_auths: [[account.ownerPubKey, 1]]
};
const active = {
weight_threshold: 1,
account_auths: [],
key_auths: [[account.activePubKey, 1]]
};
const posting = {
weight_threshold: 1,
account_auths: [["ecency.app", 1]],
key_auths: [[account.postingPubKey, 1]]
};
const ops: Array<any> = [];
const params: any = {
creator: creator_account,
new_account_name: account.name,
owner,
active,
posting,
memo_key: account.memoPubKey,
json_metadata: "",
extensions: [],
fee: "3.000 HIVE"
};
const operation: Operation = [op_name, params];
ops.push(operation);
try {

const response = await keychain.broadcast(creator_account, [operation], "Active");
console.log(response)
return response;
} catch (err: any) {
console.log(err);
return err;
}
} catch (err) {
console.log(err);
}
};

// Create account with credit
export const createAccountWithCredit = async (data: any, creator_account: string) => {
try {
const { username, keys } = data;

const account = {
name: username,
...keys,
active: false
};

let tokens: any = await hiveClient.database.getAccounts([creator_account]);
console.log(tokens)
tokens = tokens[0]?.pending_claimed_accounts;

let fee = null;
let op_name: OperationName = "create_claimed_account";

const owner = {
weight_threshold: 1,
account_auths: [],
key_auths: [[account.ownerPubKey, 1]]
};
const active = {
weight_threshold: 1,
account_auths: [],
key_auths: [[account.activePubKey, 1]]
};
const posting = {
weight_threshold: 1,
account_auths: [["ecency.app", 1]],
key_auths: [[account.postingPubKey, 1]]
};
const ops: Array<any> = [];
const params: any = {
creator: creator_account,
new_account_name: account.name,
owner,
active,
posting,
memo_key: account.memoPubKey,
json_metadata: "",
extensions: []
};

if (fee) params.fee = fee;
const operation: Operation = [op_name, params];
ops.push(operation);
try {
const newAccount = await keychain.broadcast(creator_account, [operation], "Active");
return newAccount;
} catch (err: any) {
return err;
}
} catch (err) {
console.log(err);
return err;
}
};

7 changes: 7 additions & 0 deletions src/common/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import AuthContainer from "./pages/auth";
import SubmitContainer from "./pages/submit";
import MarketPage from "./pages/market";
import SignUpContainer from "./pages/sign-up";
import OnboardFriend from "./components/onboard-friend";
import NotFound from "./components/404";

import Tracker from "./tracker";
Expand Down Expand Up @@ -133,6 +134,12 @@ const App = ({ setLang }: any) => {
path={routes.SIGN_UP}
component={SignUpContainer}
/>
<Route
exact={true}
strict={true}
path={routes.ONBOARD}
component={OnboardFriend}
/>
<Route
exact={true}
strict={true}
Expand Down
Loading

0 comments on commit a6d78fd

Please sign in to comment.