修改alchymy购买流程,所有api请求增加header

This commit is contained in:
CounterFire2023 2023-08-04 12:06:46 +08:00
parent 0ae4b54bd8
commit db4b6da5f3
6 changed files with 56 additions and 30 deletions

View File

@ -1,13 +1,18 @@
import { PAY_API_HOST } from '../config/constants';
import { PAY_API_HOST_ETH } from '../config/constants';
import { GET_JSON, POST_JSON } from '../lib/Http';
export function reqAlchemyPrePay(data: any) {
const url = `${PAY_API_HOST}/pay/alchemy/buy`;
const url = `${jc.wallet.payUrl}/pay/alchemy/buy`;
return POST_JSON(url, data);
}
export function reqAlchemyPayETH(data: any) {
const url = `${PAY_API_HOST_ETH}/pay/alchemy/buy`;
return POST_JSON(url, data);
}
export function queryTokenUsdPrice(eth: string, chain: string, env: string) {
const url = `${PAY_API_HOST}/pay/alchemy/crypto_price`;
const url = `${jc.wallet.payUrl}/pay/alchemy/crypto_price`;
return POST_JSON(url, { token: eth, chain, env });
}
/**
@ -15,21 +20,21 @@ export function queryTokenUsdPrice(eth: string, chain: string, env: string) {
* @returns
*/
export function checkBuyTreasury() {
const url = `${PAY_API_HOST}/pay/alchemy/can_i_buy_treasury`;
const url = `${jc.wallet.payUrl}/pay/alchemy/can_i_buy_treasury`;
return GET_JSON(url);
}
export function queryFiatList() {
const url = `${PAY_API_HOST}/pay/alchemy/fait_list`;
const url = `${jc.wallet.payUrl}/pay/alchemy/fait_list`;
return GET_JSON(url);
}
export function verifyGooglePay(data: any) {
const url = `${PAY_API_HOST}/pay/google/verify`;
const url = `${jc.wallet.payUrl}/pay/google/verify`;
return POST_JSON(url, data);
}
export function verifyApplePay(data: any) {
const url = `${PAY_API_HOST}/pay/apple/verify`;
const url = `${jc.wallet.payUrl}/pay/apple/verify`;
return POST_JSON(url, data);
}

View File

