-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solution: stories for web demo with ethereum features
- Loading branch information
Showing
9 changed files
with
308 additions
and
51 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
packages/react-app/stories/ExampleWeb/ERC20Allowance.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import {providerForStore} from "../storeProvider"; | ||
import {Meta} from "@storybook/react"; | ||
import * as React from 'react'; | ||
import {accounts, allowances, tokens} from "@emeraldwallet/store"; | ||
import {BackendMock, MemoryApiMock} from "../__mocks__"; | ||
import {WalletEntry} from "@emeraldpay/emerald-vault-core"; | ||
import {BlockchainCode} from "@emeraldwallet/core"; | ||
import WalletAllowance from "../../src/wallets/WalletDetails/WalletAllowance"; | ||
import {tokenDAI, tokenWETH} from "../wallets"; | ||
|
||
const api = new MemoryApiMock(); | ||
const backend = new BackendMock(); | ||
|
||
const entries: WalletEntry[] = [ | ||
{ | ||
id: '2a19e023-f119-4dab-b2cb-4b3e73fa32c9-1', | ||
address: { | ||
type: 'single', | ||
value: '0x1d1C7DB10aa1a6067Ba81F0Dd6FD4F26FC594f13', | ||
}, | ||
key: { | ||
type: 'hd-path', | ||
hdPath: "m/44'/60'/0'/0/0", | ||
seedId: 'c782ff2b-ba6e-43e2-9e2d-92d05cc37b03', | ||
}, | ||
blockchain: 100, | ||
createdAt: new Date(), | ||
}, | ||
]; | ||
|
||
let actions = [ | ||
accounts.actions.setWalletsAction([ | ||
{ | ||
entries, | ||
id: '2a19e023-f119-4dab-b2cb-4b3e73fa32c9', | ||
createdAt: new Date(), | ||
}, | ||
]), | ||
{ | ||
type: 'LAUNCHER/TOKENS', | ||
payload: [ | ||
{ | ||
name: 'Wrapped Ether', | ||
blockchain: 100, | ||
address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', | ||
symbol: 'WETH', | ||
decimals: 18, | ||
type: 'ERC20', | ||
}, | ||
], | ||
}, | ||
|
||
accounts.actions.setBalanceAction({ | ||
address: '0x0', | ||
balance: '1000000000000000000/WEI', | ||
entryId: '2a19e023-f119-4dab-b2cb-4b3e73fa32c9-1', | ||
}), | ||
tokens.actions.setTokenBalance(BlockchainCode.ETH, '0x0', '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', { | ||
decimals: 18, | ||
symbol: 'WETH', | ||
unitsValue: '1000000000000000000', | ||
}), | ||
|
||
allowances.actions.setAllowance({ | ||
address: '0x1d1C7DB10aa1a6067Ba81F0Dd6FD4F26FC594f13', | ||
allowance: "1000000000000000000", | ||
available: "700000000000000000", | ||
blockchain: BlockchainCode.ETH, | ||
contractAddress: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', | ||
ownerAddress: "0x1d1C7DB10aa1a6067Ba81F0Dd6FD4F26FC594f13", | ||
spenderAddress: "0x7992586aCaEcA5b19B973c1cd12B695131c0B736", | ||
timestamp: Date.now() - 12345678, | ||
}, [ | ||
tokenWETH, tokenDAI | ||
]), | ||
|
||
allowances.actions.setAllowance({ | ||
address: '0x1d1C7DB10aa1a6067Ba81F0Dd6FD4F26FC594f13', | ||
allowance: "20000000000000000000000", | ||
available: "17500000000000000000", | ||
blockchain: BlockchainCode.ETH, | ||
contractAddress: '0x6B175474E89094C44Da98b954EedeAC495271d0F', | ||
ownerAddress: "0x1d1C7DB10aa1a6067Ba81F0Dd6FD4F26FC594f13", | ||
spenderAddress: "0x7992586aCaEcA5b19B973c1cd12B695131c0B736", | ||
timestamp: Date.now() - 12345678, | ||
}, [ | ||
tokenWETH, tokenDAI | ||
]), | ||
|
||
allowances.actions.setAllowance({ | ||
address: '0x1d1C7DB10aa1a6067Ba81F0Dd6FD4F26FC594f13', | ||
allowance: "99000000000000000000000000000000000000000000", | ||
available: "9161660000000000000", | ||
blockchain: BlockchainCode.ETH, | ||
contractAddress: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', | ||
ownerAddress: "0xCb1c1a86bcae979B971c192Cc5D2B6551311B73e", | ||
spenderAddress: "0x1d1C7DB10aa1a6067Ba81F0Dd6FD4F26FC594f13", | ||
timestamp: Date.now() - 12345678, | ||
}, [ | ||
tokenWETH, tokenDAI | ||
]), | ||
|
||
]; | ||
|
||
|
||
export default { | ||
title: 'Example Web / ERC20 Allowance', | ||
decorators: [providerForStore(api, backend, actions),], | ||
} as Meta; | ||
|
||
export const Default = { | ||
name: 'ERC20 Allowance', | ||
render: () => <WalletAllowance walletId="2a19e023-f119-4dab-b2cb-4b3e73fa32c9" /> | ||
}; |
19 changes: 19 additions & 0 deletions
19
packages/react-app/stories/ExampleWeb/ETHSignMessage.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {providerForStore} from "../storeProvider"; | ||
import {Meta} from "@storybook/react"; | ||
import * as React from "react"; | ||
import {BackendMock, MemoryApiMock} from "../__mocks__"; | ||
import SignMessage from "../../src/message/SignMessage"; | ||
import {createWallets} from "../wallets"; | ||
|
||
const api = new MemoryApiMock(); | ||
const backend = new BackendMock(); | ||
|
||
export default { | ||
title: 'Example Web / ETH Sign Message', | ||
decorators: [providerForStore(api, backend, [...createWallets]), ], | ||
} as Meta; | ||
|
||
export const Default = { | ||
name: 'ETH Sign Message', | ||
render: () => <SignMessage walletId="8ff89b7d-8a73-4ee0-ad5b-8ac1f04a49ef" /> | ||
}; |
85 changes: 85 additions & 0 deletions
85
packages/react-app/stories/ExampleWeb/SwapWETH.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import {providerForStore} from "../storeProvider"; | ||
import {Meta} from "@storybook/react"; | ||
import * as React from 'react'; | ||
import {accounts, StoredTransaction, tokens, TxAction, txStash} from "@emeraldwallet/store"; | ||
import {CreateTransaction} from "../../src/transaction"; | ||
import {BackendMock, MemoryApiMock} from "../__mocks__"; | ||
import {WalletEntry} from "@emeraldpay/emerald-vault-core"; | ||
import {BlockchainCode, TokenRegistry, workflow} from "@emeraldwallet/core"; | ||
import {State, Status} from "@emeraldwallet/core/lib/persistentState"; | ||
|
||
const api = new MemoryApiMock(); | ||
const backend = new BackendMock(); | ||
|
||
const entries: WalletEntry[] = [ | ||
{ | ||
id: '2a19e023-f119-4dab-b2cb-4b3e73fa32c9-1', | ||
address: { | ||
type: 'single', | ||
value: '0x1d1C7DB10aa1a6067Ba81F0Dd6FD4F26FC594f13', | ||
}, | ||
key: { | ||
type: 'hd-path', | ||
hdPath: "m/44'/60'/0'/0/0", | ||
seedId: 'c782ff2b-ba6e-43e2-9e2d-92d05cc37b03', | ||
}, | ||
blockchain: 100, | ||
createdAt: new Date(), | ||
}, | ||
]; | ||
|
||
let actions = [ | ||
accounts.actions.setWalletsAction([ | ||
{ | ||
entries, | ||
id: '2a19e023-f119-4dab-b2cb-4b3e73fa32c9', | ||
createdAt: new Date(), | ||
}, | ||
]), | ||
{ | ||
type: 'LAUNCHER/TOKENS', | ||
payload: [ | ||
{ | ||
name: 'Wrapped Ether', | ||
blockchain: 100, | ||
address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', | ||
symbol: 'WETH', | ||
decimals: 18, | ||
type: 'ERC20', | ||
}, | ||
], | ||
}, | ||
|
||
accounts.actions.setBalanceAction({ | ||
address: '0x0', | ||
balance: '1000000000000000000/WEI', | ||
entryId: '2a19e023-f119-4dab-b2cb-4b3e73fa32c9-1', | ||
}), | ||
tokens.actions.setTokenBalance(BlockchainCode.ETH, '0x0', '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', { | ||
decimals: 18, | ||
symbol: 'WETH', | ||
unitsValue: '1000000000000000000', | ||
}), | ||
|
||
txStash.actions.setTransaction({ | ||
blockchain: BlockchainCode.ETH, | ||
amount: '1000000000000000000/WEI', | ||
asset: 'ETH', | ||
target: workflow.TxTarget.MANUAL, | ||
type: "transfer", | ||
meta: { | ||
type: workflow.TxMetaType.ERC20_CONVERT, | ||
} | ||
}), | ||
]; | ||
|
||
|
||
export default { | ||
title: 'Example Web / ETH to WETH Conversion', | ||
decorators: [providerForStore(api, backend, actions),], | ||
} as Meta; | ||
|
||
export const Default = { | ||
name: 'ETH to WETH Conversion', | ||
render: () => <CreateTransaction action={TxAction.CONVERT} entryId="2a19e023-f119-4dab-b2cb-4b3e73fa32c9-1" /> | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.