Skip to content

Commit

Permalink
Merge pull request #10 from stratosnet/feat/QB-2293/evm-functionality
Browse files Browse the repository at this point in the history
feat/QB-2293: Project fixes:
  • Loading branch information
alexstratos authored Nov 13, 2023
2 parents 9db7d8d + f3950e5 commit 0261a3b
Show file tree
Hide file tree
Showing 14 changed files with 412 additions and 24 deletions.
13 changes: 12 additions & 1 deletion .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion apps/web-stratos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
},
"dependencies": {
"@apollo/client": "^3.7.14",
"@cosmjs/encoding": "^0.30.1",
"@cosmjs/encoding": "^0.31.0",
"@cosmjs/launchpad": "^0.27.1",
"@cosmjs/stargate": "^0.29.5",
"@emotion/react": "^11.11.0",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.11.0",
"@ethersproject/address": "^5.7.0",
"@keplr-wallet/types": "^0.11.59",
"@keplr-wallet/wc-client": "^0.11.59",
"@mui/icons-material": "^5.11.16",
Expand Down
108 changes: 103 additions & 5 deletions apps/web-stratos/src/chain.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,54 @@
},
"keplr": "{\"chainId\":\"desmos-mainnet\",\"chainName\":\"Desmos\",\"chainSymbolImageUrl\":\"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/desmos-mainnet/chain.png\",\"rpc\":\"https://rpc.mainnet.desmos.network\",\"rest\":\"https://api.mainnet.desmos.network\",\"nodeProvider\":{\"name\":\"Forbole\",\"email\":\"info@forbole.com\",\"website\":\"https://www.forbole.com\"},\"bip44\":{\"coinType\":852},\"bech32Config\":{\"bech32PrefixAccAddr\":\"desmos\",\"bech32PrefixAccPub\":\"desmospub\",\"bech32PrefixValAddr\":\"desmosvaloper\",\"bech32PrefixValPub\":\"desmosvaloperpub\",\"bech32PrefixConsAddr\":\"desmosvalcons\",\"bech32PrefixConsPub\":\"desmosvalconspub\"},\"currencies\":[{\"coinDenom\":\"DSM\",\"coinMinimalDenom\":\"udsm\",\"coinDecimals\":6,\"coinGeckoId\":\"desmos\"}],\"feeCurrencies\":[{\"coinDenom\":\"DSM\",\"coinMinimalDenom\":\"udsm\",\"coinDecimals\":6,\"coinGeckoId\":\"desmos\",\"gasPriceStep\":{\"low\":0.01,\"average\":0.03,\"high\":0.05}}],\"stakeCurrency\":{\"coinDenom\":\"DSM\",\"coinMinimalDenom\":\"udsm\",\"coinDecimals\":6,\"coinGeckoId\":\"desmos\"},\"features\":[]}",
"chains": [
{
"network": "testchain",
"chainType": "Localnet",
"genesis": {
"time": "2023-08-21T13:04:12Z",
"height": 1
},
"prefix": {
"consensus": "stvalcons",
"validator": "stvaloper",
"account": "st"
},
"primaryTokenUnit": "wei",
"votingPowerTokenUnit": "vp",
"tokenUnits": {
"wei": {
"display": "stos",
"exponent": 18
},
"gwei": {
"display": "stos",
"exponent": 9
},
"vp": {
"display": "VP",
"exponent": 15
}
},
"endpoints": {
"graphql": "http://localhost:8080/v1/graphql",
"graphqlWebsocket": "ws://localhost:8080/v1/graphql",
"publicRpcWebsocket": "ws://localhost:26657/websocket",
"rest": "http://localhost:1317"
},
"marketing": {
"matomoURL": "https://analytics.bigdipper.live",
"matomoSiteID": "8"
},
"externalExplorers": {
"blockscout": "http://localhost:4000"
},
"evm": {
"chainId": 2048
}
},
{
"network": "dev-0",
"chainType": "Testnet",
"chainType": "Devnet",
"genesis": {
"time": "2023-08-21T13:04:12Z",
"height": 1
Expand Down Expand Up @@ -243,19 +288,24 @@
"endpoints": {
"graphql": "https://hasura-dev.thestratos.org/v1/graphql",
"graphqlWebsocket": "wss://hasura-dev.thestratos.org/v1/graphql",
"publicRpcWebsocket": "wss://rpc-dev.thestratos.org/websocket"
"publicRpcWebsocket": "wss://rpc-dev.thestratos.org/websocket",
"rest": "https://rest-dev.thestratos.org"
},
"marketing": {
"matomoURL": "https://analytics.bigdipper.live",
"matomoSiteID": "8"
},
"externalExplorers": {},
"evm": {
"chainId": 2048
}
},
{
"network": "mesos-0",
"network": "mesos-1",
"chainType": "Testnet",
"genesis": {
"time": "2023-07-17T13:36:05Z",
"height": 0
"height": 1
},
"prefix": {
"consensus": "stvalcons",
Expand All @@ -277,11 +327,59 @@
"endpoints": {
"graphql": "https://hasura-mesos.thestratos.org/v1/graphql",
"graphqlWebsocket": "wss://hasura-mesos.thestratos.org/v1/graphql",
"publicRpcWebsocket": "wss://rpc-mesos.thestratos.org/websocket"
"publicRpcWebsocket": "wss://rpc-mesos.thestratos.org/websocket",
"rest": "https://rest-mesos.thestratos.org"
},
"marketing": {
"matomoURL": "https://analytics.bigdipper.live",
"matomoSiteID": "8"
},
"externalExplorers": {
"blockscout": "https://web3-explorer-mesos.thestratos.org"
},
"evm": {
"chainId": 2047
}
},
{
"network": "stratos-1",
"chainType": "Mainnet",
"genesis": {
"time": "2023-09-08T00:00:00Z",
"height": 1
},
"prefix": {
"consensus": "stvalcons",
"validator": "stvaloper",
"account": "st"
},
"primaryTokenUnit": "wei",
"votingPowerTokenUnit": "wei",
"tokenUnits": {
"wei": {
"display": "stos",
"exponent": 18
},
"gwei": {
"display": "stos",
"exponent": 9
}
},
"endpoints": {
"graphql": "https://hasura.thestratos.org/v1/graphql",
"graphqlWebsocket": "wss://hasura.thestratos.org/v1/graphql",
"publicRpcWebsocket": "wss://rpc.thestratos.org/websocket",
"rest": "https://rest.thestratos.org"
},
"marketing": {
"matomoURL": "https://analytics.bigdipper.live",
"matomoSiteID": "8"
},
"externalExplorers": {
"blockscout": "https://web3-explorer.thestratos.org"
},
"evm": {
"chainId": 2048
}
}
]
Expand Down
120 changes: 120 additions & 0 deletions apps/web-stratos/src/components/msg/evm/ethereum_tx/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import React from 'react';
import Typography from '@mui/material/Typography';
import chainConfig from '@/chainConfig';
import AppTrans from '@/components/AppTrans';

import { getContractAddress } from '@ethersproject/address';

import { MsgEthereumTx } from '@/models';
import { formatToken, formatNumber } from '@/utils/format_token';

const { externalExplorers } = chainConfig();

const getExternalExplorerLink = (explName: string, route: string, value: string): string => {
const url = externalExplorers?.[explName];
if (!url) return '#';
return `${url}/${route}/${value}`;
};

const ExtLink: React.FC<{
address: string;
name?: string;
explorer?: string;
}> = ({ address, name, explorer = 'blockscout' }) => {
const repr = name || address;

return (
<Typography
component="a"
target="_blank"
href={getExternalExplorerLink(explorer, 'address', address)}
rel="noopener noreferrer"
>
{repr}
</Typography>
);
};

const EthereumTx = (props: { message: MsgEthereumTx }) => {
const { message } = props;

const tx = message.asEthereumTx();

// big dipper staff for pretty
const amount = formatToken(tx.value?.toString(), 'wei');
const parsedAmount = `${formatNumber(
amount.value,
amount.exponent
)} ${amount.displayDenom.toUpperCase()}`;

const senderAddress = message.getSender();

if (tx.to !== null) {
// smart contract function execution
if (tx.data !== null) {
return (
<Typography>
<AppTrans
i18nKey="message_contents:txEvmExecuteContent"
components={[
<ExtLink
address={senderAddress}
name={MsgEthereumTx.getBech32Address(senderAddress)}
/>,
<b />,
<ExtLink address={tx.to} name={MsgEthereumTx.getBech32Address(tx.to)} />,
]}
values={{
amount: parsedAmount,
}}
/>
</Typography>
);
}
// transfer
return (
<Typography>
<AppTrans
i18nKey="message_contents:txEvmSendContent"
components={[
<ExtLink
address={senderAddress}
name={MsgEthereumTx.getBech32Address(senderAddress)}
/>,
<b />,
<ExtLink address={tx.to} name={MsgEthereumTx.getBech32Address(tx.to)} />,
]}
values={{
amount: parsedAmount,
}}
/>
</Typography>
);
}

const smartContractAddress = getContractAddress({
from: senderAddress,
nonce: tx.nonce,
});

return (
<Typography>
<AppTrans
i18nKey="message_contents:txEvmCreateContent"
components={[
<ExtLink address={senderAddress} name={MsgEthereumTx.getBech32Address(senderAddress)} />,
<b />,
<ExtLink
address={smartContractAddress}
name={MsgEthereumTx.getBech32Address(smartContractAddress)}
/>,
]}
values={{
amount: parsedAmount,
}}
/>
</Typography>
);
};

export default EthereumTx;
1 change: 1 addition & 0 deletions apps/web-stratos/src/components/msg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export { default as UpdateResourceNode } from '@/components/msg/register/update_
export { default as UpdateResourceNodeDeposit } from '@/components/msg/register/update_resource_node_deposit';
export { default as FileUpload } from '@/components/msg/sds/file_upload';
export { default as Prepay } from '@/components/msg/sds/prepay';
export { default as EthereumTx } from '@/components/msg/evm/ethereum_tx';
export * from 'ui/components/msg';
9 changes: 9 additions & 0 deletions apps/web-stratos/src/components/msg/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,15 @@ const customTypeToModel = {
tagTheme: 'three',
tagDisplay: 'txPrepayLabel',
},
// ========================
// evm
// ========================
'/stratos.evm.v1.MsgEthereumTx': {
model: MODELS.MsgEthereumTx,
content: COMPONENTS.EthereumTx,
tagTheme: 'evm',
tagDisplay: 'txEthereumTxLabel',
},
};
type CustomTypeToModel = typeof customTypeToModel;

Expand Down
8 changes: 5 additions & 3 deletions apps/web-stratos/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// ================================
// Transaction Message Types
// ================================
//pot
// pot
export { default as MsgVolumeReport } from '@/models/msg/pot/msg_volume_report';
export { default as MsgWithdraw } from '@/models/msg/pot/msg_withdraw';
export { default as MsgFoundationDeposit } from '@/models/msg/pot/msg_foundation_deposit';
export { default as MsgSlashingResourceNode } from '@/models/msg/pot/msg_slashing_resource_node';
//register
// register
export { default as MsgCreateMetaNode } from '@/models/msg/register/msg_create_meta_node';
export { default as MsgCreateResourceNode } from '@/models/msg/register/msg_create_resource_node';
export { default as MsgMetaNodeRegistrationVote } from '@/models/msg/register/msg_meta_node_registration_vote';
Expand All @@ -17,7 +17,9 @@ export { default as MsgUpdateMetaNodeDeposit } from '@/models/msg/register/msg_u
export { default as MsgUpdateMetaNode } from '@/models/msg/register/msg_update_meta_node';
export { default as MsgUpdateResourceNodeDeposit } from '@/models/msg/register/msg_update_resource_node_deposit';
export { default as MsgUpdateResourceNode } from '@/models/msg/register/msg_update_resource_node';
//sds
// sds
export { default as MsgFileUpload } from '@/models/msg/sds/msg_file_upload';
export { default as MsgPrepay } from '@/models/msg/sds/msg_prepay';
export * from 'ui/models';
// evm
export { default as MsgEthereumTx } from '@/models/msg/evm/msg_ethereum_tx';
Loading

0 comments on commit 0261a3b

Please sign in to comment.