From 45a6495c4b44e12f64d25f2b140c8f3b0bb7014f Mon Sep 17 00:00:00 2001 From: Viterbo Date: Thu, 18 Jan 2024 04:27:51 -0300 Subject: [PATCH] Simpler flow for Telos Cloud Login --- env.js | 4 +- src/antelope/stores/account.ts | 8 +- src/antelope/wallets/ual/MetakeepUAL.ts | 20 +- src/boot/ual.js | 2 +- src/i18n/en-us/index.js | 1 + src/pages/home/HomePage.vue | 59 ++- src/pages/home/LoginButtons.vue | 543 ++++++++++++++++++++++ test/jest/utils/antelope/store-account.ts | 4 +- 8 files changed, 594 insertions(+), 47 deletions(-) create mode 100644 src/pages/home/LoginButtons.vue diff --git a/env.js b/env.js index f6ffdbd1..7e8c945a 100644 --- a/env.js +++ b/env.js @@ -11,7 +11,9 @@ const sharedEnv = { PROJECT_ID: '2392473d6d98499c7138cd2d705a791f', METAKEEP_APP_ID_NATIVE: 'ad5e05fb-280a-41ae-b186-5a2654567b92', METAKEEP_APP_ID_EVM: 'd190c88f-1bb5-4e16-bc48-96dbf33b77e0', - GOOGLE_APP_ID: '56634824599-ff3iu788c32c3s7ec65cs4bieop9gpgv.apps.googleusercontent.com', + // GOOGLE_APP_ID: '56634824599-ff3iu788c32c3s7ec65cs4bieop9gpgv.apps.googleusercontent.com', + GOOGLE_APP_ID: '639241197544-kcubenhmti6u7ef3uj360n2lcl5cmn8c.apps.googleusercontent.com', + // FIXME: This is a auxillary key for the app, it should be replaced for the one commented }; const TESTNET = { diff --git a/src/antelope/stores/account.ts b/src/antelope/stores/account.ts index bc92cae6..9540aa4e 100644 --- a/src/antelope/stores/account.ts +++ b/src/antelope/stores/account.ts @@ -38,7 +38,7 @@ import { } from 'src/antelope'; -export interface LoginNativeActionData { +export interface loginZeroActionData { authenticator: Authenticator, network: string, } @@ -110,8 +110,8 @@ export const useAccountStore = defineStore(store_name, { }, actions: { trace: createTraceFunction(store_name), - async loginNative({ authenticator, network }: LoginNativeActionData): Promise { - this.trace('loginNative', authenticator, network); + async loginZero({ authenticator, network }: loginZeroActionData): Promise { + this.trace('loginZero', authenticator, network); let success = false; try { await authenticator.init(); @@ -254,7 +254,7 @@ export const useAccountStore = defineStore(store_name, { console.error(authenticators.map(a => a.getName()).join(', ')); throw new Error('antelope.account.error_auto_login'); } - this.loginNative({ + this.loginZero({ authenticator, network, }); diff --git a/src/antelope/wallets/ual/MetakeepUAL.ts b/src/antelope/wallets/ual/MetakeepUAL.ts index 625cf683..329ef195 100644 --- a/src/antelope/wallets/ual/MetakeepUAL.ts +++ b/src/antelope/wallets/ual/MetakeepUAL.ts @@ -205,11 +205,9 @@ export class MetakeepAuthenticator extends Authenticator { public_key: publicKey, }); const accountExists = response?.data?.account_names.length>0; - console.log('accountExists: ', accountExists, 'pero la descartamos'); if (accountExists) { accountName = response.data.account_names[0]; } else { - console.log('vamos a crear la cuenta'); accountName = await this.createAccount(publicKey); } @@ -326,6 +324,16 @@ class MetakeepUser extends User { this.reasonCallback = callback; } + handleCatchError(error: any): Error { + if ( + (error as unknown as {status:string}).status === 'USER_REQUEST_DENIED' + ) { + return new Error('antelope.evm.error_transaction_canceled'); + } else { + return new Error('antelope.evm.error_send_transaction'); + } + } + /** * @param transaction The transaction to be signed (a object that matches the RpcAPI structure). */ @@ -423,13 +431,7 @@ class MetakeepUser extends User { return Promise.resolve(finalResponse); } catch (e: any) { - if (e.status) { - throw new Error(e.status); - } else if (e.message) { - throw new Error(e.message); - } else { - throw new Error('Unknown error'); - } + throw this.handleCatchError(e); } } diff --git a/src/boot/ual.js b/src/boot/ual.js index c2985c62..7552bbba 100644 --- a/src/boot/ual.js +++ b/src/boot/ual.js @@ -50,7 +50,7 @@ export default boot(async ({ app, store }) => { }).catch((e) => { throw e; }); - if (store.state.account.justViewer) { + if (store.state.account.justViewer || localStorage.getItem('justViewer')) { permission = 'active'; } else { await new Promise((resolve) => { diff --git a/src/i18n/en-us/index.js b/src/i18n/en-us/index.js index 8c64e79f..0fb64ec1 100644 --- a/src/i18n/en-us/index.js +++ b/src/i18n/en-us/index.js @@ -31,6 +31,7 @@ export default { view_any_account: 'View Any Account', connect_with_wallet: 'Connect Your Wallet', telos_cloud_wallet: 'Telos Cloud Wallet', + telos_cloud_login: 'Telos Cloud Login', sign_with_google: 'Sign with Google', sign_with_facebook: 'Sign with Facebook', sign_with_x: 'Sign with X', diff --git a/src/pages/home/HomePage.vue b/src/pages/home/HomePage.vue index 3aa11ddb..c5083977 100644 --- a/src/pages/home/HomePage.vue +++ b/src/pages/home/HomePage.vue @@ -1,36 +1,51 @@ + + + + diff --git a/test/jest/utils/antelope/store-account.ts b/test/jest/utils/antelope/store-account.ts index 121a70ed..a2f74294 100644 --- a/test/jest/utils/antelope/store-account.ts +++ b/test/jest/utils/antelope/store-account.ts @@ -21,7 +21,7 @@ const getAuthenticator = jest.fn().mockImplementation(() => null); const getEVMAuthenticator = jest.fn().mockImplementation(() => MockData.EvmAuthenticator); const getNativeAuthenticator = jest.fn().mockImplementation(() => null); -const loginNative = jest.fn().mockImplementation(() => ({ +const loginZero = jest.fn().mockImplementation(() => ({ then: jest.fn().mockImplementation((cb: any) => cb()), })); const loginEVM = jest.fn().mockImplementation(() => ({ @@ -76,7 +76,7 @@ const AccountActions = { getAuthenticator, getEVMAuthenticator, getNativeAuthenticator, - loginNative, + loginZero, loginEVM, logout, autoLogin,