Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: convert #2116

Merged
merged 113 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
a7c7ce0
feat(swap): add swap view
Cali93 Nov 21, 2023
9693a2a
refactor: update swap view ui (#1492)
enesozturk Nov 22, 2023
fff2914
chore: fix ts issues
enesozturk Nov 22, 2023
e3eca53
feat(1inch-api): request data from 1inch swap API (#1497)
Cali93 Nov 24, 2023
fedbb87
fix(multiple-requests): fix multiple requests issue
Cali93 Nov 24, 2023
9cf5b70
feat: implement remaining pages and ui components (#1493)
enesozturk Nov 24, 2023
d5ee070
refactor: update swap token state logics
enesozturk Nov 24, 2023
66061e9
fix(swaps): fix input onChange
Cali93 Nov 24, 2023
7bf805c
refactor: update all swap comps
enesozturk Mar 5, 2024
671cdd7
chore: update styles, remove unused functions
enesozturk Mar 5, 2024
b00813d
refactor: add amount input validation and formatting
enesozturk Mar 5, 2024
a93aaf7
chore: comment client methods
enesozturk Mar 5, 2024
ffaa666
chore: update lock file
enesozturk Mar 5, 2024
bf39179
refactor: ui changes, add gas price API
enesozturk Mar 6, 2024
7c4a76f
fix: build issues
enesozturk Mar 6, 2024
8781d6b
fix: linter issues
enesozturk Mar 6, 2024
82ebc55
fix: type error
enesozturk Mar 6, 2024
83ff610
refactor: update controller values, calculations, separate components
enesozturk Mar 7, 2024
ae8eed4
fix: build issues
enesozturk Mar 7, 2024
fac33b5
refactor: handle TX success
enesozturk Mar 8, 2024
452e158
feat: calculate price impact and slippage values
enesozturk Mar 11, 2024
25bca0b
chore: remove unused variables
enesozturk Mar 11, 2024
c1d511d
feat: add search, separate utils
enesozturk Mar 11, 2024
a7ec5b9
fix: linter issues
enesozturk Mar 11, 2024
554bc85
refactor: separate convert controllers
enesozturk Mar 15, 2024
5d1ca7d
chore: remove convert from default account view
enesozturk Mar 15, 2024
7ded284
refactor: improve business logics
enesozturk Mar 15, 2024
0144050
refactor: linter and build issues
enesozturk Mar 15, 2024
2836515
Merge branch 'V4' into feat/1inch-swaps
enesozturk Mar 19, 2024
a4f6d95
refactor: update token button usage
enesozturk Mar 19, 2024
4e2b47c
feat: add gas price checking
enesozturk Mar 21, 2024
0d66179
feat: add bignumber.js, refactor convert business logics
enesozturk Mar 22, 2024
f07dfdf
refactor: update price impact calculation method
enesozturk Mar 22, 2024
3cf32e3
chore: add suggested tokens list
enesozturk Mar 22, 2024
8ea56d7
chore: linter issues
enesozturk Mar 22, 2024
c63f4e6
fix: build and linter issues
enesozturk Mar 22, 2024
8c3d915
feat: add new ui components for different variations of transaction UIs
enesozturk Mar 28, 2024
877dee8
Merge branch 'V4' into feat/1inch-swaps
enesozturk Mar 28, 2024
a80ec50
feat: ui/styling improvements
enesozturk Apr 1, 2024
220a2d2
refactor: approve transaction view opening business logic
enesozturk Apr 1, 2024
af14fbc
chore: convert details section styling
enesozturk Apr 1, 2024
e249bd3
Merge branch 'V4' into feat/1inch-swaps
enesozturk Apr 2, 2024
c37cf68
chore: set native token as source token when reset state
enesozturk Apr 2, 2024
b8750a3
refactor: approve transaction iframe position stylings
enesozturk Apr 2, 2024
ddcdaa0
chore: update lock file
enesozturk Apr 2, 2024
9cf0ca0
feat: implement new lab with tailwind and shadcn comps
enesozturk Apr 2, 2024
bd165ae
chore: update lock file
enesozturk Apr 2, 2024
00e0d0f
chore: w3m color variables
enesozturk Apr 2, 2024
e5916f9
chore: fix package versions and format files
enesozturk Apr 2, 2024
63a6cf1
chore: add sonner
enesozturk Apr 2, 2024
1d75013
fix: toast call
enesozturk Apr 2, 2024
d11964a
chore: remove brackets for string props
enesozturk Apr 2, 2024
0c00a32
chore: remove loose dependency
enesozturk Apr 2, 2024
56db6d2
chore: hydration and styling issues
enesozturk Apr 2, 2024
6e7f04e
chore: svg props
enesozturk Apr 2, 2024
5ac15e5
chore: remove classname from the lit elements
enesozturk Apr 2, 2024
b2f4eb3
chore: remove lucid, refactor class names
enesozturk Apr 2, 2024
13d8dac
fix: dialog forwarded comps
enesozturk Apr 2, 2024
1888fc7
chore: update comp locations, refactor class names
enesozturk Apr 2, 2024
ed9e434
Merge branch 'refactor/lab-ui-update-design-system-vars' into feat/1i…
enesozturk Apr 2, 2024
fc5d5f8
chore: list more polygon tokens, add token balance watcher
enesozturk Apr 2, 2024
6b2ae0d
chore: build issues
enesozturk Apr 2, 2024
678fdb3
chore: code review updates
enesozturk Apr 3, 2024
befc141
chore: move convert api to utils, export missing comps
enesozturk Apr 3, 2024
4712c6a
fix: imports
enesozturk Apr 3, 2024
1767677
Revert "Merge branch 'refactor/lab-ui-update-design-system-vars' into…
enesozturk Apr 3, 2024
cf5665b
Merge branch 'V4' into feat/1inch-swaps
enesozturk Apr 3, 2024
4bb1008
chore: remove ts ignores, add mock functions for solana client
enesozturk Apr 3, 2024
a07300c
chore: export missing comps
enesozturk Apr 3, 2024
726e30e
chore: convert controller tests
enesozturk Apr 3, 2024
47b1ca8
chore: linter issues
enesozturk Apr 3, 2024
8b8b4d2
Merge branch 'V4' into feat/1inch-swaps
enesozturk Apr 3, 2024
74486a1
refactor: update transaction and router logics
enesozturk Apr 3, 2024
b738d98
chore: make sure about component exports
enesozturk Apr 3, 2024
25b1a7d
chore: update transaction stack callbacks
enesozturk Apr 3, 2024
4258418
chore: add missing exported composites
enesozturk Apr 3, 2024
d054a5c
chore: update lock file
enesozturk Apr 3, 2024
32e5d57
Merge branch 'V4' into feat/1inch-swaps
enesozturk Apr 4, 2024
0f43f7b
chore: update token fetch listeners
enesozturk Apr 5, 2024
7a21054
chore: update intervals
enesozturk Apr 5, 2024
17701e2
Merge branch 'V4' into feat/convert
enesozturk Apr 8, 2024
b97d069
chore: fix ui comp exports and conflicts
enesozturk Apr 8, 2024
e52483b
chore: remove scaffold components from ui package
enesozturk Apr 8, 2024
d6a7900
fix: convert components and styles
enesozturk Apr 8, 2024
18baf26
feat: add unit tests for convert, fix router controller tests
enesozturk Apr 8, 2024
ca72aed
chore: linter issues
enesozturk Apr 8, 2024
0460fec
Merge branch 'V4' into feat/convert
enesozturk Apr 9, 2024
17b0bdb
Merge branch 'V4' into feat/convert
enesozturk Apr 11, 2024
2dcfaf5
Merge branch 'V4' into feat/convert
enesozturk Apr 11, 2024
1f53b1c
Merge branch 'feat/convert' of https://github.com/WalletConnect/web3m…
enesozturk Apr 11, 2024
46c986e
Merge branch 'V4' into feat/convert
enesozturk Apr 14, 2024
43c29c6
chore: remove swap from default w3m and remove toast on cancel transa…
enesozturk Apr 15, 2024
647e7ae
refactor: convert input text color
enesozturk Apr 15, 2024
aa9374d
chore: switch to blockchain api for convert tokens and balance
enesozturk Apr 15, 2024
99db707
Merge branch 'V4' into feat/convert
enesozturk Apr 16, 2024
03a07fd
refactor: switch to blockchain api for convert endpoints
enesozturk Apr 16, 2024
0645a37
refactor: update type definitions
enesozturk Apr 17, 2024
e9ab90f
refactor: approve tx params and type updates
enesozturk Apr 17, 2024
80c01d6
Merge branch 'V4' into feat/convert
enesozturk Apr 18, 2024
246b340
refactor: blockchain api switching done
enesozturk Apr 19, 2024
7b1706a
refactor: remove 1inch endpoints, linter issues and general refactor
enesozturk Apr 19, 2024
463d674
refactor: code review updates
enesozturk Apr 19, 2024
458b9bc
refactor: code review improvements
enesozturk Apr 19, 2024
885a275
chore: estimate gas naming
enesozturk Apr 19, 2024
11601bc
Merge branch 'V4' into feat/convert
enesozturk Apr 19, 2024
5f6f129
feat: add regex util for checking transactions
enesozturk Apr 19, 2024
204dc8e
chore: linter issues
enesozturk Apr 19, 2024
bf9e857
fix: ethers onrpcresponse function param
enesozturk Apr 19, 2024
418bc74
chore: remove unused core method
enesozturk Apr 19, 2024
05e017a
refactor: rpc response logics
enesozturk Apr 19, 2024
1cd5b54
Merge branch 'V4' into feat/convert
enesozturk Apr 19, 2024
3d47f7e
refactor: add long tx hash handling to rpc response handler
enesozturk Apr 22, 2024
b7ca507
chore: update regex name
enesozturk Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions packages/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
Token
} from '@web3modal/scaffold'
import { Web3ModalScaffold } from '@web3modal/scaffold'
import { ConstantsUtil, PresetsUtil, HelpersUtil, RegexUtil } from '@web3modal/scaffold-utils'
import { ConstantsUtil, PresetsUtil, HelpersUtil } from '@web3modal/scaffold-utils'
import EthereumProvider from '@walletconnect/ethereum-provider'
import type { Web3ModalSIWEClient } from '@web3modal/siwe'
import type {
Expand All @@ -38,7 +38,12 @@ import {
} from '@web3modal/scaffold-utils/ethers'
import type { EthereumProviderOptions } from '@walletconnect/ethereum-provider'
import type { Eip1193Provider } from 'ethers'
import { W3mFrameProvider, W3mFrameHelpers, W3mFrameRpcConstants } from '@web3modal/wallet'
import {
W3mFrameProvider,
W3mFrameHelpers,
W3mFrameRpcConstants,
W3mFrameConstants
} from '@web3modal/wallet'
import type { CombinedProvider } from '@web3modal/scaffold-utils/ethers'
import { BrowserProvider } from 'ethers'
import { JsonRpcSigner } from 'ethers'
Expand Down Expand Up @@ -842,32 +847,32 @@ export class Web3Modal extends Web3ModalScaffold {
}, 300)
}
})
this.emailProvider.onRpcResponse(receive => {
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment
// @ts-ignore
const payload = receive?.payload
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment
// @ts-ignore
const isError = receive?.type === '@w3m-frame/RPC_REQUEST_ERROR'

if (isError && super.isOpen()) {
if (super.isTransactionStackEmpty()) {
super.close()
} else {
super.popTransactionStack(true)
this.emailProvider.onRpcResponse(response => {
const responseType = W3mFrameHelpers.getResponseType(response)

switch (responseType) {
case W3mFrameConstants.RPC_RESPONSE_TYPE_ERROR: {
const isModalOpen = super.isOpen()

if (isModalOpen) {
if (super.isTransactionStackEmpty()) {
super.close()
} else {
super.popTransactionStack(true)
}
}
break
}
}

const isPayloadString = typeof payload === 'string'
const isAddress = isPayloadString ? payload?.startsWith('0x') : false
const isCompleted = isAddress && payload?.match(RegexUtil.transactionHashRegex)

if (isCompleted) {
if (super.isTransactionStackEmpty()) {
super.close()
} else {
super.popTransactionStack()
case W3mFrameConstants.RPC_RESPONSE_TYPE_TX: {
if (super.isTransactionStackEmpty()) {
super.close()
} else {
super.popTransactionStack()
}
break
}
default:
break
}
})
this.emailProvider.onNotConnected(() => {
Expand Down
1 change: 0 additions & 1 deletion packages/scaffold-utils/exports/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { ConstantsUtil } from '../src/ConstantsUtil.js'
export { PresetsUtil } from '../src/PresetsUtil.js'
export { HelpersUtil } from '../src/HelpersUtil.js'
export { RegexUtil } from '../src/RegexUtil.js'
4 changes: 0 additions & 4 deletions packages/scaffold-utils/src/RegexUtil.ts

This file was deleted.

50 changes: 25 additions & 25 deletions packages/wagmi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import { formatUnits, parseUnits } from 'viem'
import type { Hex } from 'viem'
import { Web3ModalScaffold } from '@web3modal/scaffold'
import type { Web3ModalSIWEClient } from '@web3modal/siwe'
import { ConstantsUtil, PresetsUtil, HelpersUtil, RegexUtil } from '@web3modal/scaffold-utils'
import { ConstantsUtil, PresetsUtil, HelpersUtil } from '@web3modal/scaffold-utils'
import {
getCaipDefaultChain,
getEmailCaipNetworks,
getWalletConnectCaipNetworks
} from './utils/helpers.js'
import { W3mFrameHelpers, W3mFrameRpcConstants } from '@web3modal/wallet'
import { W3mFrameConstants, W3mFrameHelpers, W3mFrameRpcConstants } from '@web3modal/wallet'
import type { W3mFrameProvider, W3mFrameTypes } from '@web3modal/wallet'
import { NetworkUtil } from '@web3modal/common'
import type { defaultWagmiConfig as coreConfig } from './utils/defaultWagmiCoreConfig.js'
Expand Down Expand Up @@ -493,32 +493,32 @@ export class Web3Modal extends Web3ModalScaffold {
}
})

provider.onRpcResponse(receive => {
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment
// @ts-ignore
const payload = receive?.payload
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment
// @ts-ignore
const isError = receive?.type === '@w3m-frame/RPC_REQUEST_ERROR'

if (isError && super.isOpen()) {
if (super.isTransactionStackEmpty()) {
super.close()
} else {
super.popTransactionStack(true)
}
}
provider.onRpcResponse(response => {
const responseType = W3mFrameHelpers.getResponseType(response)

const isPayloadString = typeof payload === 'string'
const isAddress = isPayloadString ? payload?.startsWith('0x') : false
const isCompleted = isAddress && payload?.match(RegexUtil.transactionHashRegex)
switch (responseType) {
enesozturk marked this conversation as resolved.
Show resolved Hide resolved
case W3mFrameConstants.RPC_RESPONSE_TYPE_ERROR: {
const isModalOpen = super.isOpen()

if (isCompleted) {
if (super.isTransactionStackEmpty()) {
super.close()
} else {
super.popTransactionStack()
if (isModalOpen) {
if (super.isTransactionStackEmpty()) {
super.close()
} else {
super.popTransactionStack(true)
}
}
break
}
case W3mFrameConstants.RPC_RESPONSE_TYPE_TX: {
if (super.isTransactionStackEmpty()) {
super.close()
} else {
super.popTransactionStack()
}
break
}
default:
break
}
})

Expand Down
6 changes: 5 additions & 1 deletion packages/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export { W3mFrame } from './src/W3mFrame.js'
export { W3mFrameHelpers } from './src/W3mFrameHelpers.js'
export { W3mFrameProvider } from './src/W3mFrameProvider.js'
export { W3mFrameSchema } from './src/W3mFrameSchema.js'
export { W3mFrameConstants, W3mFrameRpcConstants } from './src/W3mFrameConstants.js'
export {
W3mFrameConstants,
W3mFrameRpcConstants,
type W3mFrameConstantValue
} from './src/W3mFrameConstants.js'
export { W3mFrameStorage } from './src/W3mFrameStorage.js'
export type { W3mFrameTypes } from './src/W3mFrameTypes.js'
4 changes: 4 additions & 0 deletions packages/wallet/src/RegexUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const RegexUtil = {
address: /^0x(?:[A-Fa-f0-9]{40})$/u,
transactionHash: /^0x(?:[A-Fa-f0-9]{64})$/u
}
4 changes: 2 additions & 2 deletions packages/wallet/src/W3mFrame.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { W3mFrameConstants } from './W3mFrameConstants.js'
import { SECURE_SITE_SDK, W3mFrameConstants } from './W3mFrameConstants.js'
import { W3mFrameSchema } from './W3mFrameSchema.js'
import { W3mFrameHelpers } from './W3mFrameHelpers.js'
import type { W3mFrameTypes } from './W3mFrameTypes.js'
Expand Down Expand Up @@ -34,7 +34,7 @@ export class W3mFrame {
if (W3mFrameHelpers.isClient) {
const iframe = document.createElement('iframe')
iframe.id = 'w3m-iframe'
iframe.src = `${W3mFrameConstants.SECURE_SITE_SDK}?projectId=${projectId}`
iframe.src = `${SECURE_SITE_SDK}?projectId=${projectId}`
iframe.style.position = 'fixed'
iframe.style.zIndex = '999999'
iframe.style.display = 'none'
Expand Down
13 changes: 10 additions & 3 deletions packages/wallet/src/W3mFrameConstants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const SECURE_SITE_SDK =
enesozturk marked this conversation as resolved.
Show resolved Hide resolved
process.env['NEXT_PUBLIC_SECURE_SITE_SDK_URL'] || 'https://secure.walletconnect.com/sdk'

export const W3mFrameConstants = {
SECURE_SITE_SDK:
process.env['NEXT_PUBLIC_SECURE_SITE_SDK_URL'] || 'https://secure.walletconnect.com/sdk',
APP_EVENT_KEY: '@w3m-app/',
FRAME_EVENT_KEY: '@w3m-frame/',
RPC_METHOD_KEY: 'RPC_',
Expand Down Expand Up @@ -70,9 +71,15 @@ export const W3mFrameConstants = {
FRAME_INIT_SMART_ACCOUNT_SUCCESS: '@w3m-frame/INIT_SMART_ACCOUNT_SUCCESS',
FRAME_INIT_SMART_ACCOUNT_ERROR: '@w3m-frame/INIT_SMART_ACCOUNT_ERROR',
FRAME_SET_PREFERRED_ACCOUNT_SUCCESS: '@w3m-frame/SET_PREFERRED_ACCOUNT_SUCCESS',
FRAME_SET_PREFERRED_ACCOUNT_ERROR: '@w3m-frame/SET_PREFERRED_ACCOUNT_ERROR'
FRAME_SET_PREFERRED_ACCOUNT_ERROR: '@w3m-frame/SET_PREFERRED_ACCOUNT_ERROR',

RPC_RESPONSE_TYPE_ERROR: 'RPC_RESPONSE_ERROR',
RPC_RESPONSE_TYPE_TX: 'RPC_RESPONSE_TRANSACTION_HASH',
RPC_RESPONSE_TYPE_OBJECT: 'RPC_RESPONSE_OBJECT'
} as const

export type W3mFrameConstantValue = (typeof W3mFrameConstants)[keyof typeof W3mFrameConstants]

export const W3mFrameRpcConstants = {
SAFE_RPC_METHODS: [
'eth_accounts',
Expand Down
29 changes: 28 additions & 1 deletion packages/wallet/src/W3mFrameHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { W3mFrameStorage } from './W3mFrameStorage.js'
import { W3mFrameConstants, W3mFrameRpcConstants } from './W3mFrameConstants.js'
import {
W3mFrameConstants,
W3mFrameRpcConstants,
type W3mFrameConstantValue
} from './W3mFrameConstants.js'
import type { W3mFrameTypes } from './W3mFrameTypes.js'
import { RegexUtil } from './RegexUtil.js'

const RESTRICTED_TIMEZONES = [
'ASIA/SHANGHAI',
Expand Down Expand Up @@ -67,6 +72,28 @@ export const W3mFrameHelpers = {
return (request as { payload: W3mFrameTypes.RPCRequest })?.payload?.method
},

getResponseType(response: unknown) {
enesozturk marked this conversation as resolved.
Show resolved Hide resolved
const { type, payload } = response as {
type: W3mFrameConstantValue
payload: W3mFrameTypes.RPCResponse
}

const isError = type === W3mFrameConstants.FRAME_RPC_REQUEST_ERROR

if (isError) {
return W3mFrameConstants.RPC_RESPONSE_TYPE_ERROR
}

const isPayloadString = typeof payload === 'string'
const isTransactionHash = isPayloadString && payload.match(RegexUtil.transactionHash)

if (isTransactionHash) {
return W3mFrameConstants.RPC_RESPONSE_TYPE_TX
}

return W3mFrameConstants.RPC_RESPONSE_TYPE_OBJECT
},

checkIfRequestIsAllowed(request: unknown) {
const method = this.getRequestMethod(request)

Expand Down
Loading