-
Notifications
You must be signed in to change notification settings - Fork 985
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(wallet): add ability to send a token #18242
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
(:require | ||
[quo.components.avatars.account-avatar.view :as account-avatar] | ||
[quo.components.avatars.user-avatar.view :as user-avatar] | ||
[quo.components.avatars.wallet-user-avatar.view :as wallet-user-avatar] | ||
[quo.components.markdown.text :as text] | ||
[quo.components.wallet.summary-info.style :as style] | ||
[quo.foundations.colors :as colors] | ||
|
@@ -26,33 +27,43 @@ | |
|
||
(defn networks | ||
[values theme] | ||
(let [{:keys [ethereum optimism arbitrum]} values] | ||
(let [{:keys [ethereum optimism arbitrum]} values | ||
show-optimism? (pos? optimism) | ||
show-arbitrum? (pos? arbitrum)] | ||
[rn/view | ||
{:style style/networks-container | ||
:accessibility-label :networks} | ||
[network-amount | ||
{:network :ethereum | ||
:amount (str ethereum " ETH") | ||
:divider? true | ||
:theme theme}] | ||
[network-amount | ||
{:network :optimism | ||
:amount (str optimism " ETH") | ||
:divider? true | ||
:theme theme}] | ||
[network-amount | ||
{:network :arbitrum | ||
:amount (str arbitrum " ETH") | ||
:theme theme}]])) | ||
(when (pos? ethereum) | ||
[network-amount | ||
{:network :ethereum | ||
:amount (str ethereum " ETH") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a place to extract these strings ("ETH", "OPT", etc) by network name (e.g. :optimism) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to revisit how this component is working - I will create a follow up issue for this. For this pr it goes outside of the scope and send already is a huge feature set. imo the quo components should have no knowledge of networks and should just render the UI. |
||
:divider? (or show-arbitrum? show-optimism?) | ||
:theme theme}]) | ||
(when show-optimism? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the designs only show these if they have a value. We could also look to remove network specific details out of this component and make it more generic but it's for another pr as this work is already growing too large. |
||
[network-amount | ||
{:network :optimism | ||
:amount (str optimism " OPT") | ||
:divider? show-arbitrum? | ||
:theme theme}]) | ||
(when show-arbitrum? | ||
[network-amount | ||
{:network :arbitrum | ||
:amount (str arbitrum " ARB") | ||
:theme theme}])])) | ||
|
||
(defn- view-internal | ||
[{:keys [theme type account-props networks? values]}] | ||
[rn/view | ||
{:style (style/container networks? theme)} | ||
[rn/view | ||
{:style style/info-container} | ||
(if (= type :status-account) | ||
[account-avatar/view account-props] | ||
(case type | ||
:status-account [account-avatar/view account-props] | ||
:saved-account [wallet-user-avatar/wallet-user-avatar (assoc account-props :size :size-32)] | ||
:account [wallet-user-avatar/wallet-user-avatar | ||
(assoc account-props | ||
:size :size-32 | ||
:neutral? true)] | ||
[user-avatar/user-avatar account-props]) | ||
[rn/view {:style {:margin-left 8}} | ||
(when (not= type :account) [text/text {:weight :semi-bold} (:name account-props)]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
(ns status-im.contexts.wallet.send.events | ||
(:require | ||
[camel-snake-kebab.core :as csk] | ||
[camel-snake-kebab.extras :as cske] | ||
[status-im.constants :as constants] | ||
[status-im.contexts.wallet.send.utils :as send-utils] | ||
[taoensso.timbre :as log] | ||
[utils.money :as money] | ||
[utils.number] | ||
[utils.re-frame :as rf])) | ||
|
||
(rf/reg-event-fx :wallet/select-address-tab | ||
(fn [{:keys [db]} [tab]] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will delete empty line 👍 |
||
{:db (assoc-in db [:wallet :ui :send :select-address-tab] tab)})) | ||
|
||
(rf/reg-event-fx :wallet/select-send-account-address | ||
|
@@ -17,10 +21,14 @@ | |
(rf/reg-event-fx :wallet/suggested-routes-success | ||
(fn [{:keys [db]} [suggested-routes timestamp]] | ||
(when (= (get-in db [:wallet :ui :send :suggested-routes-call-timestamp]) timestamp) | ||
{:db (-> db | ||
(assoc-in [:wallet :ui :send :suggested-routes] suggested-routes) | ||
(assoc-in [:wallet :ui :send :route] (first (:Best suggested-routes))) | ||
(assoc-in [:wallet :ui :send :loading-suggested-routes?] false))}))) | ||
(let [suggested-routes-data (cske/transform-keys csk/->kebab-case suggested-routes) | ||
chosen-route (->> suggested-routes-data | ||
:best | ||
first)] | ||
{:db (-> db | ||
(assoc-in [:wallet :ui :send :suggested-routes] suggested-routes-data) | ||
(assoc-in [:wallet :ui :send :route] chosen-route) | ||
(assoc-in [:wallet :ui :send :loading-suggested-routes?] false))})))) | ||
|
||
(rf/reg-event-fx :wallet/suggested-routes-error | ||
(fn [{:keys [db]} [_error]] | ||
|
@@ -47,8 +55,9 @@ | |
:fx [[:navigate-to-within-stack [:wallet-send-input-amount stack-id]]]})) | ||
|
||
(rf/reg-event-fx :wallet/send-select-amount | ||
(fn [{:keys [db]} [{:keys [amount]}]] | ||
{:db (assoc-in db [:wallet :ui :send :amount] amount)})) | ||
(fn [{:keys [db]} [{:keys [amount stack-id]}]] | ||
{:db (assoc-in db [:wallet :ui :send :amount] amount) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
:fx [[:navigate-to-within-stack [:wallet-transaction-confirmation stack-id]]]})) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😎 |
||
|
||
(rf/reg-event-fx :wallet/get-suggested-routes | ||
(fn [{:keys [db now]} [amount]] | ||
|
@@ -59,7 +68,7 @@ | |
token-id (:symbol token) | ||
network-preferences [] | ||
gas-rates constants/gas-rate-medium | ||
amount-in (money/amount-in-hex amount token-decimal) | ||
amount-in (send-utils/amount-in-hex amount token-decimal) | ||
from-address wallet-address | ||
disabled-from-chain-ids [] | ||
disabled-to-chain-ids [] | ||
|
@@ -88,3 +97,69 @@ | |
{:event :wallet/get-suggested-routes | ||
:error error | ||
:params request-params}))}]}))) | ||
|
||
(rf/reg-event-fx :wallet/add-authorized-transaction | ||
(fn [{:keys [db]} [transaction]] | ||
(let [transaction-hashes (:hashes transaction) | ||
chain-id (key (first transaction-hashes)) | ||
tx-id (first (val (first transaction-hashes))) | ||
Comment on lines
+103
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we only get the first item? what is contained in the rest of them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah this is a temporary solution, will adjust properly when we go to implement the transaction progress page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed with @ulisesmac - will create an issue for this feature and mention this needs to be reworked. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
transaction-detes {:status :pending | ||
ulisesmac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:id (:id transaction) | ||
:chain-id chain-id}] | ||
{:db (assoc-in db [:wallet :transactions tx-id] transaction-detes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a question here, Are transactions associated to an account? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's discuss this today! |
||
:fx [[:dispatch [:navigate-to :wallet-transaction-progress]]]}))) | ||
|
||
(defn- transaction-bridge | ||
[{:keys [from-address to-address route]}] | ||
(let [{:keys [from bridge-name amount-out gas-amount gas-fees]} route | ||
{:keys [gas-price max-fee-per-gas-medium max-priority-fee-per-gas]} gas-fees] | ||
[{:BridgeName bridge-name | ||
:ChainID (:chain-id from) | ||
:TransferTx {:From from-address | ||
:To to-address | ||
:Gas (money/to-hex gas-amount) | ||
:GasPrice (money/to-hex (money/->wei :gwei gas-price)) | ||
:Value amount-out | ||
:Nonce nil | ||
:MaxFeePerGas (money/to-hex (money/->wei :gwei max-fee-per-gas-medium)) | ||
:MaxPriorityFeePerGas (money/to-hex (money/->wei :gwei max-priority-fee-per-gas)) | ||
:Input "" | ||
:Data "0x"}}])) | ||
|
||
(defn- multi-transaction-command | ||
[{:keys [from-address to-address from-asset to-asset amount-out transfer-type] | ||
:or {transfer-type constants/send-type-transfer}}] | ||
{:fromAddress from-address | ||
:toAddress to-address | ||
:fromAsset from-asset | ||
:toAsset to-asset | ||
:fromAmount amount-out | ||
:type transfer-type}) | ||
|
||
(rf/reg-event-fx :wallet/send-transaction | ||
(fn [{:keys [db]} [sha3-pwd]] | ||
Comment on lines
+139
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really nice 👍 💯 |
||
(let [route (get-in db [:wallet :ui :send :route]) | ||
from-address (get-in db [:wallet :current-viewing-account-address]) | ||
to-address (get-in db [:wallet :ui :send :to-address]) | ||
token (get-in db [:wallet :ui :send :token]) | ||
token-id (:symbol token) | ||
request-params [(multi-transaction-command {:from-address from-address | ||
:to-address to-address | ||
:from-asset token-id | ||
:to-asset token-id | ||
:amount-out (:amount-out route)}) | ||
(transaction-bridge {:to-address to-address | ||
:from-address from-address | ||
:route route}) | ||
sha3-pwd]] | ||
{:json-rpc/call [{:method "wallet_createMultiTransaction" | ||
:params request-params | ||
:on-success (fn [result] | ||
(rf/dispatch [:hide-bottom-sheet]) | ||
(rf/dispatch [:wallet/add-authorized-transaction result])) | ||
:on-error (fn [error] | ||
(log/error "failed to send transaction" | ||
{:event :wallet/send-transaction | ||
:error error | ||
:params request-params}))}]}))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ulisesmac & I found a bug where empty tokens didn't sit right, this fix that 👍