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

CU-86a5nhxr1-NEON3 - Implement Direct Support to BNB chain (Moralis) #245

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/bsAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function exposeBsAggregatorToRenderer() {
new BSNeoLegacy('neoLegacy'),
new BSEthereum('ethereum', undefined, getHardwareWalletTransport),
new BSEthereum('neox', undefined, getHardwareWalletTransport),
new BSEthereum('bnb', undefined, getHardwareWalletTransport),
])

exposeApiToRenderer(bsAggregator)
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/src/assets/blockchain/images/bnb_blue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/renderer/src/assets/blockchain/images/bnb_gray.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/renderer/src/assets/blockchain/images/bnb_green.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/renderer/src/assets/blockchain/images/bnb_white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/renderer/src/constants/blockchain.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { ReactComponent as BnbBlue } from '@renderer/assets/blockchain/images/bnb_blue.svg'
import { ReactComponent as BnbGray } from '@renderer/assets/blockchain/images/bnb_gray.svg'
import { ReactComponent as BnbGreen } from '@renderer/assets/blockchain/images/bnb_green.svg'
import { ReactComponent as BnbWhite } from '@renderer/assets/blockchain/images/bnb_white.svg'
import { ReactComponent as EthereumBlue } from '@renderer/assets/blockchain/images/ethereum_blue.svg'
import { ReactComponent as EthereumGray } from '@renderer/assets/blockchain/images/ethereum_gray.svg'
import { ReactComponent as EthereumGreen } from '@renderer/assets/blockchain/images/ethereum_green.svg'
Expand Down Expand Up @@ -44,4 +48,10 @@ export const blockchainIconsByBlockchain: Record<
blue: NeoxBlue,
green: NeoxGreen,
},
bnb: {
gray: BnbGray,
white: BnbWhite,
blue: BnbBlue,
green: BnbGreen,
},
}
21 changes: 14 additions & 7 deletions src/renderer/src/constants/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { TBlockchainServiceKey, TNetwork } from '@shared/@types/blockchain'

const { t } = getI18next()

const BNB_NETWORK_IDS = ['56']
const BNB_NETWORKS = BSEthereumConstants.ALL_NETWORKS.filter(({ id }) => BNB_NETWORK_IDS.includes(id))

const isEthereumNetworkId = (id: string) => ![...BSEthereumConstants.NEOX_NETWORK_IDS, ...BNB_NETWORK_IDS].includes(id)

export const NETWORK_OPTIONS_BY_BLOCKCHAIN: Record<
TBlockchainServiceKey,
{
Expand All @@ -25,26 +30,28 @@ export const NETWORK_OPTIONS_BY_BLOCKCHAIN: Record<
testnet: BSNeoLegacyConstants.TESTNET_NETWORKS,
},
ethereum: {
all: BSEthereumConstants.ALL_NETWORKS.filter(({ id }) => !BSEthereumConstants.NEOX_NETWORK_IDS.includes(id)),
mainnet: BSEthereumConstants.MAINNET_NETWORKS.filter(
({ id }) => !BSEthereumConstants.NEOX_NETWORK_IDS.includes(id)
),
testnet: BSEthereumConstants.TESTNET_NETWORKS.filter(
({ id }) => !BSEthereumConstants.NEOX_NETWORK_IDS.includes(id)
),
all: BSEthereumConstants.ALL_NETWORKS.filter(({ id }) => isEthereumNetworkId(id)),
mainnet: BSEthereumConstants.MAINNET_NETWORKS.filter(({ id }) => isEthereumNetworkId(id)),
testnet: BSEthereumConstants.TESTNET_NETWORKS.filter(({ id }) => isEthereumNetworkId(id)),
},
neox: {
all: BSEthereumConstants.NEOX_NETWORKS,
mainnet: [BSEthereumConstants.NEOX_MAINNET_NETWORK],
testnet: [BSEthereumConstants.NEOX_TESTNET_NETWORK],
},
bnb: {
all: BNB_NETWORKS,
mainnet: [BNB_NETWORKS[0]],
testnet: [],
},
}

