Merge remote-tracking branch 'origin/develop' into chore/2939-add-filters-proposal-table
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
"tranche_id": 56,
|
||||
"tranche_start": "2023-04-20T00:00:00.000Z",
|
||||
"tranche_end": "2023-05-20T00:00:00.000Z",
|
||||
"total_added": "11103.75",
|
||||
"total_added": "12533.75",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "11103.75",
|
||||
"locked_amount": "12533.75",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "50",
|
||||
@@ -41,6 +41,21 @@
|
||||
"amount": "379.5",
|
||||
"user": "0x6536B87D6a31a37645c2E0E948BB1a2166FAcdaE",
|
||||
"tx": "0x6dc1c78046509fc85f149ad55a0683e059f46d53eab51397ff202c22ee55938f"
|
||||
},
|
||||
{
|
||||
"amount": "138",
|
||||
"user": "0x9f709F2b44e14B2832832FC35aC378e41Bf14bBC",
|
||||
"tx": "0x1b2921c481d2af4dead917173e4fc821ca119bc9408460caff9c25ae09e06a3d"
|
||||
},
|
||||
{
|
||||
"amount": "1154",
|
||||
"user": "0x981D29D939cAa4ADC04A5e44224dBB45539E8730",
|
||||
"tx": "0x3e8baadb612f97fd9fa0b4a8f28c57381d87ff43a083117e19d0332e37869a7f"
|
||||
},
|
||||
{
|
||||
"amount": "138",
|
||||
"user": "0xF2c8658Bad7314c3c3c1FED7e300a1691EC4f98A",
|
||||
"tx": "0xa9db9e09f9841a8cbcaf161bf98d32e67f24c2c162f13c364450487ccaf8ebd6"
|
||||
}
|
||||
],
|
||||
"withdrawals": [],
|
||||
@@ -149,6 +164,51 @@
|
||||
"total_tokens": "379.5",
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "379.5"
|
||||
},
|
||||
{
|
||||
"address": "0x9f709F2b44e14B2832832FC35aC378e41Bf14bBC",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "138",
|
||||
"user": "0x9f709F2b44e14B2832832FC35aC378e41Bf14bBC",
|
||||
"tranche_id": 56,
|
||||
"tx": "0x1b2921c481d2af4dead917173e4fc821ca119bc9408460caff9c25ae09e06a3d"
|
||||
}
|
||||
],
|
||||
"withdrawals": [],
|
||||
"total_tokens": "138",
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "138"
|
||||
},
|
||||
{
|
||||
"address": "0x981D29D939cAa4ADC04A5e44224dBB45539E8730",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1154",
|
||||
"user": "0x981D29D939cAa4ADC04A5e44224dBB45539E8730",
|
||||
"tranche_id": 56,
|
||||
"tx": "0x3e8baadb612f97fd9fa0b4a8f28c57381d87ff43a083117e19d0332e37869a7f"
|
||||
}
|
||||
],
|
||||
"withdrawals": [],
|
||||
"total_tokens": "1154",
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "1154"
|
||||
},
|
||||
{
|
||||
"address": "0xF2c8658Bad7314c3c3c1FED7e300a1691EC4f98A",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "138",
|
||||
"user": "0xF2c8658Bad7314c3c3c1FED7e300a1691EC4f98A",
|
||||
"tranche_id": 56,
|
||||
"tx": "0xa9db9e09f9841a8cbcaf161bf98d32e67f24c2c162f13c364450487ccaf8ebd6"
|
||||
}
|
||||
],
|
||||
"withdrawals": [],
|
||||
"total_tokens": "138",
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "138"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -209,9 +269,9 @@
|
||||
"tranche_id": 54,
|
||||
"tranche_start": "2023-04-06T00:00:00.000Z",
|
||||
"tranche_end": "2023-05-06T00:00:00.000Z",
|
||||
"total_added": "8565",
|
||||
"total_added": "8661",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "8565",
|
||||
"locked_amount": "8586.9203819444447973",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "33",
|
||||
@@ -243,6 +303,11 @@
|
||||
"user": "0xf96afaB11e5617560b9183766470B23F45c38C56",
|
||||
"tx": "0x49ab3f37bda02347cb1966e8fa21885a463f09d0593a890e96b2e36dfb8dec49"
|
||||
},
|
||||
{
|
||||
"amount": "96",
|
||||
"user": "0x6324334064d1d807940191C658d925DA7d323b12",
|
||||
"tx": "0x96b16197328b59556848409bcc4ebf1f71648485fabedde2848461247aa4be32"
|
||||
},
|
||||
{
|
||||
"amount": "111",
|
||||
"user": "0x268070d5EEd5b24E34a5F4C17B5482178b18089D",
|
||||
@@ -416,6 +481,21 @@
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "2523"
|
||||
},
|
||||
{
|
||||
"address": "0x6324334064d1d807940191C658d925DA7d323b12",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "96",
|
||||
"user": "0x6324334064d1d807940191C658d925DA7d323b12",
|
||||
"tranche_id": 54,
|
||||
"tx": "0x96b16197328b59556848409bcc4ebf1f71648485fabedde2848461247aa4be32"
|
||||
}
|
||||
],
|
||||
"withdrawals": [],
|
||||
"total_tokens": "96",
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "96"
|
||||
},
|
||||
{
|
||||
"address": "0x268070d5EEd5b24E34a5F4C17B5482178b18089D",
|
||||
"deposits": [
|
||||
@@ -762,8 +842,8 @@
|
||||
"tranche_start": "2023-03-06T00:00:00.000Z",
|
||||
"tranche_end": "2023-04-06T00:00:00.000Z",
|
||||
"total_added": "14099",
|
||||
"total_removed": "165.10784124668",
|
||||
"locked_amount": "224.192208034646958248",
|
||||
"total_removed": "332.88824447236",
|
||||
"locked_amount": "0",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "30",
|
||||
@@ -1537,6 +1617,16 @@
|
||||
"user": "0x6A228Fffda4D1B3C773b9ce38DA43592581b36FC",
|
||||
"tx": "0x5a8d0a823b77eb011079663279e0f2eaf0bd8773114dd6d5bfe65c2ab47680e6"
|
||||
},
|
||||
{
|
||||
"amount": "27.78040322568",
|
||||
"user": "0x6F32AA5A6198329c16e438512F992a0548C856f9",
|
||||
"tx": "0x47ef65d8ea128dfa3308d25fadf4e3b6b2b95a91f98bd074b268c002babf1edf"
|
||||
},
|
||||
{
|
||||
"amount": "140",
|
||||
"user": "0xF3C6c37B9EBB4D21e8bf119841C0e0e296e3EA04",
|
||||
"tx": "0x3af459fccc854056f4a3a3d0223e5b5fec587f2990c0ec48f0f1be65882e5d96"
|
||||
},
|
||||
{
|
||||
"amount": "14.85013776876",
|
||||
"user": "0x6F32AA5A6198329c16e438512F992a0548C856f9",
|
||||
@@ -1775,6 +1865,12 @@
|
||||
}
|
||||
],
|
||||
"withdrawals": [
|
||||
{
|
||||
"amount": "27.78040322568",
|
||||
"user": "0x6F32AA5A6198329c16e438512F992a0548C856f9",
|
||||
"tranche_id": 53,
|
||||
"tx": "0x47ef65d8ea128dfa3308d25fadf4e3b6b2b95a91f98bd074b268c002babf1edf"
|
||||
},
|
||||
{
|
||||
"amount": "14.85013776876",
|
||||
"user": "0x6F32AA5A6198329c16e438512F992a0548C856f9",
|
||||
@@ -1789,8 +1885,8 @@
|
||||
}
|
||||
],
|
||||
"total_tokens": "63",
|
||||
"withdrawn_tokens": "35.00279905878",
|
||||
"remaining_tokens": "27.99720094122"
|
||||
"withdrawn_tokens": "62.78320228446",
|
||||
"remaining_tokens": "0.21679771554"
|
||||
},
|
||||
{
|
||||
"address": "0x8499411Bff99ddE9A02903008F917EEa0E27B42A",
|
||||
@@ -2190,10 +2286,17 @@
|
||||
"tx": "0x46d80a145d2f49ef3152cbfaa6d2bb054deabe21396ab43553a3f076e2db62e1"
|
||||
}
|
||||
],
|
||||
"withdrawals": [],
|
||||
"withdrawals": [
|
||||
{
|
||||
"amount": "140",
|
||||
"user": "0xF3C6c37B9EBB4D21e8bf119841C0e0e296e3EA04",
|
||||
"tranche_id": 53,
|
||||
"tx": "0x3af459fccc854056f4a3a3d0223e5b5fec587f2990c0ec48f0f1be65882e5d96"
|
||||
}
|
||||
],
|
||||
"total_tokens": "140",
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "140"
|
||||
"withdrawn_tokens": "140",
|
||||
"remaining_tokens": "0"
|
||||
},
|
||||
{
|
||||
"address": "0xEb01fF124D71b6C7E6613fd6E0A86c28C733F008",
|
||||
@@ -3551,7 +3654,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "86666.297",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "57815.4286010790859272716",
|
||||
"locked_amount": "57637.4570956972995656974",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "86666.297",
|
||||
@@ -3617,7 +3720,7 @@
|
||||
"tranche_end": "2023-06-01T00:00:00.000Z",
|
||||
"total_added": "2500",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "776.001920533170575",
|
||||
"locked_amount": "765.7060821123321",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "2500",
|
||||
@@ -3738,7 +3841,7 @@
|
||||
"tranche_end": "2023-09-01T00:00:00.000Z",
|
||||
"total_added": "17500",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "14122.9698193438015",
|
||||
"locked_amount": "14051.682329408213",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "12500",
|
||||
@@ -4005,7 +4108,7 @@
|
||||
"tranche_end": "2023-08-01T00:00:00.000Z",
|
||||
"total_added": "37500",
|
||||
"total_removed": "11781.2245815",
|
||||
"locked_amount": "24342.459906384285",
|
||||
"locked_amount": "24187.1690837937375",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "7500",
|
||||
@@ -4325,7 +4428,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "129999.45",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "57762.679297096771897515",
|
||||
"locked_amount": "57584.870168320415566065",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "129999.45",
|
||||
@@ -4358,7 +4461,7 @@
|
||||
"tranche_end": "2024-04-01T00:00:00.000Z",
|
||||
"total_added": "54144.7663",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "53478.00750101943585405563",
|
||||
"locked_amount": "53367.12360019002586831048",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "54144.7663",
|
||||
@@ -4391,7 +4494,7 @@
|
||||
"tranche_end": "2023-09-03T00:00:00.000Z",
|
||||
"total_added": "62600",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "25810.56995180111776",
|
||||
"locked_amount": "25682.0192161339434",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "10000",
|
||||
@@ -4584,7 +4687,7 @@
|
||||
"tranche_end": "2023-09-17T00:00:00.000Z",
|
||||
"total_added": "5000",
|
||||
"total_removed": "0",
|
||||
"locked_amount": "2253.32794266869585",
|
||||
"locked_amount": "2243.060312024353",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "5000",
|
||||
@@ -5103,7 +5206,7 @@
|
||||
"tranche_end": "2023-05-01T00:00:00.000Z",
|
||||
"total_added": "22500",
|
||||
"total_removed": "6357.929999175",
|
||||
"locked_amount": "3169.01185543278045",
|
||||
"locked_amount": "3075.8373618784524",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "7500",
|
||||
@@ -5543,7 +5646,7 @@
|
||||
"tranche_end": "2023-06-02T00:00:00.000Z",
|
||||
"total_added": "1939928.38",
|
||||
"total_removed": "928642.9598472029154",
|
||||
"locked_amount": "305567.6317709348835147958",
|
||||
"locked_amount": "301583.938154471032688225",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1852091.69",
|
||||
@@ -11031,7 +11134,7 @@
|
||||
"tranche_id": 11,
|
||||
"tranche_start": "2021-09-03T00:00:00.000Z",
|
||||
"tranche_end": "2022-09-03T00:00:00.000Z",
|
||||
"total_added": "57213.000000000000000003",
|
||||
"total_added": "57238.000000000000000003",
|
||||
"total_removed": "48157.21518131551",
|
||||
"locked_amount": "0",
|
||||
"deposits": [
|
||||
@@ -11055,6 +11158,11 @@
|
||||
"user": "0x363D3d06d70761c34D6EfEB25E409A9549E6970D",
|
||||
"tx": "0x180cd3aca2d716aa233483a9a52b02e83d9ac88716ca85d998269965c7a01a96"
|
||||
},
|
||||
{
|
||||
"amount": "25",
|
||||
"user": "0x981D29D939cAa4ADC04A5e44224dBB45539E8730",
|
||||
"tx": "0xac528ad2b9d958135e7556c5d9d36ce97eb6fb723dd44b3430374276e0fae9be"
|
||||
},
|
||||
{
|
||||
"amount": "150",
|
||||
"user": "0xEb01fF124D71b6C7E6613fd6E0A86c28C733F008",
|
||||
@@ -22858,6 +22966,21 @@
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "25"
|
||||
},
|
||||
{
|
||||
"address": "0x981D29D939cAa4ADC04A5e44224dBB45539E8730",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "25",
|
||||
"user": "0x981D29D939cAa4ADC04A5e44224dBB45539E8730",
|
||||
"tranche_id": 11,
|
||||
"tx": "0xac528ad2b9d958135e7556c5d9d36ce97eb6fb723dd44b3430374276e0fae9be"
|
||||
}
|
||||
],
|
||||
"withdrawals": [],
|
||||
"total_tokens": "25",
|
||||
"withdrawn_tokens": "0",
|
||||
"remaining_tokens": "25"
|
||||
},
|
||||
{
|
||||
"address": "0xEb01fF124D71b6C7E6613fd6E0A86c28C733F008",
|
||||
"deposits": [
|
||||
@@ -39276,7 +39399,7 @@
|
||||
"tranche_end": "2023-06-05T00:00:00.000Z",
|
||||
"total_added": "3732368.4671",
|
||||
"total_removed": "700133.348465855088393",
|
||||
"locked_amount": "494052.387411363117222196857",
|
||||
"locked_amount": "487930.837297663877080092493",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "1998.95815",
|
||||
@@ -40658,7 +40781,7 @@
|
||||
"tranche_end": "2023-12-05T00:00:00.000Z",
|
||||
"total_added": "15870102.715470999700000001",
|
||||
"total_removed": "815921.67873801845247952",
|
||||
"locked_amount": "7051565.6302064045342393167928833721438227",
|
||||
"locked_amount": "7029859.0065443106923818088552439038280617",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "16249.93",
|
||||
@@ -46972,7 +47095,7 @@
|
||||
"tranche_end": "2023-05-05T00:00:00.000Z",
|
||||
"total_added": "14597706.0446472999",
|
||||
"total_removed": "5808173.326897276766376406",
|
||||
"locked_amount": "788515.1388445815139999883144135346",
|
||||
"locked_amount": "768475.722477836206720900273876518",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "129284.449",
|
||||
@@ -56718,8 +56841,8 @@
|
||||
"tranche_start": "2022-06-05T00:00:00.000Z",
|
||||
"tranche_end": "2023-06-05T00:00:00.000Z",
|
||||
"total_added": "472355.6199999996",
|
||||
"total_removed": "41316.3370079701949",
|
||||
"locked_amount": "78285.424909176752146146526230336",
|
||||
"total_removed": "41480.0971297341949",
|
||||
"locked_amount": "77315.43030138884441024977777776",
|
||||
"deposits": [
|
||||
{
|
||||
"amount": "3000",
|
||||
@@ -63408,6 +63531,16 @@
|
||||
"user": "0x9405F540EcC1204801De5C4444D06386BD6693F0",
|
||||
"tx": "0x0df6ec04cbdda41c8649a5e360ec541d14371e3877d82e1404308180024ede02"
|
||||
},
|
||||
{
|
||||
"amount": "152.077625568",
|
||||
"user": "0x7345AaA0D0e4C4A46d921fA9323973956F2b7392",
|
||||
"tx": "0xf2737eb145aea0c573c2f604ae4b840fd56358a89f1470e37a26fff91df2e38d"
|
||||
},
|
||||
{
|
||||
"amount": "11.682496196",
|
||||
"user": "0xcB555C5602cC0b2434A27d277e14Cb5C7bF4Ead1",
|
||||
"tx": "0xc757d9ea4d28133266b723ac41ba64d3bc5e1f4498e08b24745bf84e203009e0"
|
||||
},
|
||||
{
|
||||
"amount": "154.812094114",
|
||||
"user": "0x27e2254A2A8c9c9D1321E5Fe64cAD88e7A4f0ba7",
|
||||
@@ -81781,6 +81914,12 @@
|
||||
}
|
||||
],
|
||||
"withdrawals": [
|
||||
{
|
||||
"amount": "152.077625568",
|
||||
"user": "0x7345AaA0D0e4C4A46d921fA9323973956F2b7392",
|
||||
"tranche_id": 5,
|
||||
"tx": "0xf2737eb145aea0c573c2f604ae4b840fd56358a89f1470e37a26fff91df2e38d"
|
||||
},
|
||||
{
|
||||
"amount": "94.45296804",
|
||||
"user": "0x7345AaA0D0e4C4A46d921fA9323973956F2b7392",
|
||||
@@ -81831,8 +81970,8 @@
|
||||
}
|
||||
],
|
||||
"total_tokens": "1200",
|
||||
"withdrawn_tokens": "850.0164003",
|
||||
"remaining_tokens": "349.9835997"
|
||||
"withdrawn_tokens": "1002.094025868",
|
||||
"remaining_tokens": "197.905974132"
|
||||
},
|
||||
{
|
||||
"address": "0x47181cf36aDFb0b5dB7EfDB123f403D890607841",
|
||||
@@ -82030,6 +82169,12 @@
|
||||
"tranche_id": 5,
|
||||
"tx": "0x9d4c99fdeee2d95caee8d6725f6796f8e02f8a9fd2d911a8e151b2665e192ebc"
|
||||
},
|
||||
{
|
||||
"amount": "11.682496196",
|
||||
"user": "0xcB555C5602cC0b2434A27d277e14Cb5C7bF4Ead1",
|
||||
"tranche_id": 5,
|
||||
"tx": "0xc757d9ea4d28133266b723ac41ba64d3bc5e1f4498e08b24745bf84e203009e0"
|
||||
},
|
||||
{
|
||||
"amount": "19.74474886",
|
||||
"user": "0xcB555C5602cC0b2434A27d277e14Cb5C7bF4Ead1",
|
||||
@@ -82062,8 +82207,8 @@
|
||||
}
|
||||
],
|
||||
"total_tokens": "400",
|
||||
"withdrawn_tokens": "322.776395228",
|
||||
"remaining_tokens": "77.223604772"
|
||||
"withdrawn_tokens": "334.458891424",
|
||||
"remaining_tokens": "65.541108576"
|
||||
},
|
||||
{
|
||||
"address": "0x3738bec36216eA2F11B954891C65AAd1Bc852156",
|
||||
|
||||
@@ -61,6 +61,7 @@ beforeEach(() => {
|
||||
submitDeposit: jest.fn(),
|
||||
submitFaucet: jest.fn(),
|
||||
onDisconnect: jest.fn(),
|
||||
handleAmountChange: jest.fn(),
|
||||
approveTxId: null,
|
||||
faucetTxId: null,
|
||||
isFaucetable: true,
|
||||
|
||||
@@ -25,11 +25,9 @@ import {
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { useWeb3React } from '@web3-react/core';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import type { ButtonHTMLAttributes, ReactNode } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { useMemo } from 'react';
|
||||
import { useWatch } from 'react-hook-form';
|
||||
import { Controller, useForm } from 'react-hook-form';
|
||||
import type { ButtonHTMLAttributes, ChangeEvent, ReactNode } from 'react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useWatch, Controller, useForm } from 'react-hook-form';
|
||||
import { DepositLimits } from './deposit-limits';
|
||||
import { useAssetDetailsDialogStore } from '@vegaprotocol/assets';
|
||||
import {
|
||||
@@ -40,6 +38,7 @@ import {
|
||||
import type { DepositBalances } from './use-deposit-balances';
|
||||
import { FaucetNotification } from './faucet-notification';
|
||||
import { ApproveNotification } from './approve-notification';
|
||||
import { usePersistentDeposit } from './use-persistent-deposit';
|
||||
|
||||
interface FormFields {
|
||||
asset: string;
|
||||
@@ -53,6 +52,7 @@ export interface DepositFormProps {
|
||||
selectedAsset?: Asset;
|
||||
balances: DepositBalances | null;
|
||||
onSelectAsset: (assetId: string) => void;
|
||||
handleAmountChange: (amount: string) => void;
|
||||
onDisconnect: () => void;
|
||||
submitApprove: () => void;
|
||||
approveTxId: number | null;
|
||||
@@ -71,6 +71,7 @@ export const DepositForm = ({
|
||||
selectedAsset,
|
||||
balances,
|
||||
onSelectAsset,
|
||||
handleAmountChange,
|
||||
onDisconnect,
|
||||
submitApprove,
|
||||
submitDeposit,
|
||||
@@ -85,6 +86,8 @@ export const DepositForm = ({
|
||||
const { pubKey, pubKeys: _pubKeys } = useVegaWallet();
|
||||
const [approveNotificationIntent, setApproveNotificationIntent] =
|
||||
useState<Intent>(Intent.Warning);
|
||||
const [persistedDeposit] = usePersistentDeposit(selectedAsset?.id);
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
@@ -95,7 +98,8 @@ export const DepositForm = ({
|
||||
} = useForm<FormFields>({
|
||||
defaultValues: {
|
||||
to: pubKey ? pubKey : undefined,
|
||||
asset: selectedAsset?.id || '',
|
||||
asset: selectedAsset?.id,
|
||||
amount: persistedDeposit.amount,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -333,6 +337,9 @@ export const DepositForm = ({
|
||||
return maxSafe(balances?.balance || new BigNumber(0))(v);
|
||||
},
|
||||
},
|
||||
onChange: (e: ChangeEvent<HTMLInputElement>) => {
|
||||
handleAmountChange(e.target.value || '');
|
||||
},
|
||||
})}
|
||||
/>
|
||||
{errors.amount?.message && (
|
||||
@@ -343,10 +350,9 @@ export const DepositForm = ({
|
||||
{selectedAsset && balances && (
|
||||
<UseButton
|
||||
onClick={() => {
|
||||
setValue(
|
||||
'amount',
|
||||
balances.balance.toFixed(selectedAsset.decimals)
|
||||
);
|
||||
const amount = balances.balance.toFixed(selectedAsset.decimals);
|
||||
setValue('amount', amount);
|
||||
handleAmountChange(amount);
|
||||
clearErrors('amount');
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { prepend0x } from '@vegaprotocol/smart-contracts';
|
||||
import sortBy from 'lodash/sortBy';
|
||||
import { useSubmitApproval } from './use-submit-approval';
|
||||
import { useSubmitFaucet } from './use-submit-faucet';
|
||||
import { useState } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useDepositBalances } from './use-deposit-balances';
|
||||
import { useDepositDialog } from './deposit-dialog';
|
||||
import type { Asset } from '@vegaprotocol/assets';
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
useBridgeContract,
|
||||
useEthereumConfig,
|
||||
} from '@vegaprotocol/web3';
|
||||
import { usePersistentDeposit } from './use-persistent-deposit';
|
||||
|
||||
interface DepositManagerProps {
|
||||
assetId?: string;
|
||||
@@ -28,7 +29,9 @@ export const DepositManager = ({
|
||||
}: DepositManagerProps) => {
|
||||
const createEthTransaction = useEthTransactionStore((state) => state.create);
|
||||
const { config } = useEthereumConfig();
|
||||
const [assetId, setAssetId] = useState(initialAssetId);
|
||||
const [persistentDeposit, savePersistentDeposit] =
|
||||
usePersistentDeposit(initialAssetId);
|
||||
const [assetId, setAssetId] = useState(persistentDeposit?.assetId);
|
||||
const asset = assets.find((a) => a.id === assetId);
|
||||
const bridgeContract = useBridgeContract();
|
||||
const closeDepositDialog = useDepositDialog((state) => state.close);
|
||||
@@ -65,17 +68,26 @@ export const DepositManager = ({
|
||||
closeDepositDialog();
|
||||
};
|
||||
|
||||
const onAmountChange = useCallback(
|
||||
(amount: string) => {
|
||||
savePersistentDeposit({ ...persistentDeposit, amount });
|
||||
},
|
||||
[savePersistentDeposit, persistentDeposit]
|
||||
);
|
||||
|
||||
return (
|
||||
<DepositForm
|
||||
selectedAsset={asset}
|
||||
onDisconnect={reset}
|
||||
onSelectAsset={(id) => {
|
||||
setAssetId(id);
|
||||
savePersistentDeposit({ assetId: id });
|
||||
// When we change asset, also clear the tracked faucet/approve transactions so
|
||||
// we dont render stale UI
|
||||
approve.reset();
|
||||
faucet.reset();
|
||||
}}
|
||||
handleAmountChange={onAmountChange}
|
||||
assets={sortBy(assets, 'name')}
|
||||
submitApprove={approve.perform}
|
||||
submitDeposit={submitDeposit}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { renderHook, waitFor, act } from '@testing-library/react';
|
||||
import { usePersistentDeposit } from './use-persistent-deposit';
|
||||
|
||||
describe('usePersistenDeposit', () => {
|
||||
it('should return empty data', () => {
|
||||
const { result } = renderHook(() => usePersistentDeposit());
|
||||
expect(result.current).toEqual([{ assetId: '' }, expect.any(Function)]);
|
||||
});
|
||||
it('should return empty and properly saved data', async () => {
|
||||
const aId = 'test';
|
||||
const retObj = { assetId: 'test', amount: '1.00000' };
|
||||
const { result } = renderHook(() => usePersistentDeposit(aId));
|
||||
expect(result.current).toEqual([{ assetId: 'test' }, expect.any(Function)]);
|
||||
await act(() => {
|
||||
result.current[1](retObj);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(result.current[0]).toEqual(retObj);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
import { useMemo } from 'react';
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
import { immer } from 'zustand/middleware/immer';
|
||||
|
||||
const STORAGE_KEY = 'vega_deposit_store';
|
||||
interface PersistedDeposit {
|
||||
assetId: string;
|
||||
amount?: string;
|
||||
}
|
||||
type PersistedDepositData = Record<string, PersistedDeposit>;
|
||||
|
||||
const usePersistentDepositStore = create<{
|
||||
deposits: PersistedDepositData;
|
||||
saveValue: (entry: PersistedDeposit) => void;
|
||||
lastVisited?: PersistedDeposit;
|
||||
}>()(
|
||||
persist(
|
||||
immer((set) => ({
|
||||
deposits: {},
|
||||
saveValue: (entry) =>
|
||||
set((state) => {
|
||||
const oldValue = state.deposits[entry.assetId] || null;
|
||||
state.deposits[entry.assetId] = { ...oldValue, ...entry };
|
||||
state.lastVisited = { ...oldValue, ...entry };
|
||||
return state;
|
||||
}),
|
||||
})),
|
||||
{ name: STORAGE_KEY }
|
||||
)
|
||||
);
|
||||
|
||||
export const usePersistentDeposit = (
|
||||
assetId?: string
|
||||
): [PersistedDeposit, (entry: PersistedDeposit) => void] => {
|
||||
const { deposits, lastVisited, saveValue } = usePersistentDepositStore();
|
||||
const discoveredData = useMemo(() => {
|
||||
return deposits[assetId || ''] || lastVisited || { assetId: assetId || '' };
|
||||
}, [deposits, lastVisited, assetId]);
|
||||
|
||||
return [discoveredData, saveValue];
|
||||
};
|
||||
Reference in New Issue
Block a user