-
Notifications
You must be signed in to change notification settings - Fork 8
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
Changes from 19 commits
b7e9263
056dee9
0710c04
6f6d22d
90c7e36
4d8cd04
25a86a4
3402699
3617270
6f8c951
1040b9d
09052f3
38e465c
20fdb9c
171a9a2
0c9009a
c11c5ec
f641d3f
2879291
19799d0
315e337
722465a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,5 +34,5 @@ yarn-error.log* | |
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
|
||
.vscode | ||
.env |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,6 +239,11 @@ export const useAllowancesStore = defineStore(store_name, { | |
|
||
const chainSettings = useChainStore().currentChain.settings as EVMChainSettings; | ||
|
||
if (chainSettings.isNative()) { | ||
this.trace('fetchAllowancesForAccount', 'Native chain does not have allowances'); | ||
return; | ||
} | ||
|
||
Comment on lines
+242
to
+246
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This avoids trying to fetch allowances data from a native chain |
||
const erc20AllowancesPromise = chainSettings.fetchErc20Allowances(account, { limit: ALLOWANCES_LIMIT }); | ||
const erc721AllowancesPromise = chainSettings.fetchErc721Allowances(account, { limit: ALLOWANCES_LIMIT }); | ||
const erc1155AllowancesPromise = chainSettings.fetchErc1155Allowances(account, { limit: ALLOWANCES_LIMIT }); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,23 +180,31 @@ export const useChainStore = defineStore(store_name, { | |
}, | ||
async updateStakedRatio(label: string): Promise<void> { | ||
// first we need the contract instance to be able to execute queries | ||
this.trace('actualUpdateStakedRatio', label); | ||
useFeedbackStore().setLoading('actualUpdateStakedRatio'); | ||
const chain_settings = useChainStore().getChain(label).settings as EVMChainSettings; | ||
const sysToken = chain_settings.getSystemToken(); | ||
const stkToken = chain_settings.getStakedSystemToken(); | ||
this.trace('updateStakedRatio', label); | ||
const chain = this.getChain(label); | ||
try { | ||
useFeedbackStore().setLoading('updateStakedRatio'); | ||
if (!chain.settings.isNative()) { | ||
const chain_settings = chain.settings as EVMChainSettings; | ||
const sysToken = chain_settings.getSystemToken(); | ||
const stkToken = chain_settings.getStakedSystemToken(); | ||
Comment on lines
+187
to
+190
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
const abi = [stlosAbiPreviewDeposit[0], stlosAbiPreviewRedeem[0]]; | ||
const provider = await getAntelope().wallets.getWeb3Provider(); | ||
const contractInstance = new ethers.Contract(stkToken.address, abi, provider); | ||
// Now we preview a deposit of 1 SYS to get the ratio | ||
const oneSys = ethers.utils.parseUnits('1.0', sysToken.decimals); | ||
const stakedRatio = await contractInstance.previewDeposit(oneSys.toString()); | ||
const unstakedRatio:ethers.BigNumber = await contractInstance.previewRedeem(oneSys); | ||
// Finally we update the store | ||
this.setStakedRatio(label, stakedRatio); | ||
this.setUnstakedRatio(label, unstakedRatio); | ||
useFeedbackStore().unsetLoading('actualUpdateStakedRatio'); | ||
const abi = [stlosAbiPreviewDeposit[0], stlosAbiPreviewRedeem[0]]; | ||
const provider = await getAntelope().wallets.getWeb3Provider(); | ||
const contractInstance = new ethers.Contract(stkToken.address, abi, provider); | ||
// Now we preview a deposit of 1 SYS to get the ratio | ||
const oneSys = ethers.utils.parseUnits('1.0', sysToken.decimals); | ||
const stakedRatio = await contractInstance.previewDeposit(oneSys.toString()); | ||
const unstakedRatio:ethers.BigNumber = await contractInstance.previewRedeem(oneSys); | ||
// Finally we update the store | ||
this.setStakedRatio(label, stakedRatio); | ||
this.setUnstakedRatio(label, unstakedRatio); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
} finally { | ||
useFeedbackStore().unsetLoading('updateStakedRatio'); | ||
} | ||
}, | ||
async updateGasPrice(label: string): Promise<void> { | ||
useFeedbackStore().setLoading('updateGasPrice'); | ||
|
@@ -206,6 +214,8 @@ export const useChainStore = defineStore(store_name, { | |
if (!chain.settings.isNative()) { | ||
const wei = await (chain.settings as EVMChainSettings).getGasPrice(); | ||
(chain as EvmChainModel).gasPrice = wei; | ||
} else { | ||
this.trace('updateGasPrice', label, 'Native chain has no gas costs'); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
|
@@ -237,7 +247,6 @@ export const useChainStore = defineStore(store_name, { | |
// make the change only if they are different | ||
if (network !== this.__chains[label]?.settings.getNetwork()) { | ||
this.__chains[label] = newChainModel(network, settings[network].isNative()); | ||
this.trace('setChain', label, network, '--> void this.updateChainData(label);'); | ||
void this.updateChainData(label); | ||
getAntelope().events.onNetworkChanged.next( | ||
{ label, chain: this.__chains[label] }, | ||
|
@@ -248,16 +257,43 @@ export const useChainStore = defineStore(store_name, { | |
} | ||
}, | ||
setStakedRatio(label: string, ratio: ethers.BigNumber) { | ||
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; | ||
this.trace('setStakedRatio', label, ratio.toString()); | ||
const chain = this.getChain(label); | ||
try { | ||
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'); | ||
} | ||
Comment on lines
+263
to
+270
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensuring the correct chain |
||
} catch (error) { | ||
console.error(error); | ||
throw new Error('antelope.chain.error_token_list'); | ||
} finally { | ||
useFeedbackStore().unsetLoading('updateTokenList'); | ||
} | ||
|
||
}, | ||
setUnstakedRatio(label: string, ratio: ethers.BigNumber) { | ||
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; | ||
this.trace('setUnstakedRatio', label, ratio.toString()); | ||
const chain = this.getChain(label); | ||
try { | ||
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'); | ||
} | ||
Comment on lines
+283
to
+290
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensuring the correct chain |
||
} catch (error) { | ||
console.error(error); | ||
throw new Error('antelope.chain.error_token_list'); | ||
} finally { | ||
useFeedbackStore().unsetLoading('updateTokenList'); | ||
} | ||
}, | ||
}, | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,11 +190,14 @@ export const useHistoryStore = defineStore(store_name, { | |
const contractStore = useContractStore(); | ||
|
||
this.trace('fetchEvmNftTransfersForAccount', label); | ||
|
||
feedbackStore.setLoading('history.fetchEvmNftTransfersForAccount'); | ||
|
||
const chainSettings = useChainStore().getChain(label).settings as EVMChainSettings; | ||
|
||
if (chainSettings.isNative()) { | ||
this.trace('fetchEvmNftTransfersForAccount', 'Native networks not supported yet'); | ||
return; | ||
} | ||
Comment on lines
+195
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fetching history only for EVM (for now) |
||
|
||
feedbackStore.setLoading('history.fetchEvmNftTransfersForAccount'); | ||
try { | ||
// get all erc721 and erc1155 transfers for the given account | ||
const [ | ||
|
There was a problem hiding this comment.
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.