Skip to content

Commit

Permalink
Merge commit '44fb8afcc64925c57f85ecd797a88d91e90b75fd' into refactor…
Browse files Browse the repository at this point in the history
…/parse-evm-transaction-data
  • Loading branch information
MarkNerdi committed May 14, 2024
2 parents 67dc9a5 + 44fb8af commit acb1aa2
Show file tree
Hide file tree
Showing 55 changed files with 353 additions and 367 deletions.
2 changes: 1 addition & 1 deletion packages/desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The following **must** be installed on all platforms:

- [Node.js](https://nodejs.org/en/) 18.15.0+
- [Node.js](https://nodejs.org/en/) 20.10.0+
- [Yarn](https://classic.yarnpkg.com/en/docs/install)
- [Rust](https://www.rust-lang.org/tools/install)

Expand Down
12 changes: 6 additions & 6 deletions packages/desktop/components/ContactAddressCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import { IContact, IContactAddress, IContactAddressMap, setSelectedContactNetworkAddress } from '@core/contact'
import { localize } from '@core/i18n'
import { resetLedgerPreparedOutput, resetShowInternalVerificationPopup } from '@core/ledger'
import { ExplorerEndpoint, getDefaultExplorerUrl, getNameFromNetworkId, NetworkId } from '@core/network'
import { ExplorerEndpoint, getExplorerUrl, getNameFromNetworkId, getNetwork, NetworkId } from '@core/network'
import { Router } from '@core/router'
import { buildUrl, truncateString } from '@core/utils'
import { truncateString } from '@core/utils'
import { SendFlowType, setSendFlowParameters, SubjectType } from '@core/wallet'
import { closeDrawer } from '@desktop/auxiliary/drawer'
import { openPopup, PopupId } from '@desktop/auxiliary/popup'
Expand All @@ -21,11 +21,11 @@
export let contact: IContact
export let contactAddressMap: IContactAddressMap
const explorer = getDefaultExplorerUrl(networkId, ExplorerEndpoint.Address)
const hasExplorer = !!getNetwork(networkId)?.explorerUrl
function onExplorerClick(address: string): void {
const url = buildUrl({ origin: explorer.baseUrl, pathname: `${explorer.endpoint}/${address}` })
openUrlInBrowser(url?.href)
const url = getExplorerUrl(networkId, ExplorerEndpoint.Address, address)
openUrlInBrowser(url)
}
function onQrCodeClick(contactAddress: IContactAddress): void {
Expand Down Expand Up @@ -72,7 +72,7 @@
</Copyable>
</div>
<div class="flex flex-row space-x-1">
{#if explorer.baseUrl}
{#if hasExplorer}
<IconButton
size="sm"
icon={IconName.Globe}
Expand Down
13 changes: 6 additions & 7 deletions packages/desktop/components/NetworkCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,29 @@
ExplorerEndpoint,
Network,
NetworkNamespace,
getDefaultExplorerUrl,
getExplorerUrl,
setSelectedNetworkForNetworkDrawer,
} from '@core/network'
import { ProfileType } from '@core/profile'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { activeProfile } from '@core/profile/stores'
import { buildUrl, truncateString } from '@core/utils'
import { truncateString } from '@core/utils'
import { NetworkAvatar, NetworkStatusPill } from '@ui'
import { NetworkConfigRoute, networkConfigRouter } from '@views/dashboard/drawers'
export let network: Network
let address: string | undefined
const explorer = getDefaultExplorerUrl(network.id, ExplorerEndpoint.Address)
$: health = network.health
$: address = getAddressFromAccountForNetwork($selectedAccount as IAccountState, network.id)
function onExplorerClick(): void {
if (!explorer || !address) {
if (!address) {
return
}
const url = buildUrl({ origin: explorer.baseUrl, pathname: `${explorer.endpoint}/${address}` })
openUrlInBrowser(url?.href)
const url = getExplorerUrl(network.id, ExplorerEndpoint.Address, address)
openUrlInBrowser(url)
}
function onCardClick(): void {
Expand Down Expand Up @@ -107,7 +106,7 @@
{/if}
</div>
<div class="flex flex-row space-x-1">
{#if explorer?.baseUrl && address}
{#if network.explorerUrl && address}
<IconButton
size="sm"
icon={IconName.Globe}
Expand Down
15 changes: 4 additions & 11 deletions packages/desktop/components/modals/FilterModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,21 @@
bind:this={modal}
on:close={closeFilters}
position={{ absolute: true, right: '0', top: '30px' }}
classes="overflow-visible"
classes="flex !overflow-hidden"
autoMaxHeight
>
<filter-modal>
<filter-modal class="flex flex-col w-64 rounded-[inherit]">
<filter-modal-header
class="flex flex-row items-center justify-between bg-surface-1 dark:bg-transparent px-4 py-2 rounded-t-xl"
class="flex-none flex flex-row items-center justify-between bg-surface-1 dark:bg-transparent px-4 py-2 rounded-t-xl"
>
<Button text={localize('actions.clear')} on:click={onClearClick} size="xs" variant="outlined" />
<Text align="center">
{localize('filters.title')}
</Text>
<Button text={localize('actions.apply')} on:click={onConfirmClick} size="xs" disabled={!isChanged} />
</filter-modal-header>
<filter-modal-slot class="block">
<filter-modal-slot class="flex-1 h-0 overflow-y-scroll">
<slot />
</filter-modal-slot>
</filter-modal>
</Modal>

<style lang="scss">
filter-modal {
@apply block w-64;
border-radius: inherit;
}
</style>
1 change: 1 addition & 0 deletions packages/desktop/components/popup/Popup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
bind:this={popupContent}
class:relative
class="popup {size}"
class:-mt-7={IS_WINDOWS}
>
<svelte:component this={POPUP_MAP[id]} {...props} />
{#if !hideClose}
Expand Down
37 changes: 15 additions & 22 deletions packages/desktop/components/popup/PopupTemplate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
</script>

<popup-template>
<div class="popup-banner">
<div class="popup-banner overflow-hidden rounded-t-[32px]">
<slot name="banner" />
</div>
<popop-content class="flex flex-col gap-6 p-8 {$$slots.banner ? 'pt-4' : ''}">
<popup-content class="max-h-[90vh] flex flex-col gap-6 p-8" class:pt-4={$$slots.banner}>
{#if title || $$slots.menu || $$slots.description || description}
<popup-header class="flex flex-col space-y-2.5">
<title-row class="flex flex-row space-x-2 justify-between">
<popup-header class="flex-none flex flex-col gap-2.5">
<title-row class="flex flex-row gap-2 mr-7 justify-between">
{#if title}<Text type="h6" truncate>{title}</Text>{/if}
{#if $$slots.menu}
<slot name="menu" class="flex-0" />
Expand All @@ -76,13 +76,15 @@
{/if}
</popup-header>
{/if}
{#if $$slots.default}
<slot />
{:else if $$slots.content}
<slot name="content" />
{/if}
<div class="flex-1 h-0 flex flex-col">
{#if $$slots.default}
<slot />
{:else if $$slots.content}
<slot name="content" />
{/if}
</div>
{#if backButton || continueButton}
<popup-footer class="flex flex-row space-x-3">
<popup-footer class="flex-none flex flex-row gap-3">
{#if backButton}
<Button
type="button"
Expand All @@ -91,7 +93,7 @@
disabled={busy || _backButton.disabled}
width="full"
form={_backButton.type === 'submit' ? _backButton.form : undefined}
on:click={_backButton.type === 'button' && _backButton.onClick}
on:click={_backButton.type === 'button' ? _backButton.onClick : undefined}
{..._backButton.restProps}
/>
{/if}
Expand All @@ -105,20 +107,11 @@
disabled={_continueButton.disabled}
{busy}
width="full"
on:click={_continueButton.type === 'button' && _continueButton.onClick}
on:click={_continueButton.type === 'button' ? _continueButton.onClick : undefined}
{..._continueButton.restProps}
/>
{/if}
</popup-footer>
{/if}
</popop-content>
</popup-content>
</popup-template>

<style lang="postcss">
.popup-banner {
@apply overflow-hidden rounded-t-[32px];
}
title-row {
margin-right: 28px;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import { openUrlInBrowser } from '@core/app'
import { localize } from '@core/i18n'
import { ExplorerEndpoint } from '@core/network'
import { getDefaultExplorerUrl } from '@core/network/utils'
import { getExplorerUrl } from '@core/network/utils'
import { NftStandard } from '@core/nfts'
import { Nft } from '@core/nfts/interfaces'
import { ownedNfts, selectedNftId, getNftByIdForAccount } from '@core/nfts/stores'
import { CollectiblesRoute, DashboardRoute, collectiblesRouter, dashboardRouter } from '@core/router'
import { getTokenFromSelectedAccountTokens } from '@core/token/stores'
import { buildUrl, setClipboard, truncateString } from '@core/utils'
import { setClipboard, truncateString } from '@core/utils'
import { TokenTransferData } from '@core/wallet/types'
import { closePopup } from '@desktop/auxiliary/popup'
import { EvmActivityInformation, TransactionAssetSection } from '@ui'
Expand All @@ -31,10 +31,12 @@
}
}
$: explorerUrl = getExplorerUrl(activity)
function getExplorerUrl(_activity: EvmActivity): string | undefined {
const { baseUrl, endpoint } = getDefaultExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Transaction)
return buildUrl({ origin: baseUrl, pathname: `${endpoint}/${_activity?.transactionId}` })?.href
$: explorerUrl = buildExplorerUrl(activity)
function buildExplorerUrl(_activity: EvmActivity): string | undefined {
if (_activity.type === EvmActivityType.BalanceChange) {
return
}
return getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Transaction, _activity?.transactionId)
}
$: nft = getNft(activity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import { CallbackParameters } from '@auxiliary/wallet-connect/types'
import { sendAndPersistTransactionFromEvm, signEvmTransaction } from '@core/wallet/actions'
import { getSelectedAccount, selectedAccount } from '@core/account/stores'
import { ExplorerEndpoint, IEvmNetwork, getDefaultExplorerUrl } from '@core/network'
import { ExplorerEndpoint, IEvmNetwork, getExplorerUrl } from '@core/network'
import { DappInfo, TransactionAssetSection } from '@ui'
import PopupTemplate from '../PopupTemplate.svelte'
import { EvmTransactionData } from '@core/layer-2/types'
import { EvmTransactionDetails } from '@views/dashboard/send-flow/views/components'
import {
IParsedInput,
ParsedSmartContractType,
calculateEstimatedGasFeeFromTransactionData,
calculateMaxGasFeeFromTransactionData,
Expand All @@ -22,7 +23,7 @@
import { Nft } from '@core/nfts'
import { Alert, Link, Table, Text } from '@bloomwalletio/ui'
import { PopupId, closePopup, modifyPopupState, openPopup } from '@desktop/auxiliary/popup'
import { Converter, buildUrl, truncateString } from '@core/utils'
import { Converter, truncateString } from '@core/utils'
import { openUrlInBrowser } from '@core/app'
import { BASE_TOKEN_ID } from '@core/token/constants'
import { checkActiveProfileAuth } from '@core/profile/actions'
Expand Down Expand Up @@ -52,7 +53,7 @@
let baseCoinTransfer: TokenTransferData | undefined
let isSmartContractCall = false
let methodName: string | undefined = undefined
let parameters: Record<string, string> | undefined = undefined
let inputs: IParsedInput[] | undefined = undefined
let busy = false
setTransactionInformation()
Expand All @@ -75,7 +76,7 @@
)
methodName = parsedData?.parsedMethod?.name
parameters = parsedData?.parsedMethod?.inputs
inputs = parsedData?.parsedMethod?.inputs
switch (parsedData?.type) {
case ParsedSmartContractType.CoinTransfer: {
Expand Down Expand Up @@ -185,9 +186,8 @@
}
function onExplorerClick(contractAddress: string): void {
const { baseUrl, endpoint } = getDefaultExplorerUrl(evmNetwork.id, ExplorerEndpoint.Address)
const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${contractAddress}` })
openUrlInBrowser(url?.href)
const url = getExplorerUrl(evmNetwork.id, ExplorerEndpoint.Address, contractAddress)
openUrlInBrowser(url)
}
</script>

Expand Down Expand Up @@ -236,7 +236,7 @@
onClick: () => onExplorerClick(String(preparedTransaction.to)),
},
{ key: localize('general.methodName'), value: methodName },
{ key: localize('general.parameters'), value: parameters },
{ key: localize('general.parameters'), value: inputs },
{ key: localize('general.data'), value: String(preparedTransaction.data), copyable: true },
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
onMount(() => {
getNodeInfo(node?.url, node?.auth)
.then((nodeInfoResponse) => {
nodeInfo = nodeInfoResponse.nodeInfo
nodeInfo = nodeInfoResponse?.nodeInfo
})
.catch((err) => {
closePopup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import { openUrlInBrowser } from '@core/app'
import { localize } from '@core/i18n'
import { ExplorerEndpoint } from '@core/network'
import { getDefaultExplorerUrl } from '@core/network/utils'
import { getExplorerUrl } from '@core/network/utils'
import { getNftByIdForAccount, ownedNfts, selectedNftId } from '@core/nfts/stores'
import { CollectiblesRoute, DashboardRoute, collectiblesRouter, dashboardRouter } from '@core/router'
import { buildUrl, setClipboard, truncateString } from '@core/utils'
import { setClipboard, truncateString } from '@core/utils'
import { claimActivity, rejectActivity } from '@core/wallet'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
import { StardustActivityInformation, TransactionAssetSection } from '@ui'
Expand Down Expand Up @@ -45,16 +45,12 @@
}
}
$: explorerUrl = getExplorerUrl(activity)
function getExplorerUrl(_activity: StardustActivity): string | undefined {
$: explorerUrl = buildExplorerUrl(activity)
function buildExplorerUrl(_activity: StardustActivity): string | undefined {
if (activity?.direction === ActivityDirection.Genesis) {
const { baseUrl, endpoint } = getDefaultExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Output)
const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${_activity?.outputId}` })
return url?.href
return getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Output, _activity?.outputId)
} else {
const { baseUrl, endpoint } = getDefaultExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Transaction)
const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${_activity?.transactionId}` })
return url?.href
return getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Transaction, _activity?.transactionId)
}
}
Expand Down
21 changes: 13 additions & 8 deletions packages/desktop/lib/electron/apis/wallet.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,21 @@ const sdkUtilsMethods = bindSdkUtilsMethods()

export default {
...sdkUtilsMethods,
async getNodeInfo(managerId: number, url: string, auth: IAuth): Promise<INodeInfoResponse> {
const manager = profileManagers[managerId]
const client = await manager.getClient()
async getNodeInfo(managerId: number, url: string, auth: IAuth): Promise<INodeInfoResponse | undefined> {
try {
const manager = profileManagers[managerId]
const client = await manager.getClient()

const nodeUrl = url ?? (await client.getNode()).url
const nodeInfo = await client.getNodeInfo(nodeUrl, auth)
const nodeUrl = url ?? (await client.getNode()).url
const nodeInfo = await client.getNodeInfo(nodeUrl, auth)

return {
url: nodeUrl,
nodeInfo,
return {
url: nodeUrl,
nodeInfo,
}
} catch (err) {
console.error(err)
return undefined
}
},
createWallet(id: string, options: WalletOptions): Wallet {
Expand Down
8 changes: 2 additions & 6 deletions packages/desktop/lib/electron/processes/main.process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,8 @@ export function createMainWindow(): BrowserWindow {
/**
* Handle permissions requests
*/
session.defaultSession.setPermissionRequestHandler((_webContents, permission, cb, details) => {
if (permission === 'openExternal' && details && details.externalURL) {
return cb(true)
}

const permissionAllowlist = ['clipboard-read', 'notifications', 'fullscreen']
session.defaultSession.setPermissionRequestHandler((_webContents, permission, cb) => {
const permissionAllowlist = ['clipboard-read', 'notifications', 'fullscreen', 'openExternal']

return cb(permissionAllowlist.indexOf(permission) > -1)
})
Expand Down
Loading

0 comments on commit acb1aa2

Please sign in to comment.