Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/npm_and_yarn/es5-ext-0.10.63
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuditi authored Feb 29, 2024
2 parents 29d0b23 + 0952d3e commit 1f6ae55
Show file tree
Hide file tree
Showing 72 changed files with 1,110 additions and 498 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { handleError } from '@core/error/handlers'
import { IConnectedDapp } from '@auxiliary/wallet-connect/interface'
import { CallbackParameters } from '@auxiliary/wallet-connect/types'
import { signAndSendTransactionFromEvm } from '@core/wallet/actions'
import { sendAndPersistTransactionFromEvm, signEvmTransaction } from '@core/wallet/actions'
import { selectedAccount } from '@core/account/stores'
import { ExplorerEndpoint, IChain, getDefaultExplorerUrl } from '@core/network'
import { DappInfo, TransactionAssetSection } from '@ui'
Expand All @@ -13,6 +13,7 @@
import {
calculateEstimatedGasFeeFromTransactionData,
calculateMaxGasFeeFromTransactionData,
getHexEncodedTransaction,
getMethodNameForEvmTransaction,
} from '@core/layer-2'
import { getTokenFromSelectedAccountTokens } from '@core/token/stores'
Expand All @@ -28,17 +29,23 @@
import { BASE_TOKEN_ID } from '@core/token/constants'
import { checkActiveProfileAuthAsync } from '@core/profile/actions'
import { LedgerAppName } from '@core/ledger'
import { DappVerification } from '@auxiliary/wallet-connect/enums'
import { DappVerification, RpcMethod } from '@auxiliary/wallet-connect/enums'
import { LegacyTransaction } from '@ethereumjs/tx'
export let preparedTransaction: EvmTransactionData
export let chain: IChain
export let dapp: IConnectedDapp
export let signAndSend: boolean
export let verifiedState: DappVerification
export let method: RpcMethod.EthSendTransaction | RpcMethod.EthSignTransaction | RpcMethod.EthSendRawTransaction
export let callback: (params: CallbackParameters) => void
const { id } = chain.getConfiguration()
$: localeKey = signAndSend ? (isSmartContractCall ? 'smartContractCall' : 'sendTransaction') : 'signTransaction'
$: localeKey =
method === RpcMethod.EthSignTransaction
? 'signTransaction'
: isSmartContractCall
? 'smartContractCall'
: 'sendTransaction'
let nft: Nft | undefined
let tokenTransfer: TokenTransferData | undefined
Expand Down Expand Up @@ -79,6 +86,30 @@
}
}
async function getSignedTransaction(): Promise<string> {
if (preparedTransaction?.v && preparedTransaction?.s && preparedTransaction?.r) {
const transaction = LegacyTransaction.fromTxData(preparedTransaction)
return getHexEncodedTransaction(transaction)
} else {
return await signEvmTransaction(preparedTransaction, chain, $selectedAccount)
}
}
async function signOrSend(): Promise<void> {
const signedTransaction = await getSignedTransaction()
if (method === RpcMethod.EthSignTransaction) {
callback({ result: signedTransaction })
return
}
const transactionHash = await sendAndPersistTransactionFromEvm(
preparedTransaction,
signedTransaction,
chain,
$selectedAccount
)
callback({ result: transactionHash })
}
async function onConfirmClick(): Promise<void> {
try {
await checkActiveProfileAuthAsync(LedgerAppName.Ethereum)
Expand All @@ -89,15 +120,11 @@
try {
busy = true
modifyPopupState({ preventClose: true })
const response = await signAndSendTransactionFromEvm(
preparedTransaction,
chain,
$selectedAccount,
signAndSend
)
await signOrSend()
modifyPopupState({ preventClose: false }, true)
busy = false
callback({ result: response })
openPopup({
id: PopupId.SuccessfulDappInteraction,
props: {
Expand All @@ -112,7 +139,7 @@
}
}
$: setMethodName(preparedTransaction)
$: void setMethodName(preparedTransaction)
async function setMethodName(preparedTransaction: EvmTransactionData): Promise<void> {
const result = await getMethodNameForEvmTransaction(preparedTransaction)
methodName = result?.startsWith('0x') ? undefined : result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { DEFAULT_ACCOUNT_RECOVERY_CONFIGURATION } from '@core/profile'
import { RecoverAccountsPayload, recoverAccounts } from '@core/profile-manager'
import { checkActiveProfileAuth, getBaseToken, loadAccounts } from '@core/profile/actions'
import { activeAccounts, activeProfile, visibleActiveAccounts } from '@core/profile/stores'
import { activeAccounts, activeProfile, activeProfileId, visibleActiveAccounts } from '@core/profile/stores'
import { formatTokenAmountBestMatch } from '@core/token'
import { refreshAccountTokensForActiveProfile } from '@core/token/actions'
import { closePopup } from '@desktop/auxiliary/popup'
Expand Down Expand Up @@ -141,7 +141,7 @@
onDestroy(async () => {
if (hasUsedWalletFinder) {
await refreshAccountTokensForActiveProfile()
await generateAndStoreActivitiesForAllAccounts()
await generateAndStoreActivitiesForAllAccounts($activeProfileId)
loadNftsForActiveProfile()
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { localize } from '@core/i18n'
import { SupportedNamespaces } from '@auxiliary/wallet-connect/types'
import { NetworkId, getChainConfiguration } from '@core/network'
import { SelectionOption } from '@core/utils/interfaces'
export let checkedNetworks: string[]
export let requiredNamespaces: ProposalTypes.RequiredNamespaces
Expand All @@ -14,9 +15,10 @@
const localeKey = 'views.dashboard.drawers.dapps.confirmConnection.networks'
let networkSelections: { label: string; value: string; checked: boolean; required: boolean }[] = []
let requiredNetworks: SelectionOption[] = []
let optionalNetworks: SelectionOption[] = []
function setNetworkSelections(): void {
const networks = {}
const networks: Record<string, SelectionOption> = {}
for (const namespace of Object.values(requiredNamespaces)) {
for (const chain of namespace.chains) {
const chainName = getChainConfiguration(chain as NetworkId)?.name ?? chain
Expand All @@ -34,18 +36,32 @@
}
}
}
networkSelections = Object.values(networks)
requiredNetworks = Object.values(networks).filter((network) => network.required)
optionalNetworks = Object.values(networks).filter((network) => !network.required)
}
$: checkedNetworks = networkSelections.filter((selection) => selection.checked).map((selection) => selection.value)
$: checkedNetworks = [...requiredNetworks, ...optionalNetworks]
.filter((selection) => selection.checked)
.map((selection) => selection.value)
onMount(() => {
setNetworkSelections()
})
</script>

<Selection
bind:selectionOptions={networkSelections}
title={localize(`${localeKey}.title`)}
error={checkedNetworks.length ? undefined : localize(`${localeKey}.empty`)}
/>
<div class="h-full flex flex-col gap-8">
{#if requiredNetworks.length}
<Selection
bind:selectionOptions={requiredNetworks}
disableSelectAll
title={localize(`${localeKey}.requiredTitle`)}
/>
{/if}
{#if optionalNetworks.length}
<Selection
bind:selectionOptions={optionalNetworks}
title={localize(`${localeKey}.optionalTitle`)}
error={checkedNetworks.length ? undefined : localize(`${localeKey}.empty`)}
/>
{/if}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
import { SupportedNamespaces } from '@auxiliary/wallet-connect/types'
import { Text } from '@bloomwalletio/ui'
import { getPermissionForMethod } from '@auxiliary/wallet-connect/utils'
import { RpcMethod } from '@auxiliary/wallet-connect/enums'
import { SelectionOption } from '@core/utils/interfaces'
export let checkedMethods: string[]
export let requiredNamespaces: ProposalTypes.RequiredNamespaces
export let optionalNamespaces: ProposalTypes.RequiredNamespaces
export let persistedNamespaces: SupportedNamespaces | undefined = undefined
export let permissionSelections: { label: string; value: string; checked: boolean; required: boolean }[] = []
const localeKey = 'views.dashboard.drawers.dapps.confirmConnection.permissions'
let requiredPermissions: SelectionOption[] = []
let optionalPermissions: SelectionOption[] = []
function setPermissionSelections(): void {
const permissions: { label: string; value: string; checked: boolean; required: boolean }[] = []
const checkedMethods: { [method: string]: boolean } = {}
const addedPermission: { [permission: string]: boolean } = {}
Expand All @@ -37,7 +38,7 @@
}
checkedMethods[method.method] = true
const permission = getPermissionForMethod(method.method)
const permission = getPermissionForMethod(method.method as RpcMethod)
if (!permission || addedPermission[permission]) {
continue
}
Expand All @@ -47,21 +48,24 @@
? Object.values(persistedNamespaces).some((namespace) => namespace.methods.includes(method.method))
: true
permissions.push({
const option = {
label: localize(`views.dashboard.drawers.dapps.confirmConnection.permissions.${String(permission)}`),
value: permission,
checked: isChecked,
required: method.required,
})
}
if (method.required) {
requiredPermissions = [...requiredPermissions, option]
} else {
optionalPermissions = [...optionalPermissions, option]
}
}
permissionSelections = permissions
}
$: permissionSelections, (checkedMethods = getMethodsFromCheckedPermissions())
$: requiredPermissions, optionalPermissions, (checkedMethods = getMethodsFromCheckedPermissions())
function getMethodsFromCheckedPermissions(): string[] {
return permissionSelections
return [...requiredPermissions, ...optionalPermissions]
.filter((selection) => selection.checked)
.flatMap((selection) => METHODS_FOR_PERMISSION[selection.value])
}
Expand All @@ -71,12 +75,23 @@
})
</script>

{#if permissionSelections.length}
<Selection
bind:selectionOptions={permissionSelections}
title={localize(`${localeKey}.title`)}
error={checkedMethods.length ? undefined : localize(`${localeKey}.empty`)}
/>
{#if requiredPermissions.length || optionalPermissions.length}
<div class="h-full flex flex-col gap-8">
{#if requiredPermissions.length}
<Selection
bind:selectionOptions={requiredPermissions}
disableSelectAll
title={localize(`${localeKey}.requiredTitle`)}
/>
{/if}
{#if optionalPermissions.length}
<Selection
bind:selectionOptions={optionalPermissions}
title={localize(`${localeKey}.optionalTitle`)}
error={checkedMethods.length ? undefined : localize(`${localeKey}.empty`)}
/>
{/if}
</div>
{:else}
<selection-component class="h-full flex flex-col gap-4">
<Text textColor="secondary">{localize(`${localeKey}.title`)}</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}[]
export let showPrimary: boolean = false
export let title: string
export let disableSelectAll: boolean = false
export let error: string | undefined = undefined
$: indexOfPrimary = selectionOptions.findIndex((option) => option.checked)
Expand All @@ -29,10 +30,12 @@
<selection-component class="flex flex-col gap-4">
<div class="flex flex-row justify-between items-center px-4">
<Text textColor="secondary">{title}</Text>
<div class="flex flex-row items-center gap-3">
<Text textColor="secondary">{localize('general.all')}</Text>
<Checkbox size="md" on:click={onAllClick} bind:checked={allChecked} />
</div>
{#if !disableSelectAll}
<div class="flex flex-row items-center gap-3">
<Text textColor="secondary">{localize('general.all')}</Text>
<Checkbox size="md" on:click={onAllClick} bind:checked={allChecked} />
</div>
{/if}
</div>
<selection-options>
{#each selectionOptions as option, index}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
localize(`${localeKey}.accounts.step`),
]
let permissionSelections: { label: string; value: string; checked: boolean; required: boolean }[] = []
let checkedAccounts: IAccountState[] = []
let checkedNetworks: string[] = []
let checkedMethods: string[] = []
Expand All @@ -48,7 +47,7 @@
$: isButtonDisabled =
loading ||
(!persistedNamespaces && currentStep === 0 && permissionSelections.length && checkedMethods.length === 0) ||
(!persistedNamespaces && currentStep === 0 && checkedMethods.length === 0) ||
(currentStep === 1 && checkedNetworks.length === 0) ||
(currentStep === 2 && checkedAccounts.length === 0)
Expand Down Expand Up @@ -129,7 +128,6 @@
<div class="flex-grow {currentStep === 0 ? 'visible' : 'hidden'}">
<PermissionSelection
bind:checkedMethods
bind:permissionSelections
requiredNamespaces={$sessionProposal.params.requiredNamespaces}
optionalNamespaces={$sessionProposal.params.optionalNamespaces}
/>
Expand Down
Loading

0 comments on commit 1f6ae55

Please sign in to comment.