-
Notifications
You must be signed in to change notification settings - Fork 23
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
Release/main/20240611 #3494
Release/main/20240611 #3494
Changes from 11 commits
3551808
e71e0a2
0d04748
ecd26f3
2006708
c94711d
894c21b
f72e531
fc4c0a2
9fddcec
8986d13
286c99e
9e91ad6
ff8b07f
3ca1ca4
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
import { DomSanitizer } from '@angular/platform-browser'; | ||
|
||
@Pipe({ name: 'highlight_function' }) | ||
export class HighlightFunctionPipe implements PipeTransform { | ||
constructor(private sanitizer: DomSanitizer) {} | ||
transform(value: string) { | ||
if (!value) return null; | ||
let replacedValue = value; | ||
const parametersPattern = /\(([^)]+)\)/; | ||
const parametersMatch = value.match(parametersPattern); | ||
const parameters = parametersMatch ? parametersMatch[1]?.split(',')?.map((param) => param?.trim()) : []; | ||
|
||
parameters.map((item) => { | ||
const [dataType, modifier, name] = item?.split(' ') || []; | ||
const dataTypeHTML = dataType | ||
? `<span style="color: var(--aura-green-3); font-family: inherit">${dataType}</span>` | ||
: ''; | ||
const modifierHTML = modifier | ||
? `<span style="color: ${ | ||
!name ? 'var(--aura-red-3)' : 'var(--aura-gray-3)' | ||
}; font-family: inherit">${modifier}</span>` | ||
: ''; | ||
const nameHTML = name ? `<span style="color: var(--aura-red-3); font-family: inherit">${name}</span>` : ''; | ||
|
||
replacedValue = replacedValue?.replace(item, `${dataTypeHTML} ${modifierHTML} ${nameHTML}`); | ||
}); | ||
return this.sanitizer.bypassSecurityTrustHtml(replacedValue); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ import { getGasPriceByChain } from '../utils/cosmoskit/helpers/gas'; | |
import { ExtendsWalletClient } from '../utils/cosmoskit/wallets'; | ||
import { wallets as leapMetamask } from '../utils/cosmoskit/wallets/leap-metamask-cosmos-snap'; | ||
import { getSigner } from '../utils/ethers/ethers'; | ||
import { addNetwork, checkNetwork } from '../utils/ethers/utils'; | ||
import { addNetwork, checkNetwork, getMetamask } from '../utils/ethers/utils'; | ||
import local from '../utils/storage/local'; | ||
|
||
@Injectable({ | ||
|
@@ -146,7 +146,7 @@ export class WalletService implements OnDestroy { | |
await this._walletManager.onMounted(); | ||
|
||
this.accountChangeEvent(); | ||
|
||
this.evmChangeEvent(); | ||
return 'SUCCESS'; | ||
} | ||
|
||
|
@@ -248,6 +248,17 @@ export class WalletService implements OnDestroy { | |
}); | ||
} | ||
|
||
evmChangeEvent() { | ||
const reconnect = () => { | ||
const timeoutId = setTimeout(() => { | ||
clearTimeout(timeoutId); | ||
this.connectToChain(); | ||
}, 1000); | ||
}; | ||
(window as any).ethereum?.on('accountsChanged', reconnect); | ||
(window as any).ethereum?.on('chainChanged', reconnect); | ||
} | ||
|
||
private async _getSigningCosmWasmClientAuto() { | ||
let _walletName = localStorage.getItem(STORAGE_KEY.CURRENT_WALLET); | ||
const chainWallet = this._walletManager.getMainWallet(_walletName); | ||
|
@@ -340,7 +351,7 @@ export class WalletService implements OnDestroy { | |
} | ||
|
||
getCosmosAccountOnly() { | ||
return this.walletAccount; | ||
return this.walletAccount; | ||
} | ||
|
||
getEvmAccount() { | ||
|
@@ -411,10 +422,9 @@ export class WalletService implements OnDestroy { | |
} | ||
|
||
async connectEvmWallet() { | ||
const network = await checkNetwork(this.env.evmChainInfo.chainId); | ||
|
||
if (!network) { | ||
await addNetwork(this.env.evmChainInfo); | ||
const connected = await this.connectToChain(); | ||
if (!connected) { | ||
return; | ||
Comment on lines
+425
to
+427
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. Ensure proper error handling when the connection fails in Consider adding a user-friendly error message or logging when the connection fails. |
||
} | ||
|
||
getSigner(this.env.etherJsonRpc).then((signer) => { | ||
|
@@ -433,6 +443,32 @@ export class WalletService implements OnDestroy { | |
}); | ||
} | ||
|
||
async connectToChain() { | ||
const metamask = getMetamask(); | ||
const chainId = '0x' + this.env.evmChainInfo.chainId.toString(16); | ||
try { | ||
await metamask.request({ | ||
method: 'wallet_switchEthereumChain', | ||
params: [{ chainId: chainId }], | ||
}); | ||
} catch (switchError: any) { | ||
switch (switchError.code) { | ||
case 4902: | ||
// This error code indicates that the chain has not been added to MetaMask. | ||
await addNetwork(this.env.evmChainInfo); | ||
break; | ||
case 4001: | ||
// This error code : "User rejected the request." | ||
return false; | ||
case -32002: | ||
// This error code : "Request of type 'wallet_switchEthereumChain' already pending" | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
parseAddress(address: string) { | ||
return transferAddress(this.env.chainInfo.bech32Config.bech32PrefixAccAddr, address); | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,8 +4,13 @@ export function validateAndParsingInput(type: JsonFragmentType, value: any) { | |||||||||||||||||
switch (type.type) { | ||||||||||||||||||
case 'uint256': | ||||||||||||||||||
case 'bytes4': | ||||||||||||||||||
return value; | ||||||||||||||||||
return { value }; | ||||||||||||||||||
case 'bool': | ||||||||||||||||||
if (value?.toLowerCase() !== 'true' && value?.toLowerCase() !== 'false') { | ||||||||||||||||||
return { value, error: `"${value}" is an invalid parameter, please use true/false.` }; | ||||||||||||||||||
} | ||||||||||||||||||
return { value: value?.toLowerCase() === 'true' ? true : false }; | ||||||||||||||||||
Comment on lines
+9
to
+12
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. Great improvement in type safety for boolean values. However, consider simplifying the return statement. - return { value: value?.toLowerCase() === 'true' ? true : false };
+ return { value: value?.toLowerCase() === 'true' }; This change removes the unnecessary ternary operation, making the code cleaner and more efficient. Committable suggestion
Suggested change
ToolsBiome
|
||||||||||||||||||
default: | ||||||||||||||||||
return value; | ||||||||||||||||||
return { value }; | ||||||||||||||||||
} | ||||||||||||||||||
} |
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.
Optimize the event handling in
evmChangeEvent
to avoid potential memory leaks.Consider removing the event listener when it's no longer needed to prevent memory leaks.