Skip to content

Commit

Permalink
Merge branch 'feature/beacon-deposit-event' of https://github.com/con…
Browse files Browse the repository at this point in the history
…sensusnetworks/casimir into feature/beacon-deposit-event
  • Loading branch information
hawyar committed Oct 11, 2022
2 parents 20e5c3c + 599149d commit 467fcc2
Show file tree
Hide file tree
Showing 41 changed files with 1,494 additions and 3,785 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ jobs:
- name: Deploy cdk infrastructure
run: npm run deploy

- name: Build and deploy email templates
run: npm run deploy:templates

- name: Select success emoji
if: ${{ success() }}
run: echo 'EMOJI=:rocket:' >> $GITHUB_ENV
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ jobs:
- name: Deploy cdk infrastructure
run: npm run deploy

- name: Build and deploy email templates
run: npm run deploy:templates

- name: Sync released version files to develop
if: ${{ github.actor != 'nektos/act' }}
run: |
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ template.out
aws.env
*.log
.idea

# Hardhat
contracts/evm/build/cache
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"[html]": {
"editor.defaultFormatter": "Vue.volar"
},
"[vue]": {
"editor.defaultFormatter": "Vue.volar"
},
"[javascript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"eslint.validate": [
"vue",
"typescript"
Expand Down
28 changes: 7 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img width="50px" alt="Casimir logo" src="common/data/notebooks/diagrams/resources/casimir.png">
<img width="50px" alt="Casimir logo" src="common/images/casimir.png">

# Casimir

Expand Down Expand Up @@ -95,21 +95,21 @@ You can get up and running without configuration. You can also mock local backen

### Hardhat

EVM contract development is serviced through [Hardhat](https://hardhat.io/). The Hardhat development environment is configured in the [contracts/evm/hardhat.config.ts](contracts/evm/hardhat.config.ts) file.
Ethereum contract development is serviced through [Hardhat](https://hardhat.io/). The Hardhat development environment is configured in the [contracts/ethereum/hardhat.config.ts](contracts/ethereum/hardhat.config.ts) file.

1. Compile the contracts in [contracts/evm](contracts/evm).
1. Compile the contracts in [contracts/ethereum](contracts/ethereum).

```zsh
npm run task:compile
```

2. Deploy a contract, specifically [contracts/evm/src/Sample.sol](contracts/evm/src/Sample.sol) with [contracts/evm/deploy/sample.ts](contracts/evm/deploy/sample.ts).
2. Deploy a contract, specifically [contracts/ethereum/src/Sample.sol](contracts/ethereum/src/Sample.sol) with [contracts/ethereum/deploy/sample.ts](contracts/ethereum/deploy/sample.ts).

```zsh
npm run deploy:sample
```

3. Test the Sample with the tests in [contracts/evm/test/sample.ts](contracts/evm/test/sample.ts).
3. Test the Sample with the tests in [contracts/ethereum/test/sample.ts](contracts/ethereum/test/sample.ts).

```zsh
npm run test:contracts
Expand All @@ -127,7 +127,7 @@ EVM contract development is serviced through [Hardhat](https://hardhat.io/). The
// Todo add Casimir Typescript usage
```

7. Clean [contracts/evm/build/artifacts](contracts/evm/build/artifacts) and [contracts/evm/build/cache](contracts/evm/build/cache)).
7. Clean [contracts/ethereum/build/artifacts](contracts/ethereum/build/artifacts) and [contracts/ethereum/build/cache](contracts/ethereum/build/cache)).

```zsh
npm run task:clean
Expand Down Expand Up @@ -205,18 +205,6 @@ npm install some-dependency --workspace @casimir/workspace-name # i.e. @casimir/
npm install -D some-dev-dependency --workspace @casimir/workspace-name
```

## 📝 Content

Get started contributing to Casimir's content.
### Writing
Writing content is stored in the [content/writing](content/writing/) directory. See the [Writing Contribution Guide](content/writing/README.md) for detailed usage instructions.
### Emails
AWS Pinpont email templates and shared components are stored in the [content/email](content/email/) directory. See the [Email Contribution Guide](content/email/README.md) for detailed usage instructions.
## 📊 Data