export const DEFAULT_NETWORK_BY__BLOCKCHAIN: Record<TBlockchainServiceKey, TNetwork<TBlockchainServiceKey>> = {
neo3: NETWORK_OPTIONS_BY_BLOCKCHAIN.neo3.mainnet[0],
neoLegacy: NETWORK_OPTIONS_BY_BLOCKCHAIN.neoLegacy.mainnet[0],
ethereum: NETWORK_OPTIONS_BY_BLOCKCHAIN.ethereum.mainnet[0],
neox: NETWORK_OPTIONS_BY_BLOCKCHAIN.neox.mainnet[0],
bnb: NETWORK_OPTIONS_BY_BLOCKCHAIN.bnb.mainnet[0],
}

export const DEFAULT_NETWORK_PROFILE = {
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/src/constants/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export const SWAP_NETWORK_BY_BLOCKCHAIN_AND_NETWORK_ID: {
neox: {
'47763': [''],
},
bnb: {
'56': ['bnb', 'bsc'],
},
}

export const SWAP_DISCORD_LINK = 'https://discord.gg/zW26BZC5ku'
4 changes: 4 additions & 0 deletions src/renderer/src/helpers/NetworkHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ export class NetworkHelper {

return 'bg-pink'
}

static isBlockchainBasedOnEthereum<T extends TBlockchainServiceKey>(blockchain: T) {
return ['ethereum', 'neox', 'bnb'].includes(blockchain)
}
}
10 changes: 5 additions & 5 deletions src/renderer/src/helpers/WalletConnectHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ export abstract class WalletConnectHelper {
neo3: 'neo3',
ethereum: 'eip155',
neox: 'eip155',
bnb: 'eip155',
}