@ -1,5 +1,5 @@
import { WALLET_API_HOST } from "../config/constants";
import { GET_JSON, POST_JSON } from "../lib/Http";
import { WALLET_API_HOST } from '../config/constants';
import { GET_JSON, POST_JSON } from '../lib/Http';
export function googleAuth(idToken: string) {
const url = `${WALLET_API_HOST}/wallet/login/google`;

View File

@ -4,6 +4,8 @@ export const WALLET_STORAGE_KEY_NAME = 'jc_wallet_data';
// export const PAY_API_HOST = 'http://192.168.100.183:3007';
export const WALLET_API_HOST = 'https://wallet.cebggame.com';
export const PAY_API_HOST = 'https://pay.cebggame.com/v2';
export const PAY_API_HOST_ETH = 'https://pay.cebggame.com/v1';
export const PAY_API_HOST_TEST = 'https://pay.cebggame.com/v0';
export const MAX_TRY_COUNT = 6;
@ -20,3 +22,5 @@ export const AVAILABLE_CHAINS = [80001, 421613, 137, 42161];
export const BASE_TOKEN_URI = 'https://market.cebg.games/api/nft/info/';
export const GAS_BOOST = 1.2;
export const VERSION_CODE = 1;

View File

@ -1,10 +1,16 @@
import { recoverTypedSignature, signTypedData, SignTypedDataVersion } from '@metamask/eth-sig-util';
import Web3 from 'web3';
import 'whatwg-fetch';
import { createWalletEvents, WALLET_ACCOUNT_CHANGE, WALLET_CHAIN_CHANGE } from './common/WalletEvent';
import { JazzIcon } from './comp/JazzIcon';
import { ZWalletConnect } from './comp/ZWalletConnect';
import { AVAILABLE_CHAINS, NATIVE_PK_PREFIX, TX_CONFIRM_BLOCKS, WALLET_STORAGE_KEY_NAME } from './config/constants';
import {
AVAILABLE_CHAINS,
NATIVE_PK_PREFIX,
PAY_API_HOST,
PAY_API_HOST_TEST,
TX_CONFIRM_BLOCKS,
WALLET_STORAGE_KEY_NAME,
} from './config/constants';
import { AllChains } from './data/allchain';
import { singleton } from './decorator/singleton.decorator';
import { parseUrl } from './manage/SchemeManage';
@ -23,7 +29,6 @@ import { IChainData } from './types/data.types';
import { universalChainCb } from './util/chain.util';
import { fromTokenMinimalUnit, renderFromTokenMinimalUnit, safeNumberToBN } from './util/number.util';
import { buildLoginSignMsg, signLogin } from './util/sign.util';
import { parse } from 'url';
var global =
(typeof globalThis !== 'undefined' && globalThis) ||
@ -55,7 +60,7 @@ export default class JCWallet {
private rpcUrl: string = '';
public rpc: any = {};
public nativeAccount = '';
private env = 'dev';
public env = 'dev';
private web3Map = new Map();
constructor({ type }: { type: number }) {
@ -83,6 +88,14 @@ export default class JCWallet {
return this.walletType === WalletType.INTERNAL;
}
public get payUrl() {
if (this.env === 'release') {
return PAY_API_HOST;
} else {
return PAY_API_HOST_TEST;
}
}
public preLogin(channel: number) {
return walletPreLogin(channel);
}

View File

@ -1,18 +1,21 @@
import { fetch } from "whatwg-fetch";
import { WalletEnv } from "../config/WalletEnv";
import { fetch } from 'whatwg-fetch';
import { WalletEnv } from '../config/WalletEnv';
import { VERSION_CODE } from '../config/constants';
export function request(url, option) {
let headers = new Headers();
headers.append("Content-Type", "application/json");
headers.append('Content-Type', 'application/json');
let walletEnv = new WalletEnv();
if (walletEnv.token) {
headers.append("Authorization", `Bearer ${walletEnv.token}`);
headers.append('Authorization', `Bearer ${walletEnv.token}`);
}
headers.append('api_version', VERSION_CODE + '');
headers.append('api_env', jc.wallet.env);
let optionInt: any = {
method: "GET",
mode: "cors",
method: 'GET',
mode: 'cors',
headers,
cache: "no-cache",
cache: 'no-cache',
};
Object.assign(optionInt, option);
// console.log("request option", JSON.stringify(optionInt));
@ -31,7 +34,7 @@ export function GET_JSON(url: string) {
export function POST(url, data) {
let option = {
method: "POST",
method: 'POST',
body: JSON.stringify(data),
};
return request(url, option);
@ -39,7 +42,7 @@ export function POST(url, data) {
export function DELETE(url, data) {
let option = {
method: "DELETE",
method: 'DELETE',
body: JSON.stringify(data),
};
return request(url, option);
@ -47,7 +50,7 @@ export function DELETE(url, data) {
export function PUT(url, data) {
let option = {
method: "PUT",
method: 'PUT',
body: JSON.stringify(data),
};
return request(url, option);

View File

@ -1,5 +1,6 @@
import { queryFiatList, queryTokenUsdPrice, reqAlchemyPrePay, verifyApplePay, verifyGooglePay } from '../api/PayApi';
import { ZError } from '../common/ZError';
import { VERSION_CODE } from '../config/constants';
import { singleton } from '../decorator/singleton.decorator';
import { IPayData } from '../types/data.types';
import { NativeSvr } from './NativeSvr';
@ -12,11 +13,13 @@ export class PaySvr {
* @param data - The data to be passed to the alchemyPrePay function.
* @returns The result of the alchemyPrePay function.
*/
public async alchemyPrePay(data: IPayData) {
data.network = jc.wallet.currentChain.network;
data.crypto = data.crypto.toUpperCase();
data.country = data.country.toUpperCase();
data.fiat = data.fiat.toUpperCase();
public async alchemyPrePay(data: any) {
// data.network = data.network || jc.wallet.currentChain.network;
// data.crypto = data.crypto.toUpperCase();
// data.country = data.country.toUpperCase();
// data.fiat = data.fiat.toUpperCase();
data.evn = jc.wallet.env;
data.version = VERSION_CODE;
let res = await reqAlchemyPrePay(data);
if (res.errcode) {
throw new Error(res.errmsg);
@ -29,8 +32,6 @@ export class PaySvr {
throw new Error('No url returned');
}
console.log('pay url::', url);
// jsb.showWebPage(url);
// jsb.openURL(url);
return res.data;
}