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 Wallet (powered by Metakeep) #728

Closed
wants to merge 22 commits into from

Conversation

Viterbo
Copy link
Collaborator

@Viterbo Viterbo commented Jan 3, 2024

Fixes #727, #713

BLOCKED: The Telos Cloud for Telos Zero is not working yet because the account-creation endpoint is not ready to go yet. We need to set up a new Table in the database to remember the account created for each Google user so we don't create more than one per user.

Description

This PR includes the implementation of the new Telos Cloud Wallet, powered by Metakeep, for both Telos EVM and Telos Zero. It entirely removes any references to the old OreId service.

Additionally, the auto-login feature has been stabilized to ensure reliable functionality in all cases (EVM or Zero): for example, if the user is logged into Telos Zero and opens the website on any page, he or she will be redirected to the Telos Zero balances page (and similarly with EVM).

Checks have been added to ensure the correct network is being used before performing tasks such as obtaining the conversion ratio (STLOS) or the APY of the staking.

Test scenarios

EVM

  • go to this link and, click Telos Cloud Wallet button, wait for the Google Btn to render and click it.
  • After you authenticate with Google you should be logged in and redirected to /evm/wallet?tab=balance
  • Try to perform any transaction (like sending tokens to yourself)

EVM auto-login

T-Zero (This still does not work because the endpoint is not ready)

  • First, log out if you are not
  • Go to this link and, click Telos Cloud Wallet button, wait for the Google Btn to render, and click it.
  • After you authenticate with Google you should be logged in and redirected to /zero/balance
  • Try to perform any transaction (like staking for CPU)

T-Zero auto-login

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have cleaned up the code in the areas my change touches
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings
  • I have removed any unnecessary console messages
  • I have included all english text to the translation file and/or created a new issue with the required translations for the currently supported languages
  • I have tested for mobile functionality and responsiveness
  • I have added appropriate test coverage

@Viterbo Viterbo linked an issue Jan 3, 2024 that may be closed by this pull request
Copy link

netlify bot commented Jan 3, 2024

Deploy Preview for wallet-staging ready!

Name Link
🔨 Latest commit 722465a
🔍 Latest deploy log https://app.netlify.com/sites/wallet-staging/deploys/65a6a3aa6e7bb200083f7c35
😎 Deploy Preview https://deploy-preview-728--wallet-staging.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 3, 2024

Deploy Preview for wallet-develop-mainnet ready!

Name Link
🔨 Latest commit 722465a
🔍 Latest deploy log https://app.netlify.com/sites/wallet-develop-mainnet/deploys/65a6a3aac7b3bb000874d8bf
😎 Deploy Preview https://deploy-preview-728--wallet-develop-mainnet.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Viterbo Viterbo self-assigned this Jan 8, 2024
@Viterbo Viterbo mentioned this pull request Jan 11, 2024
@Viterbo Viterbo changed the title 727 new telos cloud wallet powered by metakeep Telos Cloud Wallet (powered by Metakeep) Jan 15, 2024
Comment on lines +48 to +53
const script = document.createElement('script');
script.src = 'https://cdn.usefathom.com/script.js';
script.dataset.site = 'ISPYEAKT';
script.dataset.spa = 'auto';
script.defer = true;
document.body.appendChild(script);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ezra-sg, this code was inside an if and the condition was that the chain used is EVM.

I had a lot of problems related to the chain being set (especially on auto-login situations where telos-evm is set because of the UI and then the telos-zero is set because the user was previously logged in telos zero).

What I need to know is if it is safe to remove that condition and have this code executed always.