static supportedChainIds = Object.keys(this.supportedBlockchains as TBlockchainServiceKey[]).reduce(
(acc, key) => {
const networks = NETWORK_OPTIONS_BY_BLOCKCHAIN[key].all
const chainIds = networks.map(({ id }) => `${this.supportedBlockchains[key]}:${id}`)
acc[key] = chainIds

acc[key] = networks.map(({ id }) => `${this.supportedBlockchains[key]}:${id}`)

return acc
},
{} as Partial<Record<TBlockchainServiceKey, string[]>>
Expand Down Expand Up @@ -56,7 +58,7 @@ export abstract class WalletConnectHelper {
static getInformationFromProposal(proposal: TSessionProposal): TWalletConnectHelperProposalInformation[] {
const combinedNamespaces = merge({}, proposal.params.requiredNamespaces, proposal.params.optionalNamespaces)

const proposalInformation = Object.values(combinedNamespaces).map((namespace: any) => {
return Object.values(combinedNamespaces).map((namespace: any) => {
const chains = namespace.chains
if (!chains) throw new Error('Chains not found')

Expand Down Expand Up @@ -89,8 +91,6 @@ export abstract class WalletConnectHelper {
proposalBlockchain,
}
})

return proposalInformation
}

static isValidURI(uri: string) {
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"neo3": "Neo N3",
"neoLegacy": "Neo Legacy",
"ethereum": "Ethereum",
"neox": "NeoX"
"neox": "NeoX",
"bnb": "BNB"
},
"networkTypeLabel": {
"mainnet": "MainNet",
Expand All @@ -44,4 +45,4 @@
"ledger": {
"requestingPermission": "Please confirm on your Ledger device"
}
}
}
11 changes: 11 additions & 0 deletions src/renderer/src/routes/modals/DappPermission/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ const componentsByBlockchain: Partial<
eth_call: EthereumSendTransactionDappPermission,
eth_sendRawTransaction: EthereumSendTransactionDappPermission,
},
bnb: {
personal_sign: EthereumSignMessageDappPermission,
eth_sign: EthereumSignMessageDappPermission,
eth_signTransaction: EthereumSignTransactionDappPermission,
eth_signTypedData: EthereumSignTypedDataDappPermission,
eth_signTypedData_v3: EthereumSignTypedDataDappPermission,
eth_signTypedData_v4: EthereumSignTypedDataDappPermission,
eth_sendTransaction: EthereumSendTransactionDappPermission,
eth_call: EthereumSendTransactionDappPermission,
eth_sendRawTransaction: EthereumSendTransactionDappPermission,
},
}

export const DappPermissionModal = () => {
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/routes/pages/Send/SendPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Button } from '@renderer/components/Button'
import { GreyAccountSelect } from '@renderer/components/GreyAccountSelect'
import { Separator } from '@renderer/components/Separator'
import { TransactionFeeActionStep } from '@renderer/components/TransactionFeeActionStep'
import { NetworkHelper } from '@renderer/helpers/NetworkHelper'
import { NumberHelper } from '@renderer/helpers/NumberHelper'
import { ToastHelper } from '@renderer/helpers/ToastHelper'
import { UtilsHelper } from '@renderer/helpers/UtilsHelper'
Expand Down Expand Up @@ -342,7 +343,7 @@ export const SendPageContent = ({ account, recipientAddress }: TProps) => {
/>

{actionData.selectedAccount &&
(actionData.selectedAccount.blockchain === 'neox' || actionData.selectedAccount.blockchain === 'ethereum') &&
NetworkHelper.isBlockchainBasedOnEthereum(actionData.selectedAccount.blockchain) &&
actionData.recipients.length > 1 && (
<Banner
type="warning"
Expand Down
31 changes: 30 additions & 1 deletion src/renderer/src/store/reducers/SettingsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,40 @@ const settingsReducerMigrations = {
},
_persist,
}),
1: (state: any) => ({
...state,
data: {
...state.data,
customNetworks: {
...state.data.customNetworks,
bnb: [],
},
selectedNetworkByBlockchain: {
...state.data.selectedNetworkByBlockchain,
bnb: DEFAULT_NETWORK_BY__BLOCKCHAIN.bnb,
},
networkProfiles: state.data.networkProfiles.map(profile => ({
...profile,
networkByBlockchain: {
...profile.networkByBlockchain,
bnb: DEFAULT_NETWORK_BY__BLOCKCHAIN.bnb,
},
})),
selectedNetworkProfile: {
...state.data.selectedNetworkProfile,
networkByBlockchain: {
...state.data.selectedNetworkProfile.networkByBlockchain,
bnb: DEFAULT_NETWORK_BY__BLOCKCHAIN.bnb,
},
},
},
}),
}

export const settingsReducerConfig: PersistConfig<ISettingsReducer> = {
key: 'settingsReducer',
storage: storage,
version: 0,
version: 1,
migrate: createMigrate(settingsReducerMigrations),
}

Expand All @@ -40,6 +68,7 @@ const initialState: ISettingsReducer = {
neo3: [],
neoLegacy: [],
neox: [],
bnb: [],
},
selectedNetworkByBlockchain: DEFAULT_NETWORK_BY__BLOCKCHAIN,
networkProfiles: [DEFAULT_NETWORK_PROFILE],
Expand Down
3 changes: 2 additions & 1 deletion src/shared/@types/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BSNeo3NetworkId } from '@cityofzion/bs-neo3'

import { IAccountState, IContactState, IWalletState, TAccountType, TSkin, TSwapRecord, TWalletType } from './store'

export type TBlockchainServiceKey = 'neo3' | 'neoLegacy' | 'ethereum' | 'neox'
export type TBlockchainServiceKey = 'neo3' | 'neoLegacy' | 'ethereum' | 'neox' | 'bnb'
export type TBlockchainImageColor = 'white' | 'gray' | 'blue' | 'green'

export type TAccountToImport = {
Expand Down Expand Up @@ -46,6 +46,7 @@ type TNetworkIdsByBlockchain = {
neoLegacy: BSNeoLegacyNetworkId
ethereum: BSEthereumNetworkId
neox: BSEthereumNetworkId
bnb: BSEthereumNetworkId
}

export type TNetworkIds<K extends TBlockchainServiceKey> = TNetworkIdsByBlockchain[K]
Expand Down
1 change: 1 addition & 0 deletions src/shared/@types/i18next-resources.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface Resources {
neoLegacy: 'Neo Legacy'
ethereum: 'Ethereum'
neox: 'NeoX'
bnb: 'BNB'
}
networkTypeLabel: {
mainnet: 'MainNet'
Expand Down