PogHttp.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import Http from "../utils/Http";
  2. export interface PogResp {
  3. protocolId: number;
  4. requestId: number;
  5. code: number;
  6. success: boolean;
  7. data: any;
  8. msg: string;
  9. }
  10. export interface PogLoginResp {
  11. token: string;
  12. expire: number;
  13. wsUrl: string;
  14. }
  15. export interface PogSignMessageResp {
  16. nonce: string;
  17. message: string;
  18. fullMessage: string;
  19. }
  20. export default class PogHttp {
  21. private static readonly client = "YbVHPrXS";
  22. private static readonly HTTP_HEAD = "https://zombies.telgather.com/platform";
  23. private static _ins: PogHttp;
  24. public static get ins(): PogHttp {
  25. return (this._ins ??= new PogHttp());
  26. }
  27. public lastError: string = "";
  28. public async _apiRequest(path: string, params: any): Promise<any> {
  29. const headers = {
  30. client: PogHttp.client,
  31. };
  32. const resp = await Http.get(PogHttp.HTTP_HEAD + path, params, headers);
  33. const pogResp = resp as PogResp;
  34. if (pogResp.code !== 200) {
  35. this.lastError = pogResp.msg;
  36. return null;
  37. }
  38. return pogResp.data;
  39. }
  40. async getSignMessage(address: string): Promise<PogSignMessageResp> {
  41. const path = "/pog-service/login/wallet/before";
  42. const res = await this._apiRequest(path, { address });
  43. return res;
  44. }
  45. public async loginByWalletAddress(address: string): Promise<PogLoginResp> {
  46. const path = "/pog-service/login/wallet";
  47. const res = await this._apiRequest(path, { address });
  48. return res;
  49. }
  50. async loginByWalletAddressAndSignature(address: string, signature: string): Promise<PogLoginResp> {
  51. const path = "/pog-service/login/wallet";
  52. console.log("loginByWalletAddressAndSignature", address, signature+"");
  53. const res = await this._apiRequest(path, { address, signature });
  54. return res;
  55. }
  56. async loginByTgParams(
  57. initDataRaw: string,
  58. tgWebAppStartParam: string
  59. ): Promise<PogLoginResp> {
  60. const path = "/pog-service/login/tg";
  61. if (!tgWebAppStartParam) {
  62. tgWebAppStartParam = "ABC";
  63. }
  64. const res = await this._apiRequest(path, {
  65. params: initDataRaw,
  66. inviteCode: tgWebAppStartParam,
  67. });
  68. return res;
  69. }
  70. async allConfig(): Promise<any> {
  71. const path = "/pog-service/login/config";
  72. const res = await this._apiRequest(path, {});
  73. return res;
  74. }
  75. }