Comment on lines +242 to +246
if (chainSettings.isNative()) {
this.trace('fetchAllowancesForAccount', 'Native chain does not have allowances');
return;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This avoids trying to fetch allowances data from a native chain

Comment on lines +187 to +190
if (!chain.settings.isNative()) {
const chain_settings = chain.settings as EVMChainSettings;
const sysToken = chain_settings.getSystemToken();
const stkToken = chain_settings.getStakedSystemToken();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this avoids fetching the staking ratio data from a non-evm chain

Comment on lines +263 to +270
if (!chain.settings.isNative()) {
const decimals = (this.getChain(label).settings as EVMChainSettings).getStakedSystemToken().decimals;
const ratioNumber = parseFloat(ethers.utils.formatUnits(ratio, decimals));
this.trace('setStakedRatio', label, ratio.toString(), ratioNumber);
(this.__chains[label] as EvmChainModel).stakeRatio = ratio;
} else {
this.trace('setStakedRatio', label, 'Native chain has no staked ratio');
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensuring the correct chain

Comment on lines +283 to +290
if (!chain.settings.isNative()) {
const decimals = (this.getChain(label).settings as EVMChainSettings).getStakedSystemToken().decimals;
const ratioNumber = parseFloat(ethers.utils.formatUnits(ratio, decimals));
this.trace('setUnstakedRatio', label, ratio.toString(), ratioNumber);
(this.__chains[label] as EvmChainModel).unstakeRatio = ratio;
} else {
this.trace('setUnstakedRatio', label, 'Native chain has no unstaked ratio');
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensuring the correct chain

Comment on lines +195 to +198
if (chainSettings.isNative()) {
this.trace('fetchEvmNftTransfersForAccount', 'Native networks not supported yet');
return;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetching history only for EVM (for now)

Comment on lines +133 to +139
if (this.isNetworkEVM(label)) {
const contract = await this.getStakedSystemContractInstance(label);
const totalStaking = await contract.totalAssets();
this.setTotalStaking(label, totalStaking);
} else {
this.trace('updateTotalStaking', label, 'not supported for native chains yet');
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only for EVM chains

Comment on lines +148 to +154
if (this.isNetworkEVM(label)) {
const contract = await this.getEscrowContractInstance(label);
const period = await contract.lockDuration();
this.setUnstakingPeriod(label, period.toNumber());
} else {
this.trace('updateUnstakingPeriod', label, 'not supported for native chains yet');
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only for EVM chains

Comment on lines +197 to +204
if (this.isNetworkEVM(label)) {
const contract = await this.getEscrowContractInstance(label);
const address = useAccountStore().getAccount(label).account;
const withdrawable = await contract.maxWithdraw(address);
this.setWithdrawable(label, withdrawable);
} else {
this.trace('updateWithdrawable', label, 'not supported for native chains yet');
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only for EVM chains

Comment on lines +214 to +221
if (this.isNetworkEVM(label)) {
const contract = await this.getEscrowContractInstance(label);
const address = useAccountStore().getAccount(label).account;
const deposits = await contract.depositsOf(address);
this.setDeposits(label, deposits);
} else {
console.error('updateDeposits', label, 'not supported for native chains yet');
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only for EVM chains

Comment on lines +230 to +237
if (this.isNetworkEVM(label)) {
const contract = await this.getEscrowContractInstance(label);
const address = useAccountStore().getAccount(label).account;
const balance = await contract.balanceOf(address);
this.setBalance(label, balance);
} else {
console.error('updateBalance', label, 'not supported for native chains yet');
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only for EVM chains

@@ -42,28 +42,19 @@ export class AntelopeWallets {
// we try first the best solution which is taking the provider from the current authenticator
const authenticator = account.authenticator as EVMAuthenticator;
const provider = authenticator.web3Provider();
this.trace('getWeb3Provider authenticator.web3Provider() Success! (account.authenticator)', provider);
return provider;
} catch(e1) {
this.trace('getWeb3Provider authenticator.web3Provider() Failed!', e1);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second option was window.ethereum but now is removed. The problem with that option is that the window.ethereum may be present but the wallet may be not even opened, so the user is not logged and the chain is not set. In that case, the provider does not work so the option is discarded.

Comment on lines +1 to +3
// utils/metakeep-cache.ts

export interface MetakeepCacheData {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an auxiliary file with useful functions to keep cached all data coming from metakeep, so we don't need to query the same data over and over again each time the user logs in. That makes the process of auto-log much faster.

Comment on lines +48 to +58
next: async (account: AccountModel) => {
if (account.isNative) {
if (!window.location.pathname.startsWith('/zero')) {
const router = await getRouter(app);
router.push({ path: '/zero/balance' });
}
} else {
if (!window.location.pathname.startsWith('/evm')) {
const router = await getRouter(app);
router.push({ path: '/evm/wallet?tab=balance' });
}
Copy link
Collaborator Author

@Viterbo Viterbo Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the redirection takes into account which type of chain you are logging in to. It only redirects you if you are on the wrong path.

Comment on lines +1 to +5
import { AntelopeError } from 'src/antelope/types';

import * as Buffer from 'buffer';
import { BehaviorSubject, Subject } from 'rxjs';

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an auxiliary file with useful functions to handle everything related to the GoogleOneTap service.

@Viterbo Viterbo mentioned this pull request Jan 17, 2024
4 tasks
@Viterbo Viterbo marked this pull request as draft January 18, 2024 01:28
@Viterbo Viterbo closed this Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Telos Cloud Wallet powered by Metakeep
1 participant