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

(Deposit/Withdraw) Allow Selecting a Custom Withdraw Address #3453

Merged

Conversation

JoseRFelix
Copy link
Collaborator

@JoseRFelix JoseRFelix commented Jul 5, 2024

Description

This PR introduces the ability to add a custom address for withdrawals. It also makes wallet connection and switching entirely predictable and imperative by not relying on useEffects.

Linear Task

Linear Task URL

Copy link

vercel bot commented Jul 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
osmosis-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 8, 2024 6:40pm
osmosis-frontend-edgenet 🔄 Building (Inspect) Visit Preview 💬 Add feedback Jul 8, 2024 6:40pm
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
osmosis-frontend-datadog ⬜️ Ignored (Inspect) Visit Preview Jul 8, 2024 6:40pm
osmosis-frontend-dev ⬜️ Ignored (Inspect) Visit Preview Jul 8, 2024 6:40pm
osmosis-testnet ⬜️ Ignored (Inspect) Visit Preview Jul 8, 2024 6:40pm

@JoseRFelix JoseRFelix changed the title feat: add send address modal (Deposit/Withdraw) Allow Selecting a Custom Withdraw Address Jul 5, 2024
@JoseRFelix JoseRFelix requested review from jonator and a team July 5, 2024 23:30
@JoseRFelix JoseRFelix marked this pull request as ready for review July 5, 2024 23:55
Copy link
Contributor

coderabbitai bot commented Jul 5, 2024

Walkthrough

The updates across multiple files primarily enhance the functionality of the bridge package by refining address handling, improving chain-type management, and integrating new utilities for address validation. Key components like AmountAndReviewScreen and modals such as BridgeNetworkSelectModal and BridgeWalletSelectModal now support manual address input, giving users more flexibility. Additionally, a new TextareaBox component was introduced for enhanced textual input handling, along with corresponding styling and interaction options.

Changes

File(s) Change Summary
packages/bridge/src/skip/__tests__/skip-bridge-provider.spec.ts Updated test to check for equality with [fromAddress, toAddress] instead of just fromAddress.
packages/bridge/src/skip/index.ts Refined conditions for handling chain types based on chain ID comparisons in SkipBridgeProvider.
packages/utils/src/string.ts Added isEvmAddressValid and isCosmosAddressValid functions for address validation.
packages/web/components/bridge/immersive/amount-and-review-screen.tsx Introduced manualToAddress state for manual address input, affecting address selection and transfer confirmation.
packages/web/components/input/index.ts Added export for textarea-box.
packages/web/components/input/textarea-box.tsx Introduced TextareaBox component with customizable styling and interaction options.
packages/web/components/bridge/immersive/bridge-network-select-modal.tsx Added props (toChain, onConfirmManualAddress, initialManualAddress), affecting behavior and rendering logic.
packages/web/components/bridge/immersive/bridge-wallet-select-modal.tsx Added functionality for wallet selection and address verification including new SendToAnotherAddressForm component.
packages/web/components/bridge/immersive/review-screen.tsx Included isManualAddress prop in ReviewScreen, affecting wallet image rendering.
packages/web/hooks/use-connect-wallet-modal-redirect.tsx Made _onRequestClose optional and added onConnect parameter.
packages/web/hooks/use-wallet-select.tsx Introduced optional onConnect callback in WalletSelectParams, invoked post-connect.
packages/web/server/api/routers/bridge-transfer.ts Updated BridgeChainWithDisplayInfo type with conditional chain type properties and included bech32Prefix for "cosmos" chains.
packages/web/tailwind.config.js Added 500: "#CC54C2" color code to ammelia palette.
packages/web/components/bridge/immersive/crypto-fiat-input.tsx Added BridgeChainWithDisplayInfo import and fromChain prop to CryptoFiatInput component.

Sequence Diagram(s)

Manual Address Input and Transfer Confirmation

sequenceDiagram
  participant User
  participant AmountAndReviewScreen
  participant BridgeTransferForm
  participant BridgeNetworkSelectModal
  participant BridgeWalletSelectModal
  participant TransferService

  User ->> AmountAndReviewScreen: Enter manualToAddress
  AmountAndReviewScreen ->> BridgeTransferForm: Propagate manualToAddress
  BridgeTransferForm ->> BridgeNetworkSelectModal: Open modal
  BridgeNetworkSelectModal ->> User: Ask for manual address confirmation
  User ->> BridgeNetworkSelectModal: Confirm manual address
  BridgeNetworkSelectModal ->> AmountAndReviewScreen: Return confirmed address
  AmountAndReviewScreen ->> BridgeWalletSelectModal: Open wallet select modal
  BridgeWalletSelectModal ->> User: Show wallet options
  User ->> BridgeWalletSelectModal: Select wallet
  BridgeWalletSelectModal ->> AmountAndReviewScreen: Confirm wallet and address
  AmountAndReviewScreen ->> TransferService: Initiate transfer
  TransferService ->> User: Provide transfer status
