Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telos Cloud Login | simpler flow #757

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 4 additions & 4 deletions src/antelope/stores/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
} from 'src/antelope';


export interface LoginNativeActionData {
export interface loginZeroActionData {
authenticator: Authenticator,
network: string,
}
Expand Down Expand Up @@ -110,8 +110,8 @@ export const useAccountStore = defineStore(store_name, {
},
actions: {
trace: createTraceFunction(store_name),
async loginNative({ authenticator, network }: LoginNativeActionData): Promise<boolean> {
this.trace('loginNative', authenticator, network);
async loginZero({ authenticator, network }: loginZeroActionData): Promise<boolean> {
this.trace('loginZero', authenticator, network);
let success = false;
try {
await authenticator.init();
Expand Down Expand Up @@ -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,
});
Expand Down
20 changes: 11 additions & 9 deletions src/antelope/wallets/ual/MetakeepUAL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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).
*/
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/boot/ual.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en-us/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
59 changes: 29 additions & 30 deletions src/pages/home/HomePage.vue
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';

import NativeLoginButton from 'pages/home/NativeLoginButton.vue';
import EVMLoginButtons from 'pages/home/EVMLoginButtons.vue';
import LoginButtons from 'pages/home/LoginButtons.vue';
import { Menu } from 'src/pages/home/MenuType';
import { LocationQueryValue, useRoute, useRouter } from 'vue-router';
import { CURRENT_CONTEXT, useChainStore } from 'src/antelope';

type TabReference = 'evm' | 'zero';
type TabReference = 'evm' | 'zero' | 'unset';

const route = useRoute();
const router = useRouter();
const chainStore = useChainStore();

const tab = ref<TabReference>('evm');
const currentMenu = ref<Menu>(Menu.MAIN);

const showLoginBtns = computed((): boolean => currentMenu.value === Menu.MAIN);
const tab = ref<TabReference>('unset');
const walletOption = computed(() => route.query.login as LocationQueryValue);

function goBack(): void {
currentMenu.value = Menu.MAIN;
function setChainForTab(tab: TabReference): void {
// set chain
if (!process.env.CHAIN_NAME) {
console.error('No chain name specified in environment config; the application will not run correctly');
} else {
const chainNetworkNames: Record<string, string> = (tab === 'zero') ? {
'telos': 'telos',
'telos-testnet': 'telos-testnet',
} : {
'telos': 'telos-evm',
'telos-testnet': 'telos-evm-testnet',
};
const network: string = chainNetworkNames[process.env.CHAIN_NAME];
chainStore.setChain(CURRENT_CONTEXT, network);
}
}

function setTab(login: TabReference): void {
if (route.path !== login){
router.replace({ path: route.path, query:{ login } });
tab.value = login;
setChainForTab(login);
}
}

onMounted(() => {
if (walletOption.value){
tab.value = walletOption.value as TabReference;
setTab(walletOption.value as TabReference);
} else {
// set evm as default
setTab('evm');
}
});

Expand All @@ -47,7 +62,7 @@ onMounted(() => {
class="c-home__logo"
></div>
<div class="c-home__button-container">
<div v-if="showLoginBtns" class="c-home__network-toggle-container" role="tablist">
<div class="c-home__network-toggle-container" role="tablist">
<button
:class="{
'c-home__network-toggle-button': true,
Expand Down Expand Up @@ -75,28 +90,12 @@ onMounted(() => {
{{ $t('global.native') }}
</button>
</div>
<div v-else>
<q-btn
class="c-home__menu-back-button"
flat
dense
icon="arrow_back_ios"
@click="goBack"
>

{{ $t('global.back') }}
</q-btn>
</div>

<NativeLoginButton
v-if="tab === 'zero'"
v-model="currentMenu"
<LoginButtons
:chain="tab"
/>

<EVMLoginButtons
v-else-if="tab === 'evm'"
v-model="currentMenu"
/>

</div>
<div class="c-home__external-link">
<a
Expand Down
Loading
Loading