fix some bug

This commit is contained in:
zhl 2023-05-16 19:45:49 +08:00
parent 0f366b87c7
commit 22abde8821
8 changed files with 40 additions and 19 deletions

View File

@ -1,7 +1,7 @@
import { WALLET_API_HOST } from "../config/constants"; import { WALLET_API_HOST } from "../config/constants";
import { POST_JSON } from "../lib/Http"; import { POST_JSON } from "../lib/Http";
export function alchemyPrePay(data: any) { export function reqAlchemyPrePay(data: any) {
const url = `${WALLET_API_HOST}/pay/alchemy/buy`; const url = `${WALLET_API_HOST}/pay/alchemy/buy`;
return POST_JSON(url, data); return POST_JSON(url, data);
} }

View File

@ -1,5 +1,7 @@
export const BASE_TOKEN_URI = "https://market.cebg.games/api/nft/info/"; export const BASE_TOKEN_URI = "https://market.cebg.games/api/nft/info/";
export const AVAILABLE_CHAINS = [80001, 421613, 137, 42161];
export const DEFALUT_TOKENS = { export const DEFALUT_TOKENS = {
321: [ 321: [
{ {

View File

@ -1,7 +1,7 @@
export const WALLET_STORAGE_KEY_NAME = "jc_wallet_data"; export const WALLET_STORAGE_KEY_NAME = "jc_wallet_data";
// export const WALLET_API_HOST = "https://wallet.cebggame.com"; // export const WALLET_API_HOST = "https://wallet.cebggame.com";
export const WALLET_API_HOST = "http://192.168.100.183:3007"; export const WALLET_API_HOST = "http://192.168.100.184:3007";
export const MAX_TRY_COUNT = 6; export const MAX_TRY_COUNT = 6;

View File

@ -13,7 +13,7 @@ import {
} from "./common/WalletEvent"; } from "./common/WalletEvent";
import { JazzIcon } from "./comp/JazzIcon"; import { JazzIcon } from "./comp/JazzIcon";
import { ZWalletConnect } from "./comp/ZWalletConnect"; import { ZWalletConnect } from "./comp/ZWalletConnect";
import { DEFALUT_TOKENS } from "./config/chain_config"; import { AVAILABLE_CHAINS, DEFALUT_TOKENS } from "./config/chain_config";
import { import {
NATIVE_PK_PREFIX, NATIVE_PK_PREFIX,
TX_CONFIRM_BLOCKS, TX_CONFIRM_BLOCKS,
@ -93,18 +93,18 @@ export default class JCWallet {
this.paySvr = new PaySvr(); this.paySvr = new PaySvr();
this.walletType = type; this.walletType = type;
window.jc = { wallet: this }; window.jc = { wallet: this };
this.init();
} }
private updateChain(chain: number) { private updateChain(chain: number) {
chain = chain || 80001; chain = chain || 80001;
let data = AllChains.find((o) => o.id === chain); let data = this.chainMap.get(chain);
if (!data) { if (!data) {
throw new Error("no current chain data"); throw new Error("no current chain data");
} }
this._currentChain = data; this._currentChain = data;
this.rpcUrl = data.rpc; this.rpcUrl = data.rpc;
console.log(`rpc url: ${this.rpcUrl}`); console.log(`rpc url: ${this.rpcUrl}`);
this.init({ chains: [chain], password: this.password });
} }
public get isInternal() { public get isInternal() {
@ -198,16 +198,13 @@ export default class JCWallet {
* create local wallet data if there is no local wallet data * create local wallet data if there is no local wallet data
* @returns * @returns
*/ */
private init({ chains, password }: { chains: number[]; password: string }) { private init() {
for (let chain of chains) { for (let chain of AVAILABLE_CHAINS) {
this.chainSet.add(chain); this.chainSet.add(chain);
if (!this.chainMap.has(chain)) { if (!this.chainMap.has(chain)) {
let data = AllChains.find((o) => o.id === chain); let data = AllChains.find((o) => o.id === chain);
if (data) { if (data) {
this.chainMap.set(chain, data); this.chainMap.set(chain, data);
if (!this._currentChain) {
this._currentChain = data;
}
} }
} }
} }
@ -225,6 +222,10 @@ export default class JCWallet {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (this.walletType === WalletType.INTERNAL) { if (this.walletType === WalletType.INTERNAL) {
const chainData = this.chainMap.get(chainId); const chainData = this.chainMap.get(chainId);
if (!chainData) {
reject && reject("chain data not found");
return;
}
this._currentChain = chainData; this._currentChain = chainData;
this.web3.eth.setProvider(chainData.rpc); this.web3.eth.setProvider(chainData.rpc);
this.mainHandlers.emit(WALLET_CHAIN_CHANGE, chainData); this.mainHandlers.emit(WALLET_CHAIN_CHANGE, chainData);

View File

@ -1,4 +1,4 @@
import "whatwg-fetch"; import { fetch } from "whatwg-fetch";
import { WalletEnv } from "../config/WalletEnv"; import { WalletEnv } from "../config/WalletEnv";
export function request(url, option) { export function request(url, option) {

View File

@ -105,7 +105,6 @@ export async function loadInternalWallet(pass: string) {
} }
let { id, openid } = walletEnv.tokenData; let { id, openid } = walletEnv.tokenData;
console.log("data from token: " + JSON.stringify(walletEnv.tokenData));
let address = jsb.prepareWallet( let address = jsb.prepareWallet(
id, id,
openid, openid,

View File

@ -5,6 +5,7 @@ import {
sendCode, sendCode,
verifyEmailByCode, verifyEmailByCode,
} from "../api/EmailApi"; } from "../api/EmailApi";
import { ZError } from "../common/ZError";
import { singleton } from "../decorator/singleton.decorator"; import { singleton } from "../decorator/singleton.decorator";
@ -20,7 +21,7 @@ export class EmailVerifySvr {
}> { }> {
let res = await isEmailVerified(); let res = await isEmailVerified();
if (res.errcode) { if (res.errcode) {
throw new Error("Failed to fetch email verification status"); //Throw error if call to the checking function fails throw new ZError(res.errcode, res.errmsg); //Throw error if call to the checking function fails
} }
const { data } = res; const { data } = res;
@ -42,18 +43,36 @@ export class EmailVerifySvr {
*/ */
public async sendEmailCode(email: string, type: number) { public async sendEmailCode(email: string, type: number) {
return sendCode({ email, type }); let result = await sendCode({ email, type });
console.log(JSON.stringify(result));
if (result.errcode) {
throw new ZError(result.errcode, result.errmsg);
}
return result.data;
} }
public async updateEmailVerify(email: string, code: string) { public async updateEmailVerify(email: string, code: string) {
return verifyEmailByCode({ email, code }); let result = await verifyEmailByCode({ email, code });
if (result.errcode) {
throw new ZError(result.errcode, result.errmsg);
}
return result.data;
} }
public async isEmailRegister(email: string) { public async isEmailRegister(email: string) {
return checkEmailRegister({ email }); let result = await checkEmailRegister({ email });
if (result.errcode) {
throw new ZError(result.errcode, result.errmsg);
}
return result.data;
} }
public async registByEmail(email: string, password: string, code: string) { public async registByEmail(email: string, password: string, code: string) {
return emailRegister({ email, password, code }); password = jsb.hashSvrPass(password);
let result = await emailRegister({ email, password, code });
if (result.errcode) {
throw new ZError(result.errcode, result.errmsg);
}
return result.data;
} }
} }

View File

@ -1,4 +1,4 @@
import { alchemyPrePay } from "../api/PayApi"; import { reqAlchemyPrePay } from "../api/PayApi";
import { singleton } from "../decorator/singleton.decorator"; import { singleton } from "../decorator/singleton.decorator";
import { IPayData } from "../types/data.types"; import { IPayData } from "../types/data.types";
@ -10,7 +10,7 @@ export class PaySvr {
* @returns The result of the alchemyPrePay function. * @returns The result of the alchemyPrePay function.
*/ */
public async alchemyPrePay(data: IPayData) { public async alchemyPrePay(data: IPayData) {
let res = await alchemyPrePay(data); let res = await reqAlchemyPrePay(data);
if (res.errcode) { if (res.errcode) {
throw new Error(res.errmsg); throw new Error(res.errmsg);
} }