-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
:feat add send wallet feature (#2038)
- Loading branch information
1 parent
b9f54cb
commit 5f44461
Showing
43 changed files
with
1,484 additions
and
10 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
apps/gallery/stories/composites/wui-input-amount.stories.ts
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,28 @@ | ||
import type { Meta } from '@storybook/web-components' | ||
import '@web3modal/ui/src/composites/wui-input-amount' | ||
import type { WuiInputAmount } from '@web3modal/ui/src/composites/wui-input-amount' | ||
import { html } from 'lit' | ||
import '../../components/gallery-container' | ||
|
||
type Component = Meta<WuiInputAmount> | ||
|
||
export default { | ||
title: 'Composites/wui-input-amount', | ||
args: { | ||
disabled: false, | ||
placeholder: '0' | ||
}, | ||
argTypes: { | ||
disabled: { | ||
control: { type: 'boolean' } | ||
} | ||
} | ||
} as Component | ||
|
||
export const Default: Component = { | ||
render: args => | ||
html` <wui-input-amount | ||
placeholder=${args.placeholder} | ||
?disabled=${args.disabled} | ||
></wui-input-amount>` | ||
} |
34 changes: 34 additions & 0 deletions
34
apps/gallery/stories/composites/wui-preview-item.stories.ts
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,34 @@ | ||
import type { Meta } from '@storybook/web-components' | ||
import '@web3modal/ui/src/composites/wui-preview-item' | ||
import type { WuiPreviewItem } from '@web3modal/ui/src/composites/wui-preview-item' | ||
import { html } from 'lit' | ||
import { address, networkImageSrc } from '../../utils/PresetUtils' | ||
|
||
type Component = Meta<WuiPreviewItem> | ||
|
||
export default { | ||
title: 'Composites/wui-preview-item', | ||
args: { | ||
imageSrc: networkImageSrc, | ||
address, | ||
text: '0.2 ETH', | ||
isAddress: false | ||
}, | ||
argTypes: { | ||
isAddress: { | ||
control: { type: 'boolean' } | ||
} | ||
} | ||
} as Component | ||
|
||
export const Default: Component = { | ||
render: args => html` | ||
<wui-preview-item | ||
text=${args.text} | ||
?isAddress=${args.isAddress} | ||
.address=${args.address} | ||
.imageSrc=${args.imageSrc} | ||
> | ||
</wui-preview-item> | ||
` | ||
} |
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
20 changes: 20 additions & 0 deletions
20
apps/gallery/stories/composites/wui-token-button.stories.ts
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,20 @@ | ||
import type { Meta } from '@storybook/web-components' | ||
import '@web3modal/ui/src/composites/wui-token-button' | ||
import type { WuiTokenButton } from '@web3modal/ui/src/composites/wui-token-button' | ||
import { html } from 'lit' | ||
import { networkImageSrc } from '../../utils/PresetUtils' | ||
|
||
type Component = Meta<WuiTokenButton> | ||
|
||
export default { | ||
title: 'Composites/wui-token-button', | ||
args: { | ||
text: 'ETH', | ||
imageSrc: networkImageSrc | ||
} | ||
} as Component | ||
|
||
export const Default: Component = { | ||
render: args => | ||
html`<wui-token-button text=${args.text} .imageSrc=${args.imageSrc}>Recent</wui-token-button>` | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { subscribeKey as subKey } from 'valtio/utils' | ||
import { proxy, ref, subscribe as sub } from 'valtio/vanilla' | ||
import type { Balance } from '@web3modal/common' | ||
|
||
// -- Types --------------------------------------------- // | ||
export interface SendControllerState { | ||
token?: Balance | ||
sendTokenAmount?: number | ||
receiverAddress?: string | ||
receiverProfileName?: string | ||
receiverProfileImageUrl?: string | ||
} | ||
|
||
type StateKey = keyof SendControllerState | ||
|
||
// -- State --------------------------------------------- // | ||
const state = proxy<SendControllerState>({}) | ||
|
||
// -- Controller ---------------------------------------- // | ||
export const SendController = { | ||
state, | ||
|
||
subscribe(callback: (newState: SendControllerState) => void) { | ||
return sub(state, () => callback(state)) | ||
}, | ||
|
||
subscribeKey<K extends StateKey>(key: K, callback: (value: SendControllerState[K]) => void) { | ||
return subKey(state, key, callback) | ||
}, | ||
|
||
setToken(token: SendControllerState['token']) { | ||
if (token) { | ||
state.token = ref(token) | ||
} | ||
}, | ||
|
||
setTokenAmount(sendTokenAmount: SendControllerState['sendTokenAmount']) { | ||
state.sendTokenAmount = sendTokenAmount | ||
}, | ||
|
||
setReceiverAddress(receiverAddress: SendControllerState['receiverAddress']) { | ||
state.receiverAddress = receiverAddress | ||
}, | ||
|
||
setReceiverProfileImageUrl( | ||
receiverProfileImageUrl: SendControllerState['receiverProfileImageUrl'] | ||
) { | ||
state.receiverProfileImageUrl = receiverProfileImageUrl | ||
}, | ||
|
||
setReceiverProfileName(receiverProfileName: SendControllerState['receiverProfileName']) { | ||
state.receiverProfileName = receiverProfileName | ||
}, | ||
|
||
resetSend() { | ||
state.token = undefined | ||
state.sendTokenAmount = undefined | ||
state.receiverAddress = undefined | ||
state.receiverProfileImageUrl = undefined | ||
state.receiverProfileName = undefined | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { SendController } from '../../index.js' | ||
|
||
// -- Setup -------------------------------------------------------------------- | ||
const token = { | ||
name: 'Optimism', | ||
symbol: 'OP', | ||
chainId: 'eip155:10', | ||
value: 6.05441523113072, | ||
price: 4.5340112, | ||
quantity: { | ||
decimals: '18', | ||
numeric: '1.335333100000000000' | ||
}, | ||
iconUrl: 'https://token-icons.s3.amazonaws.com/0x4200000000000000000000000000000000000042.png' | ||
} | ||
const sendTokenAmount = 0.1 | ||
const receiverAddress = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045' | ||
const receiverProfileName = 'john.eth' | ||
const receiverProfileImageUrl = 'https://ipfs.com/0x123.png' | ||
|
||
// -- Tests -------------------------------------------------------------------- | ||
describe('SendController', () => { | ||
it('should have valid default state', () => { | ||
expect(SendController.state).toEqual({}) | ||
}) | ||
|
||
it('should update state correctly on setToken()', () => { | ||
SendController.setToken(token) | ||
expect(SendController.state.token).toEqual(token) | ||
}) | ||
|
||
it('should update state correctly on setTokenAmount()', () => { | ||
SendController.setTokenAmount(sendTokenAmount) | ||
expect(SendController.state.sendTokenAmount).toEqual(sendTokenAmount) | ||
}) | ||
|
||
it('should update state correctly on receiverAddress()', () => { | ||
SendController.setReceiverAddress(receiverAddress) | ||
expect(SendController.state.receiverAddress).toEqual(receiverAddress) | ||
}) | ||
|
||
it('should update state correctly on receiverProfileName()', () => { | ||
SendController.setReceiverProfileName(receiverProfileName) | ||
expect(SendController.state.receiverProfileName).toEqual(receiverProfileName) | ||
}) | ||
|
||
it('should update state correctly on receiverProfileName()', () => { | ||
SendController.setReceiverProfileImageUrl(receiverProfileImageUrl) | ||
expect(SendController.state.receiverProfileImageUrl).toEqual(receiverProfileImageUrl) | ||
}) | ||
|
||
it('should update state correctly on resetSend()', () => { | ||
SendController.resetSend() | ||
expect(SendController.state).toEqual({}) | ||
}) | ||
}) |
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.