Shawn Lu il y a 1 an
Parent
commit
b97684c419
1 fichiers modifiés avec 19 ajouts et 14 suppressions
  1. 19 14
      src/lunchClient.ts

+ 19 - 14
src/lunchClient.ts

@@ -18,9 +18,9 @@ import { Status } from './models/Status'
 
 export class LunchClient {
   mnemonic: string
-  client: AxiosInstance
+  axiosClient: AxiosInstance
   proxyAgent: HttpsProxyAgent<any>
-  key
+  key: MnemonicKey
   constructor(mnemonic: string, useProxy: boolean = true) {
     this.mnemonic = mnemonic
     this.proxyAgent = useProxy ? getProxyAgent() : undefined
@@ -64,7 +64,7 @@ export class LunchClient {
       message,
       account.duid,
     )
-    const client = isAndroid
+    this.axiosClient = isAndroid
       ? axios.create({
           headers: {
             'Lunch-Language': 'EN',
@@ -90,7 +90,7 @@ export class LunchClient {
           },
         })
 
-    const resp = await client.post(
+    const resp = await this.axiosClient.post(
       'https://api.lunchlunch.xyz/v1/auth/sign-in',
       {
         walletAddress: evmWallet.address,
@@ -100,25 +100,30 @@ export class LunchClient {
     )
     console.log(`${account.address}: sign-in success.`)
     // register
-    client.defaults.headers['authorization'] = `Bearer ${resp.data.accessToken}`
+    this.axiosClient.defaults.headers[
+      'authorization'
+    ] = `Bearer ${resp.data.accessToken}`
     const xrplWallet = xrpl.Wallet.fromSeed(account.xrpPrivateKey)
     let needRegister = false
     try {
-      await client.get('https://api.lunchlunch.xyz/v1/member')
+      await this.axiosClient.get('https://api.lunchlunch.xyz/v1/member')
     } catch (e) {
       if (e.response.status === 404) {
         needRegister = true
       }
     }
     if (needRegister) {
-      await client.post('https://api.lunchlunch.xyz/v1/member/register', {
-        evmWalletAddress: evmWallet.address,
-        initiaWalletAddress: this.key.accAddress,
-        isImportedWallet: true,
-        firstInitiaWalletAddress: this.key.accAddress,
-        email: account.gmail,
-        xrplWalletAddress: xrplWallet.address,
-      })
+      await this.axiosClient.post(
+        'https://api.lunchlunch.xyz/v1/member/register',
+        {
+          evmWalletAddress: evmWallet.address,
+          initiaWalletAddress: this.key.accAddress,
+          isImportedWallet: true,
+          firstInitiaWalletAddress: this.key.accAddress,
+          email: account.gmail,
+          xrplWalletAddress: xrplWallet.address,
+        },
+      )
       console.log(`${this.key.accAddress}: register done`)
     } else {
       console.log(`${this.key.accAddress}: already registered`)