Data schemas, data operations/workflows, and analytics and ML notebooks are stored in the [common/data/] directory (also namespaced as the @casimir/data npm workspace). See the [Data Contribution Guide](common/data/README.md) for detailed usage instructions.
Expand All @@ -234,9 +222,7 @@ Code is organized into work directories (apps, services, infrastructure – and
├── infrastructure/ (deployment resources)
| └── cdk/ (aws stacks)
├── common/ (shared code)
| └── lib/ (general utilities)
├── content/ (static code and text)
| └── email/ (pinpoint templates)
| └── helpers/ (general utilities)
├── scripts/ (devops and build scripts)
| └── local/ (mock and serve tasks)
├── services/ (backend services)
Expand Down
4 changes: 3 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"dependencies": {
"@heroicons/vue": "^1.0.6",
"@ledgerhq/hw-app-eth": "^6.29.4",
"@ledgerhq/hw-transport-webhid": "^6.27.2",
"@ledgerhq/hw-transport-webusb": "^6.27.4",
"@solana/web3.js": "^1.63.1",
"@walletconnect/client": "^1.8.0",
"@walletconnect/qrcode-modal": "^1.8.0",
"borsh": "^0.7.0",
"buffer": "^6.0.3",
"ethers": "^5.6.9",
"iotex-antenna": "^0.31.3",
Expand Down
96 changes: 75 additions & 21 deletions apps/web/src/components/Wallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
</p>
</div>
<div class="coinbase-div">
<button class="coinbase-btn" @click="connectWallet('CoinbaseWallet')">
<button
class="coinbase-btn"
@click="connectWallet('CoinbaseWallet')"
>
{{ coinbaseButtonText }}
</button>
<p>
Expand All @@ -20,15 +23,33 @@
</p>
</div>
<div class="ioPay-div">
<button class="iopay-btn" @click="connectWallet('IoPay')">
<button
class="iopay-btn"
@click="connectWallet('IoPay')"
>
{{ ioPayButtonText }}
</button>
<p>
Connected ioPay Account:
<span> {{ ioPayAccountsResult }} </span>
</p>
</div>
<button class="ledger-btn" @click="connectWallet('Ledger')">
<div class="phantom-div">
<button
class="phantom-btn"
@click="connectWallet('Phantom')"
>
{{ phantomButtonText }}
</button>
<p>
Connected phantom Account:
<span> {{ phantomAccountsResult }} </span>
</p>
</div>
<button
class="ledger-btn"
@click="connectWallet('Ledger')"
>
Connect Ledger
</button>
<div>
Expand All @@ -38,28 +59,37 @@
>
WalletConnect
</button>
<button
class="wallet-connect-btn"
@click="sendTransaction('WalletConnect')"
>
Send WalletConnect Transaction
</button>
<button
class="wallet-connect-btn"
@click="disconnectWallet('WalletConnect')"
>
Disable WalletConnect
</button>
</div>
</div>
<div class="form-container">
<form @submit.prevent="sendTransaction(selectedProvider)">
<div class="sign-message-container">
<input
v-model="message"
type="text"
placeholder="Write a message to sign"
>
<button @click="signMessage(message)">
Sign Message
</button>
<p>{{ signedMessage }}</p>
</div>
<form @submit.prevent="sendTransaction()">
<label for="address">Address</label>
<input v-model="toAddress" type="text" placeholder="To Address" />
<br />
<input
v-model="toAddress"
type="text"
placeholder="To Address"
>
<br>
<label for="amount">Amount</label>
<input v-model="amount" type="text" placeholder="Amount Ether" />
<button type="submit">Send Transaction</button>
<input
v-model="amount"
type="text"
placeholder="Amount Ether"
>
<button type="submit">
Send Transaction
</button>
</form>
</div>
</div>
Expand All @@ -69,21 +99,26 @@
import { ref, watchEffect } from 'vue'
import useWallet from '@/composables/wallet'
const message = ref('')
const signedMessage = ref('')
const metamaskButtonText = ref<string>('Connect Metamask')
const metamaskAccountsResult = ref<string>('Address Not Active')
const coinbaseButtonText = ref<string>('Connect Coinbase')
const coinbaseAccountsResult = ref<string>('Address Not Active')
const ioPayButtonText = ref<string>('Connect ioPay')
const ioPayAccountsResult = ref<string>('Address Not Active')
const phantomButtonText = ref<string>('Connect Phantom')
const phantomAccountsResult = ref<string>('Address Not Active')
const {
selectedProvider,
selectedAccount,
toAddress,
amount,
connectWallet,
disconnectWallet,
sendTransaction,
signMessage,
} = useWallet()
watchEffect(() => {
Expand All @@ -94,20 +129,35 @@ watchEffect(() => {
ioPayButtonText.value = 'Connect ioPay'
coinbaseAccountsResult.value = 'Not Active'
ioPayAccountsResult.value = 'Not Active'
phantomButtonText.value = 'Connect Phantom'
phantomAccountsResult.value = 'Not Active'
} else if (selectedProvider.value === 'CoinbaseWallet') {
metamaskButtonText.value = 'Connect Metamask'
coinbaseButtonText.value = 'Coinbase Connected'
ioPayButtonText.value = 'Connect ioPay'
metamaskAccountsResult.value = 'Not Active'
coinbaseAccountsResult.value = selectedAccount.value
ioPayAccountsResult.value = 'Not Active'
phantomButtonText.value = 'Connect Phantom'
phantomAccountsResult.value = 'Not Active'
} else if (selectedProvider.value === 'IoPay') {
metamaskButtonText.value = 'Connect MetaMask'
coinbaseButtonText.value = 'Connect Coinbase'
ioPayButtonText.value = 'Connected'
metamaskAccountsResult.value = 'Not Active'
coinbaseAccountsResult.value = 'Not Active'
ioPayAccountsResult.value = selectedAccount.value || 'Not Active'
phantomButtonText.value = 'Connect Phantom'
phantomAccountsResult.value = 'Not Active'
} else if (selectedProvider.value === 'Phantom') {
metamaskButtonText.value = 'Connect MetaMask'
coinbaseButtonText.value = 'Connect Coinbase'
ioPayButtonText.value = 'Connect ioPay'
phantomButtonText.value = 'Connected'
metamaskAccountsResult.value = 'Not Active'
coinbaseAccountsResult.value = 'Not Active'
ioPayAccountsResult.value = 'Not Active'
phantomAccountsResult.value = selectedAccount.value || 'Not Active'
}
})
</script>
Expand Down Expand Up @@ -155,6 +205,10 @@ button {
background-color: rgb(0, 0, 0);
}
.phantom-btn {
background-color: purple;
}
.connect-wallet-container {
display: flex;
flex-direction: column;
Expand Down
70 changes: 66 additions & 4 deletions apps/web/src/composables/ethers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,75 @@
import { ref } from 'vue'
import { ethers } from 'ethers'
import { BrowserProviders } from '@/interfaces/BrowserProviders'
import { EthersProvider } from '@/interfaces/EthersProvider'
import { ProviderString } from '@/types/ProviderString'
import { TransactionInit } from '@/interfaces/TransactionInit'
import { MessageInit } from '@/interfaces/MessageInit'

const defaultProviders = {
MetaMask: undefined,
CoinbaseWallet: undefined,
}

const ethereum: any = window.ethereum
const availableProviders = ref<BrowserProviders>(getBrowserProviders(ethereum))

export default function useEthers() {
async function requestEthersAccount(provider: EthersProvider) {
if (provider.request) {
return await provider.request({
const ethersProviderList = ['MetaMask', 'CoinbaseWallet']
async function requestEthersAccount(provider: ProviderString) {
const browserExtensionProvider =
availableProviders.value[provider as keyof BrowserProviders]
if (browserExtensionProvider?.request) {
return await browserExtensionProvider.request({
method: 'eth_requestAccounts',
})
}
}

return { requestEthersAccount }
async function sendEthersTransaction(
{ to, value, providerString }: TransactionInit
) {
const browserProvider =
availableProviders.value[providerString as keyof BrowserProviders]
const web3Provider: ethers.providers.Web3Provider =
new ethers.providers.Web3Provider(browserProvider as EthersProvider)
const signer = web3Provider.getSigner()
const etherAmount = ethers.utils.parseEther(value)
const tx = {
to,
value: etherAmount,
}
const { hash } = await signer.sendTransaction(tx)
return hash
}

async function signEthersMessage(messageInit: MessageInit): Promise<string> {
const { providerString, hashedMessage } = messageInit
const browserProvider =
availableProviders.value[
providerString as keyof BrowserProviders
]
const web3Provider: ethers.providers.Web3Provider =
new ethers.providers.Web3Provider(browserProvider as EthersProvider)
const signer = web3Provider.getSigner()
const signature = await signer.signMessage(hashedMessage)
return signature
}

return { ethersProviderList, requestEthersAccount, getBrowserProviders, sendEthersTransaction, signEthersMessage }
}

function getBrowserProviders(ethereum: any) {
if (!ethereum) return defaultProviders
else if (!ethereum.providerMap) {
return {
MetaMask: ethereum.isMetaMask ? ethereum : undefined,
CoinbaseWallet: ethereum.isCoinbaseWallet ? ethereum : undefined,
}
} else {
return {
MetaMask: ethereum.providerMap.get('MetaMask'),
CoinbaseWallet: ethereum.providerMap.get('CoinbaseWallet'),
}
}
}
Loading

0 comments on commit 467fcc2

Please sign in to comment.