Skip to content

Commit

Permalink
Merge pull request #11 from alephium/upgrade-deps
Browse files Browse the repository at this point in the history
Upgrade @alephium/web3 to 0.2.0-rc.33
  • Loading branch information
h0ngcha0 authored Oct 10, 2022
2 parents b356d46 + 70e448a commit c0a42f7
Show file tree
Hide file tree
Showing 29 changed files with 2,011 additions and 1,757 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"repository": "",
"homepage": "",
"devDependencies": {
"@rollup/plugin-json": "^4.1.0",
"bundlewatch": "^0.3.3",
"eslint-plugin-import": "^2.26.0",
"husky": "^8.0.0",
Expand All @@ -22,7 +23,7 @@
"format": "prettier --loglevel warn --write \"**/*.{js,jsx,ts,tsx,css,md,yml,json}\"",
"dev": "lerna run dev --parallel",
"dev:ui": "lerna run dev:ui --parallel",
"clean": "rm -rf packages/extension/dist packages/get-extension-wallet/dist",
"clean": "rm -rf packages/extension/dist packages/get-extension-wallet/dist packages/dapp/dist packages/extension/node_modules packages/get-extension-wallet/node_modules packages/dapp/node_modules",
"build": "lerna run build --stream",
"build:sourcemaps": "GEN_SOURCE_MAPS=true lerna run build",
"lint": "lerna run lint --stream",
Expand Down
9 changes: 8 additions & 1 deletion packages/dapp/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: true,
swcMinify: true
swcMinify: true,
webpack: (config, { isServer }) => {
config.resolve.fallback = {
...config.resolve.fallback,
fs: false
}
return config
}
}
4 changes: 2 additions & 2 deletions packages/dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"lint": "next lint"
},
"dependencies": {
"@alephium/get-extension-wallet": "0.1.5",
"@alephium/web3": "0.2.0-rc.15",
"@alephium/get-extension-wallet": "0.3.0",
"@alephium/web3": "0.2.0-rc.33",
"ethers": "^5.5.1",
"next": "^12.1.4",
"react": "^18.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/dapp/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const Home: NextPage = () => {
useEffect(() => {
;(async () => {
const wallet = await silentConnectWallet()
setAddress(wallet?.selectedAccount?.address)
setAddress(wallet?.defaultAddress?.address)
setConnected(!!wallet?.isConnected)
})()
}, [])

const handleConnectClick = async () => {
const wallet = await connectWallet()
setAddress(wallet?.selectedAccount?.address)
setAddress(wallet?.defaultAddress?.address)
setConnected(!!wallet?.isConnected)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/dapp/src/services/wallet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ export const walletAddress = async (): Promise<string | undefined> => {
if (!alephium?.isConnected) {
return
}
return alephium.selectedAccount?.address
return alephium.defaultAddress?.address
}
4 changes: 2 additions & 2 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
"@mui/material": "^5.1.0",
"@mui/styled-engine-sc": "^5.1.0",
"@tippyjs/react": "^4.2.6",
"@alephium/web3": "0.2.0-rc.15",
"@alephium/web3-wallet": "0.2.0-rc.15",
"@alephium/web3": "0.2.0-rc.33",
"@alephium/web3-wallet": "0.2.0-rc.33",
"@alephium/sdk": "0.1.0",
"crypto-browserify": "3.12.0",
"stream-browserify": "3.0.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/extension/src/background/customNetworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ export const getNetworks = async (): Promise<Network[]> => {

export const getNetwork = async (): Promise<Network> => {
const allNetworks = await getNetworks()
const currentNetworkId = await getCurrentNetwork()
const currentNetworkId = (await getCurrentNetwork()).id
return allNetworks.find(({ id }) => id === currentNetworkId) || defaultNetwork
}

export const setCurrentNetwork = async (networkId: string): Promise<{ networkId: string }> => {
export const setCurrentNetwork = async (networkId: string): Promise<{ network: Network }> => {
const allNetworks = await getNetworks()
const network = allNetworks.find(({ id }) => id === networkId) || defaultNetwork

networksStore.setItem('currentNetwork', network)
return { networkId: network.id }
return { network: network }
}

export const getNetworkStatuses = async (): Promise<NetworkStatus[]> => {
Expand Down Expand Up @@ -70,9 +70,9 @@ export const isNetworkHealthy = async (network: Network): Promise<boolean> => {
}
}

export const getCurrentNetwork = async (): Promise<string> => {
export const getCurrentNetwork = async (): Promise<Network> => {
const currentNetwork = await networksStore.getItem('currentNetwork')
return currentNetwork.id
return currentNetwork
}

export const getNetworkById = async (id: string): Promise<Network | undefined> => {
Expand Down
4 changes: 2 additions & 2 deletions packages/extension/src/background/networkMessaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export const handleNetworkMessage: HandleMessage<NetworkMessage> = async ({
}

case 'GET_CURRENT_NETWORK': {
const networkId = await getCurrentNetwork()
const network = await getCurrentNetwork()
return sendToTabAndUi({
type: 'GET_CURRENT_NETWORK_RES',
data: { networkId }
data: { network }
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export const executeAlephiumTransaction = async (
})
}

case 'ALPH_SIGN_AND_SUBMIT_TRANSFER_TX': {
return await withSigner(async (signer) => {
const submissionResult = await signer.signAndSubmitTransferTx(payload.params)
return {
type: 'ALPH_SIGN_AND_SUBMIT_TRANSFER_TX_RES',
result: submissionResult
}
})
}

case 'ALPH_SIGN_CONTRACT_CREATION_TX': {
return await withSigner(async (signer) => {
const signResult = await signer.signDeployContractTx(payload.params)
Expand All @@ -39,6 +49,16 @@ export const executeAlephiumTransaction = async (
})
}

case 'ALPH_SIGN_AND_SUBMIT_CONTRACT_CREATION_TX': {
return await withSigner(async (signer) => {
const submitResult = await signer.signAndSubmitDeployContractTx(payload.params)
return {
type: 'ALPH_SIGN_AND_SUBMIT_CONTRACT_CREATION_TX_RES',
result: submitResult
}
})
}

case 'ALPH_SIGN_SCRIPT_TX': {
return await withSigner(async (signer) => {
const signResult = await signer.signExecuteScriptTx(payload.params)
Expand All @@ -48,5 +68,45 @@ export const executeAlephiumTransaction = async (
}
})
}

case 'ALPH_SIGN_AND_SUBMIT_SCRIPT_TX': {
return await withSigner(async (signer) => {
const submitResult = await signer.signAndSubmitExecuteScriptTx(payload.params)
return {
type: 'ALPH_SIGN_AND_SUBMIT_SCRIPT_TX_RES',
result: submitResult
}
})
}

case 'ALPH_SIGN_UNSIGNED_TX': {
return await withSigner(async (signer) => {
const signResult = await signer.signUnsignedTx(payload.params)
return {
type: 'ALPH_SIGN_UNSIGNED_TX_RES',
result: signResult
}
})
}

case 'ALPH_SIGN_HEX_STRING': {
return await withSigner(async (signer) => {
const signResult = await signer.signHexString(payload.params)
return {
type: 'ALPH_SIGN_HEX_STRING_RES',
result: signResult
}
})
}

case 'ALPH_SIGN_MESSAGE': {
return await withSigner(async (signer) => {
const signResult = await signer.signMessage(payload.params)
return {
type: 'ALPH_SIGN_MESSAGE_RES',
result: signResult
}
})
}
}
}
13 changes: 1 addition & 12 deletions packages/extension/src/background/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,7 @@ export class Wallet {
) {}

async getNodeProvider(): Promise<NodeProvider> {
const currentNetwork = await this.getCurrentNetwork()
let currentNodeProvider: NodeProvider | undefined = undefined
try {
currentNodeProvider = web3.getCurrentNodeProvider()
if (currentNodeProvider.baseUrl === currentNetwork.nodeUrl) {
return currentNodeProvider
}
} catch (e) {
console.info('Error getting current node provider', e)
}

web3.setCurrentNodeProvider(currentNetwork.nodeUrl)
web3.setCurrentNodeProvider((await this.getCurrentNetwork()).nodeUrl)
return web3.getCurrentNodeProvider()
}

Expand Down
Loading

0 comments on commit c0a42f7

Please sign in to comment.