Loading

Updated Chain Type and ID Logic Handling in SkipBridgeProvider

sequenceDiagram
  participant SkipBridgeProvider
  participant ChainService
  participant LogService

  SkipBridgeProvider ->> ChainService: Get fromChain and toChain
  ChainService -->> SkipBridgeProvider: Return chain info
  SkipBridgeProvider ->> SkipBridgeProvider: Evaluate chain type and ID
  alt if conditions met
    SkipBridgeProvider ->> SkipBridgeProvider: Add addresses to addressList
    LogService ->> SkipBridgeProvider: Log successful condition
  else conditions not met
    SkipBridgeProvider ->> SkipBridgeProvider: Skip address addition
    LogService ->> SkipBridgeProvider: Log condition failure
  end
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a9178f7 and b3afec6.

Files selected for processing (1)
  • packages/web/components/bridge/immersive/crypto-fiat-input.tsx (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/web/components/bridge/immersive/crypto-fiat-input.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (1)
packages/web/components/input/textarea-box.tsx (1)

93-93: Consider using optional chaining.

The static analysis tool suggests using optional chaining for better readability and safety.

-            onBlur && onBlur(e);
+            onBlur?.(e);

-            onFocus && onFocus(e);
+            onFocus?.(e);

Also applies to: 97-97

Tools
Biome

[error] 93-93: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Comment on lines +84 to +87
const enum WalletSelectScreens {
WalletSelect = "wallet-select",
SendToAnotherAddress = "send-to-another-address",
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert const enum to regular enum.

Const enums are not supported by bundlers and are incompatible with the 'isolatedModules' mode.

- const enum WalletSelectScreens {
+ enum WalletSelectScreens {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const enum WalletSelectScreens {
WalletSelect = "wallet-select",
SendToAnotherAddress = "send-to-another-address",
}
enum WalletSelectScreens {
WalletSelect = "wallet-select",
SendToAnotherAddress = "send-to-another-address",
}
Tools
Biome

[error] 83-87: The enum declaration should not be const

Const enums are not supported by bundlers and are incompatible with the 'isolatedModules' mode. Their use can lead to import inexistent values.
See TypeScript Docs for more details.
Safe fix: Turn the const enum into a regular enum.

(lint/suspicious/noConstEnum)

Copy link
Member

@jonator jonator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial comments. BTW for some reason when I select an asset to withdraw, the page freezes and chrome suggests killing the page. Perhaps it's stuck in an infinite loop or something?

@JoseRFelix JoseRFelix requested a review from jonator July 8, 2024 18:11
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (2)
packages/web/components/bridge/immersive/amount-screen.tsx (2)

Line range hint 188-304:
Optimize the boolean check.

Avoid redundant double-negation when a value will already be coerced to a boolean.

-  if (!!account?.address) {
+  if (account?.address) {
Tools
Biome

[error] 280-280: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)


Line range hint 106-120:
Simplify nested conditional rendering.

The nested conditional rendering can be simplified for better readability.

-  if (readonly) {
-    return (
-      <div className="subtitle1 flex w-[45%] flex-1 items-center gap-2 rounded-[48px] border border-osmoverse-700 py-2 px-4 text-osmoverse-200">
-        <ChainLogo prettyName="" logoUri={chainLogo} color={chainColor} />
-        <span className="truncate">{children}</span>
-      </div>
-    );
-  }
+  return readonly ? (
+    <div className="subtitle1 flex w-[45%] flex-1 items-center gap-2 rounded-[48px] border border-osmoverse-700 py-2 px-4 text-osmoverse-200">
+      <ChainLogo prettyName="" logoUri={chainLogo} color={chainColor} />
+      <span className="truncate">{children}</span>
+    </div>
+  ) : (

Comment on lines +55 to +112
return (
<div
className={classNames(
"flex h-fit w-full flex-nowrap justify-between rounded-lg bg-osmoverse-1000 px-2 text-white-high",
{
border: style !== "no-border",
"border-osmoverse-200":
style !== "no-border" && (style === "active" || textareaFocused),
"border-osmoverse-1000":
style !== "no-border" && style === "enabled" && !textareaFocused,
"border-missionError": style === "error",
"cursor-default border-white-disabled bg-osmoverse-800": disabled,
},
className
)}
>
<div className={classNames("flex w-full shrink grow", classes?.label)}>
<textarea
id={id}
key={textareaKey}
ref={textareaRef}
className={classNames(
"md:leading-0 w-full resize-none appearance-none bg-transparent pt-px align-middle leading-10 outline-none placeholder:text-osmoverse-500 md:p-0",
{
"text-white-disabled": disabled,
"text-white-high": currentValue != "" && !disabled,
"float-right text-right": rightEntry,
"pr-1": !trailingSymbol,
},
classes?.textarea
)}
value={textareaValue}
placeholder={placeholder ?? ""}
autoComplete="off"
onBlur={(e: any) => {
setTextareaFocused(false);
onBlur && onBlur(e);
}}
onFocus={(e: any) => {
setTextareaFocused(true);
onFocus && onFocus(e);
}}
onInput={(e: any) => setValue(e.target.value)}
disabled={disabled}
autoFocus={autoFocus}
rows={rows}
data-1p-ignore
data-enable-grammarly="false"
/>

{trailingSymbol && (
<span className={classNames("pt-3", classes?.trailingSymbol)}>
{trailingSymbol}
</span>
)}
</div>
</div>
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use optional chaining for safety and clarity.

Consider using optional chaining for onBlur and onFocus handlers to avoid potential runtime errors.

-  onBlur={(e: any) => {
-    setTextareaFocused(false);
-    onBlur && onBlur(e);
-  }}
+  onBlur={(e: any) => {
+    setTextareaFocused(false);
+    onBlur?.(e);
+  }}
-  onFocus={(e: any) => {
-    setTextareaFocused(true);
-    onFocus && onFocus(e);
-  }}
+  onFocus={(e: any) => {
+    setTextareaFocused(true);
+    onFocus?.(e);
+  }}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return (
<div
className={classNames(
"flex h-fit w-full flex-nowrap justify-between rounded-lg bg-osmoverse-1000 px-2 text-white-high",
{
border: style !== "no-border",
"border-osmoverse-200":
style !== "no-border" && (style === "active" || textareaFocused),
"border-osmoverse-1000":
style !== "no-border" && style === "enabled" && !textareaFocused,
"border-missionError": style === "error",
"cursor-default border-white-disabled bg-osmoverse-800": disabled,
},
className
)}
>
<div className={classNames("flex w-full shrink grow", classes?.label)}>
<textarea
id={id}
key={textareaKey}
ref={textareaRef}
className={classNames(
"md:leading-0 w-full resize-none appearance-none bg-transparent pt-px align-middle leading-10 outline-none placeholder:text-osmoverse-500 md:p-0",
{
"text-white-disabled": disabled,
"text-white-high": currentValue != "" && !disabled,
"float-right text-right": rightEntry,
"pr-1": !trailingSymbol,
},
classes?.textarea
)}
value={textareaValue}
placeholder={placeholder ?? ""}
autoComplete="off"
onBlur={(e: any) => {
setTextareaFocused(false);
onBlur && onBlur(e);
}}
onFocus={(e: any) => {
setTextareaFocused(true);
onFocus && onFocus(e);
}}
onInput={(e: any) => setValue(e.target.value)}
disabled={disabled}
autoFocus={autoFocus}
rows={rows}
data-1p-ignore
data-enable-grammarly="false"
/>
{trailingSymbol && (
<span className={classNames("pt-3", classes?.trailingSymbol)}>
{trailingSymbol}
</span>
)}
</div>
</div>
);
return (
<div
className={classNames(
"flex h-fit w-full flex-nowrap justify-between rounded-lg bg-osmoverse-1000 px-2 text-white-high",
{
border: style !== "no-border",
"border-osmoverse-200":
style !== "no-border" && (style === "active" || textareaFocused),
"border-osmoverse-1000":
style !== "no-border" && style === "enabled" && !textareaFocused,
"border-missionError": style === "error",
"cursor-default border-white-disabled bg-osmoverse-800": disabled,
},
className
)}
>
<div className={classNames("flex w-full shrink grow", classes?.label)}>
<textarea
id={id}
key={textareaKey}
ref={textareaRef}
className={classNames(
"md:leading-0 w-full resize-none appearance-none bg-transparent pt-px align-middle leading-10 outline-none placeholder:text-osmoverse-500 md:p-0",
{
"text-white-disabled": disabled,
"text-white-high": currentValue != "" && !disabled,
"float-right text-right": rightEntry,
"pr-1": !trailingSymbol,
},
classes?.textarea
)}
value={textareaValue}
placeholder={placeholder ?? ""}
autoComplete="off"
onBlur={(e: any) => {
setTextareaFocused(false);
onBlur?.(e);
}}
onFocus={(e: any) => {
setTextareaFocused(true);
onFocus?.(e);
}}
onInput={(e: any) => setValue(e.target.value)}
disabled={disabled}
autoFocus={autoFocus}
rows={rows}
data-1p-ignore
data-enable-grammarly="false"
/>
{trailingSymbol && (
<span className={classNames("pt-3", classes?.trailingSymbol)}>
{trailingSymbol}
</span>
)}
</div>
</div>
);
Tools
Biome

[error] 91-91: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 95-95: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

@JoseRFelix JoseRFelix merged commit 2a4c5ff into stage Jul 8, 2024
36 of 37 checks passed
@JoseRFelix JoseRFelix deleted the jose/fe-619-allow-selecting-a-custom-withdraw-address branch July 8, 2024 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants