From 2f54e1cde737ad0bf1dc17d7f8ab9db9be328b14 Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 18:25:54 -0600 Subject: [PATCH 01/44] added sample script and generated github workflow to test --- .github/workflows/hello_world_workflow.yaml | 32 +++++++++++++++++++ .../scripts/hello_world_workflow.main.kts | 20 ++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .github/workflows/hello_world_workflow.yaml create mode 100755 .github/workflows/scripts/hello_world_workflow.main.kts diff --git a/.github/workflows/hello_world_workflow.yaml b/.github/workflows/hello_world_workflow.yaml new file mode 100644 index 0000000000..5821f788ec --- /dev/null +++ b/.github/workflows/hello_world_workflow.yaml @@ -0,0 +1,32 @@ +# This file was generated using Kotlin DSL (.github/workflows/scripts/hello_world_workflow.main.kts). +# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file. +# Generated with https://github.com/typesafegithub/github-workflows-kt + +name: 'Test workflow' +on: + workflow_dispatch: { } +jobs: + check_yaml_consistency: + name: 'Check YAML consistency' + runs-on: 'ubuntu-latest' + steps: + - id: 'step-0' + name: 'Check out' + uses: 'actions/checkout@v4' + - id: 'step-1' + name: 'Execute script' + run: 'rm ''.github/workflows/hello_world_workflow.yaml'' && ''.github/workflows/scripts/hello_world_workflow.main.kts''' + - id: 'step-2' + name: 'Consistency check' + run: 'git diff --exit-code ''.github/workflows/hello_world_workflow.yaml''' + test_job: + runs-on: 'ubuntu-latest' + needs: + - 'check_yaml_consistency' + steps: + - id: 'step-0' + name: 'Check out' + uses: 'actions/checkout@v4' + - id: 'step-1' + name: 'Print greeting' + run: 'echo ''Hello world!''' diff --git a/.github/workflows/scripts/hello_world_workflow.main.kts b/.github/workflows/scripts/hello_world_workflow.main.kts new file mode 100755 index 0000000000..1686e010f7 --- /dev/null +++ b/.github/workflows/scripts/hello_world_workflow.main.kts @@ -0,0 +1,20 @@ +#!/usr/bin/env kotlin + +@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.4.0") + +import io.github.typesafegithub.workflows.actions.actions.CheckoutV4 +import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest +import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch +import io.github.typesafegithub.workflows.dsl.workflow +import io.github.typesafegithub.workflows.yaml.writeToFile + +workflow( + name = "Test workflow", + on = listOf(WorkflowDispatch()), + sourceFile = __FILE__.toPath(), +) { + job(id = "test_job", runsOn = UbuntuLatest) { + uses(name = "Check out", action = CheckoutV4()) + run(name = "Print greeting", command = "echo 'Hello world!'") + } +}.writeToFile() \ No newline at end of file From 8f149606bd0670047310c461e76b5bf70eb018db Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 18:31:12 -0600 Subject: [PATCH 02/44] removed checkout for testing --- .github/workflows/hello_world_workflow.yaml | 3 --- .github/workflows/scripts/hello_world_workflow.main.kts | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/hello_world_workflow.yaml b/.github/workflows/hello_world_workflow.yaml index 5821f788ec..cf19c302d7 100644 --- a/.github/workflows/hello_world_workflow.yaml +++ b/.github/workflows/hello_world_workflow.yaml @@ -25,8 +25,5 @@ jobs: - 'check_yaml_consistency' steps: - id: 'step-0' - name: 'Check out' - uses: 'actions/checkout@v4' - - id: 'step-1' name: 'Print greeting' run: 'echo ''Hello world!''' diff --git a/.github/workflows/scripts/hello_world_workflow.main.kts b/.github/workflows/scripts/hello_world_workflow.main.kts index 1686e010f7..44dc2a7200 100755 --- a/.github/workflows/scripts/hello_world_workflow.main.kts +++ b/.github/workflows/scripts/hello_world_workflow.main.kts @@ -2,7 +2,6 @@ @file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.4.0") -import io.github.typesafegithub.workflows.actions.actions.CheckoutV4 import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch import io.github.typesafegithub.workflows.dsl.workflow @@ -14,7 +13,7 @@ workflow( sourceFile = __FILE__.toPath(), ) { job(id = "test_job", runsOn = UbuntuLatest) { - uses(name = "Check out", action = CheckoutV4()) +// uses(name = "Check out", action = CheckoutV4(ref = "feature/meta/workflow_to_notify_of_new_release")) run(name = "Print greeting", command = "echo 'Hello world!'") } }.writeToFile() \ No newline at end of file From cf2ffdf775c53096d7ea1310d1a6aaa5d06cb173 Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 18:38:09 -0600 Subject: [PATCH 03/44] removed consistency job --- .github/workflows/hello_world_workflow.yaml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.github/workflows/hello_world_workflow.yaml b/.github/workflows/hello_world_workflow.yaml index cf19c302d7..ecfbb729a6 100644 --- a/.github/workflows/hello_world_workflow.yaml +++ b/.github/workflows/hello_world_workflow.yaml @@ -6,23 +6,8 @@ name: 'Test workflow' on: workflow_dispatch: { } jobs: - check_yaml_consistency: - name: 'Check YAML consistency' - runs-on: 'ubuntu-latest' - steps: - - id: 'step-0' - name: 'Check out' - uses: 'actions/checkout@v4' - - id: 'step-1' - name: 'Execute script' - run: 'rm ''.github/workflows/hello_world_workflow.yaml'' && ''.github/workflows/scripts/hello_world_workflow.main.kts''' - - id: 'step-2' - name: 'Consistency check' - run: 'git diff --exit-code ''.github/workflows/hello_world_workflow.yaml''' test_job: runs-on: 'ubuntu-latest' - needs: - - 'check_yaml_consistency' steps: - id: 'step-0' name: 'Print greeting' From 8df184874164cb8e620a8e430dedafe3f49a006f Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 19:34:06 -0600 Subject: [PATCH 04/44] re-added consistency job. Added second print --- .github/workflows/hello_world_workflow.yaml | 25 +++++++++++++++++++ .../scripts/hello_world_workflow.main.kts | 7 +++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.github/workflows/hello_world_workflow.yaml b/.github/workflows/hello_world_workflow.yaml index ecfbb729a6..1b463c130e 100644 --- a/.github/workflows/hello_world_workflow.yaml +++ b/.github/workflows/hello_world_workflow.yaml @@ -6,9 +6,34 @@ name: 'Test workflow' on: workflow_dispatch: { } jobs: + check_yaml_consistency: + name: 'Check YAML consistency' + runs-on: 'ubuntu-latest' + steps: + - id: 'step-0' + name: 'Check out' + uses: 'actions/checkout@v4' + with: + ref: 'feature/meta/workflow_to_notify_of_new_release' + - id: 'step-1' + name: 'Execute script' + run: 'rm ''.github/workflows/hello_world_workflow.yaml'' && ''.github/workflows/scripts/hello_world_workflow.main.kts''' + - id: 'step-2' + name: 'Consistency check' + run: 'git diff --exit-code ''.github/workflows/hello_world_workflow.yaml''' test_job: runs-on: 'ubuntu-latest' + needs: + - 'check_yaml_consistency' steps: - id: 'step-0' + name: 'Check out' + uses: 'actions/checkout@v4' + with: + ref: 'feature/meta/workflow_to_notify_of_new_release' + - id: 'step-1' name: 'Print greeting' run: 'echo ''Hello world!''' + - id: 'step-2' + name: 'Print greeting' + run: 'echo ''Hello world!2''' diff --git a/.github/workflows/scripts/hello_world_workflow.main.kts b/.github/workflows/scripts/hello_world_workflow.main.kts index 44dc2a7200..95a2784d59 100755 --- a/.github/workflows/scripts/hello_world_workflow.main.kts +++ b/.github/workflows/scripts/hello_world_workflow.main.kts @@ -2,6 +2,7 @@ @file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.4.0") +import io.github.typesafegithub.workflows.actions.actions.CheckoutV4 import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch import io.github.typesafegithub.workflows.dsl.workflow @@ -13,7 +14,11 @@ workflow( sourceFile = __FILE__.toPath(), ) { job(id = "test_job", runsOn = UbuntuLatest) { -// uses(name = "Check out", action = CheckoutV4(ref = "feature/meta/workflow_to_notify_of_new_release")) + uses( + name = "Check out", + action = CheckoutV4(ref = "feature/meta/workflow_to_notify_of_new_release") + ) run(name = "Print greeting", command = "echo 'Hello world!'") + run(name = "Print greeting", command = "echo 'Hello world!2'") } }.writeToFile() \ No newline at end of file From 7cf376ee19da84a17e49b4444cb04284bc8d563b Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 19:36:53 -0600 Subject: [PATCH 05/44] re-generated test yaml --- .github/workflows/hello_world_workflow.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/hello_world_workflow.yaml b/.github/workflows/hello_world_workflow.yaml index 1b463c130e..f6d1dff4d3 100644 --- a/.github/workflows/hello_world_workflow.yaml +++ b/.github/workflows/hello_world_workflow.yaml @@ -13,8 +13,6 @@ jobs: - id: 'step-0' name: 'Check out' uses: 'actions/checkout@v4' - with: - ref: 'feature/meta/workflow_to_notify_of_new_release' - id: 'step-1' name: 'Execute script' run: 'rm ''.github/workflows/hello_world_workflow.yaml'' && ''.github/workflows/scripts/hello_world_workflow.main.kts''' From ff00df62708a3fddcd95bc07093626dd105ffcfb Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 19:39:03 -0600 Subject: [PATCH 06/44] re-generated test yaml --- .github/workflows/scripts/hello_world_workflow.main.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts/hello_world_workflow.main.kts b/.github/workflows/scripts/hello_world_workflow.main.kts index 95a2784d59..289531dcc2 100755 --- a/.github/workflows/scripts/hello_world_workflow.main.kts +++ b/.github/workflows/scripts/hello_world_workflow.main.kts @@ -10,7 +10,7 @@ import io.github.typesafegithub.workflows.yaml.writeToFile workflow( name = "Test workflow", - on = listOf(WorkflowDispatch()), + on = listOf(WorkflowDispatch(emptyMap(), emptyMap())), sourceFile = __FILE__.toPath(), ) { job(id = "test_job", runsOn = UbuntuLatest) { From 0342fea682cb0cb766508b9a62fc856b9364403f Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 19:49:46 -0600 Subject: [PATCH 07/44] updated test yaml --- .github/workflows/hello_world_workflow.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/hello_world_workflow.yaml b/.github/workflows/hello_world_workflow.yaml index f6d1dff4d3..1b463c130e 100644 --- a/.github/workflows/hello_world_workflow.yaml +++ b/.github/workflows/hello_world_workflow.yaml @@ -13,6 +13,8 @@ jobs: - id: 'step-0' name: 'Check out' uses: 'actions/checkout@v4' + with: + ref: 'feature/meta/workflow_to_notify_of_new_release' - id: 'step-1' name: 'Execute script' run: 'rm ''.github/workflows/hello_world_workflow.yaml'' && ''.github/workflows/scripts/hello_world_workflow.main.kts''' From 16d673f51025f02b65c2b595ed75efa987459b4d Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 20:01:20 -0600 Subject: [PATCH 08/44] updated test yaml --- .github/workflows/hello_world_workflow.yaml | 4 ---- .github/workflows/scripts/hello_world_workflow.main.kts | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/hello_world_workflow.yaml b/.github/workflows/hello_world_workflow.yaml index 1b463c130e..1c154cca3a 100644 --- a/.github/workflows/hello_world_workflow.yaml +++ b/.github/workflows/hello_world_workflow.yaml @@ -13,8 +13,6 @@ jobs: - id: 'step-0' name: 'Check out' uses: 'actions/checkout@v4' - with: - ref: 'feature/meta/workflow_to_notify_of_new_release' - id: 'step-1' name: 'Execute script' run: 'rm ''.github/workflows/hello_world_workflow.yaml'' && ''.github/workflows/scripts/hello_world_workflow.main.kts''' @@ -23,8 +21,6 @@ jobs: run: 'git diff --exit-code ''.github/workflows/hello_world_workflow.yaml''' test_job: runs-on: 'ubuntu-latest' - needs: - - 'check_yaml_consistency' steps: - id: 'step-0' name: 'Check out' diff --git a/.github/workflows/scripts/hello_world_workflow.main.kts b/.github/workflows/scripts/hello_world_workflow.main.kts index 289531dcc2..9a03c27889 100755 --- a/.github/workflows/scripts/hello_world_workflow.main.kts +++ b/.github/workflows/scripts/hello_world_workflow.main.kts @@ -12,8 +12,9 @@ workflow( name = "Test workflow", on = listOf(WorkflowDispatch(emptyMap(), emptyMap())), sourceFile = __FILE__.toPath(), + yamlConsistencyJobCondition = null ) { - job(id = "test_job", runsOn = UbuntuLatest) { + job(id = "test_job", runsOn = UbuntuLatest, needs = emptyList()) { uses( name = "Check out", action = CheckoutV4(ref = "feature/meta/workflow_to_notify_of_new_release") From 2e622b0e462bbc71e69f50cda52ca9987b3f6218 Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 20:05:10 -0600 Subject: [PATCH 09/44] updated test yaml --- .github/workflows/hello_world_workflow.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/hello_world_workflow.yaml b/.github/workflows/hello_world_workflow.yaml index 1c154cca3a..a521e0eccd 100644 --- a/.github/workflows/hello_world_workflow.yaml +++ b/.github/workflows/hello_world_workflow.yaml @@ -1,4 +1,4 @@ -# This file was generated using Kotlin DSL (.github/workflows/scripts/hello_world_workflow.main.kts). +# This file was generated using Kotlin DSL (.github/workflows/hello_world_workflow.main.kts). # If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file. # Generated with https://github.com/typesafegithub/github-workflows-kt @@ -15,12 +15,14 @@ jobs: uses: 'actions/checkout@v4' - id: 'step-1' name: 'Execute script' - run: 'rm ''.github/workflows/hello_world_workflow.yaml'' && ''.github/workflows/scripts/hello_world_workflow.main.kts''' + run: 'rm ''.github/workflows/hello_world_workflow.yaml'' && ''.github/workflows/hello_world_workflow.main.kts''' - id: 'step-2' name: 'Consistency check' run: 'git diff --exit-code ''.github/workflows/hello_world_workflow.yaml''' test_job: runs-on: 'ubuntu-latest' + needs: + - 'check_yaml_consistency' steps: - id: 'step-0' name: 'Check out' From b4ff69e34a13ad0251f92a6e9a540289976b4941 Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 20:15:18 -0600 Subject: [PATCH 10/44] regenerated yaml --- .github/workflows/hello_world_workflow.yaml | 46 ++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/.github/workflows/hello_world_workflow.yaml b/.github/workflows/hello_world_workflow.yaml index a521e0eccd..1c8ef89cf0 100644 --- a/.github/workflows/hello_world_workflow.yaml +++ b/.github/workflows/hello_world_workflow.yaml @@ -1,37 +1,37 @@ -# This file was generated using Kotlin DSL (.github/workflows/hello_world_workflow.main.kts). +# This file was generated using Kotlin DSL (.github/workflows/scripts/hello_world_workflow.main.kts). # If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file. # Generated with https://github.com/typesafegithub/github-workflows-kt name: 'Test workflow' on: - workflow_dispatch: { } + workflow_dispatch: {} jobs: check_yaml_consistency: name: 'Check YAML consistency' runs-on: 'ubuntu-latest' steps: - - id: 'step-0' - name: 'Check out' - uses: 'actions/checkout@v4' - - id: 'step-1' - name: 'Execute script' - run: 'rm ''.github/workflows/hello_world_workflow.yaml'' && ''.github/workflows/hello_world_workflow.main.kts''' - - id: 'step-2' - name: 'Consistency check' - run: 'git diff --exit-code ''.github/workflows/hello_world_workflow.yaml''' + - id: 'step-0' + name: 'Check out' + uses: 'actions/checkout@v4' + - id: 'step-1' + name: 'Execute script' + run: 'rm ''.github/workflows/hello_world_workflow.yaml'' && ''.github/workflows/scripts/hello_world_workflow.main.kts''' + - id: 'step-2' + name: 'Consistency check' + run: 'git diff --exit-code ''.github/workflows/hello_world_workflow.yaml''' test_job: runs-on: 'ubuntu-latest' needs: - - 'check_yaml_consistency' + - 'check_yaml_consistency' steps: - - id: 'step-0' - name: 'Check out' - uses: 'actions/checkout@v4' - with: - ref: 'feature/meta/workflow_to_notify_of_new_release' - - id: 'step-1' - name: 'Print greeting' - run: 'echo ''Hello world!''' - - id: 'step-2' - name: 'Print greeting' - run: 'echo ''Hello world!2''' + - id: 'step-0' + name: 'Check out' + uses: 'actions/checkout@v4' + with: + ref: 'feature/meta/workflow_to_notify_of_new_release' + - id: 'step-1' + name: 'Print greeting' + run: 'echo ''Hello world!''' + - id: 'step-2' + name: 'Print greeting' + run: 'echo ''Hello world!2''' From 28f16685b3aedf952e33076cea57866604b5d34f Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 20:20:18 -0600 Subject: [PATCH 11/44] updated hello_world_workflow.yaml --- .github/workflows/hello_world_workflow.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/hello_world_workflow.yaml b/.github/workflows/hello_world_workflow.yaml index 1c8ef89cf0..ad8f546824 100644 --- a/.github/workflows/hello_world_workflow.yaml +++ b/.github/workflows/hello_world_workflow.yaml @@ -13,6 +13,8 @@ jobs: - id: 'step-0' name: 'Check out' uses: 'actions/checkout@v4' + with: + ref: 'feature/meta/workflow_to_notify_of_new_release' - id: 'step-1' name: 'Execute script' run: 'rm ''.github/workflows/hello_world_workflow.yaml'' && ''.github/workflows/scripts/hello_world_workflow.main.kts''' From 422cb04a1baaf43dc22de6ab99931ac4ef724c04 Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 20:26:12 -0600 Subject: [PATCH 12/44] removed consistency check --- .github/workflows/hello_world_workflow.yaml | 17 ----------------- .../scripts/hello_world_workflow.main.kts | 5 +++-- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/.github/workflows/hello_world_workflow.yaml b/.github/workflows/hello_world_workflow.yaml index ad8f546824..83da02d699 100644 --- a/.github/workflows/hello_world_workflow.yaml +++ b/.github/workflows/hello_world_workflow.yaml @@ -6,25 +6,8 @@ name: 'Test workflow' on: workflow_dispatch: {} jobs: - check_yaml_consistency: - name: 'Check YAML consistency' - runs-on: 'ubuntu-latest' - steps: - - id: 'step-0' - name: 'Check out' - uses: 'actions/checkout@v4' - with: - ref: 'feature/meta/workflow_to_notify_of_new_release' - - id: 'step-1' - name: 'Execute script' - run: 'rm ''.github/workflows/hello_world_workflow.yaml'' && ''.github/workflows/scripts/hello_world_workflow.main.kts''' - - id: 'step-2' - name: 'Consistency check' - run: 'git diff --exit-code ''.github/workflows/hello_world_workflow.yaml''' test_job: runs-on: 'ubuntu-latest' - needs: - - 'check_yaml_consistency' steps: - id: 'step-0' name: 'Check out' diff --git a/.github/workflows/scripts/hello_world_workflow.main.kts b/.github/workflows/scripts/hello_world_workflow.main.kts index 9a03c27889..e4deffe2a7 100755 --- a/.github/workflows/scripts/hello_world_workflow.main.kts +++ b/.github/workflows/scripts/hello_world_workflow.main.kts @@ -7,11 +7,12 @@ import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch import io.github.typesafegithub.workflows.dsl.workflow import io.github.typesafegithub.workflows.yaml.writeToFile +import kotlin.io.path.pathString workflow( name = "Test workflow", on = listOf(WorkflowDispatch(emptyMap(), emptyMap())), - sourceFile = __FILE__.toPath(), + sourceFile = __FILE__.toPath().also { println(it.pathString) }, yamlConsistencyJobCondition = null ) { job(id = "test_job", runsOn = UbuntuLatest, needs = emptyList()) { @@ -22,4 +23,4 @@ workflow( run(name = "Print greeting", command = "echo 'Hello world!'") run(name = "Print greeting", command = "echo 'Hello world!2'") } -}.writeToFile() \ No newline at end of file +}.writeToFile(addConsistencyCheck = false) \ No newline at end of file From baa777b0c9b697e80c43abfc4c3a2a001aeccc2f Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 20:49:48 -0600 Subject: [PATCH 13/44] removed unused properties --- .github/workflows/scripts/hello_world_workflow.main.kts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/scripts/hello_world_workflow.main.kts b/.github/workflows/scripts/hello_world_workflow.main.kts index e4deffe2a7..92f0caec5a 100755 --- a/.github/workflows/scripts/hello_world_workflow.main.kts +++ b/.github/workflows/scripts/hello_world_workflow.main.kts @@ -7,15 +7,13 @@ import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch import io.github.typesafegithub.workflows.dsl.workflow import io.github.typesafegithub.workflows.yaml.writeToFile -import kotlin.io.path.pathString workflow( name = "Test workflow", - on = listOf(WorkflowDispatch(emptyMap(), emptyMap())), - sourceFile = __FILE__.toPath().also { println(it.pathString) }, - yamlConsistencyJobCondition = null + on = listOf(WorkflowDispatch()), + sourceFile = __FILE__.toPath(), ) { - job(id = "test_job", runsOn = UbuntuLatest, needs = emptyList()) { + job(id = "test_job", runsOn = UbuntuLatest) { uses( name = "Check out", action = CheckoutV4(ref = "feature/meta/workflow_to_notify_of_new_release") From 0bb71582a9c4f1c9a92674823cf1d720114d1530 Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 6 Nov 2023 22:09:22 -0600 Subject: [PATCH 14/44] updated test workflow script with slack api action --- .github/workflows/hello_world_workflow.yaml | 14 ++++++-- .../scripts/hello_world_workflow.main.kts | 35 +++++++++++++++++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/.github/workflows/hello_world_workflow.yaml b/.github/workflows/hello_world_workflow.yaml index 83da02d699..ea2b4e761f 100644 --- a/.github/workflows/hello_world_workflow.yaml +++ b/.github/workflows/hello_world_workflow.yaml @@ -16,7 +16,15 @@ jobs: ref: 'feature/meta/workflow_to_notify_of_new_release' - id: 'step-1' name: 'Print greeting' - run: 'echo ''Hello world!''' + run: 'echo ''Hello world!'' ${{ secrets.SLACK_WEBHOOK_URL }} after secret' - id: 'step-2' - name: 'Print greeting' - run: 'echo ''Hello world!2''' + name: 'Notify Channel' + uses: 'slackapi/slack-github-action@v1.24.0' + with: + payload: |- + { + "text":"Hello, World!" + } + env: + SLACK_WEBHOOK_URL: '${{ secrets.SLACK_WEBHOOK_URL }}' + SLACK_WEBHOOK_TYPE: 'INCOMING_WEBHOOK' diff --git a/.github/workflows/scripts/hello_world_workflow.main.kts b/.github/workflows/scripts/hello_world_workflow.main.kts index 92f0caec5a..922e56fd00 100755 --- a/.github/workflows/scripts/hello_world_workflow.main.kts +++ b/.github/workflows/scripts/hello_world_workflow.main.kts @@ -4,9 +4,23 @@ import io.github.typesafegithub.workflows.actions.actions.CheckoutV4 import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest +import io.github.typesafegithub.workflows.domain.actions.CustomAction import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch +import io.github.typesafegithub.workflows.dsl.expressions.Contexts +import io.github.typesafegithub.workflows.dsl.expressions.expr import io.github.typesafegithub.workflows.dsl.workflow import io.github.typesafegithub.workflows.yaml.writeToFile +import org.intellij.lang.annotations.Language + +@Suppress("PrivatePropertyName") +private val SLACK_WEBHOOK_URL by Contexts.secrets + +@Language("JSON") +private val slackPayload = """ + { + "text":"Hello, World!" + } + """.trimIndent() workflow( name = "Test workflow", @@ -18,7 +32,24 @@ workflow( name = "Check out", action = CheckoutV4(ref = "feature/meta/workflow_to_notify_of_new_release") ) - run(name = "Print greeting", command = "echo 'Hello world!'") - run(name = "Print greeting", command = "echo 'Hello world!2'") + run( + name = "Print greeting", + command = "echo 'Hello world!' ${expr { SLACK_WEBHOOK_URL }} after secret" + ) + uses( + name = "Notify Channel", + action = CustomAction( + actionOwner = "slackapi", + actionName = "slack-github-action", + actionVersion = "v1.24.0", + inputs = linkedMapOf( + "payload" to slackPayload + ) + ), + env = linkedMapOf( + "SLACK_WEBHOOK_URL" to expr { SLACK_WEBHOOK_URL }, + "SLACK_WEBHOOK_TYPE" to "INCOMING_WEBHOOK" + ) + ) } }.writeToFile(addConsistencyCheck = false) \ No newline at end of file From fdfdfb6ca82d64651a86c29ffefd3211e51ddc81 Mon Sep 17 00:00:00 2001 From: Kacper Date: Tue, 7 Nov 2023 11:07:45 +0100 Subject: [PATCH 15/44] Allow to initialize web3wallet and web3Modal sdks --- .../wcmodal/client/WalletConnectModal.kt | 89 +++++++++---------- .../web3/modal/client/Web3Modal.kt | 83 ++++++++--------- .../web3/wallet/client/Web3Wallet.kt | 19 +++- .../auth/common/exceptions/Exceptions.kt | 2 + .../auth/common/exceptions/Messages.kt | 4 +- .../walletconnect/sign/client/SignProtocol.kt | 3 +- .../sign/common/exceptions/Messages.kt | 4 +- .../sign/common/exceptions/SignExceptions.kt | 4 +- 8 files changed, 107 insertions(+), 101 deletions(-) diff --git a/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/client/WalletConnectModal.kt b/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/client/WalletConnectModal.kt index fb8971dd72..e9962c3479 100644 --- a/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/client/WalletConnectModal.kt +++ b/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/client/WalletConnectModal.kt @@ -1,10 +1,14 @@ package com.walletconnect.wcmodal.client +import com.walletconnect.android.internal.common.scope import com.walletconnect.android.internal.common.wcKoinApp import com.walletconnect.wcmodal.domain.WalletConnectModalDelegate import com.walletconnect.sign.client.Sign import com.walletconnect.sign.client.SignClient +import com.walletconnect.sign.common.exceptions.SignClientAlreadyInitializedException import com.walletconnect.wcmodal.di.walletConnectModalModule +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach object WalletConnectModal { @@ -38,62 +42,49 @@ object WalletConnectModal { ) { SignClient.initialize( init = Sign.Params.Init(init.core), - onSuccess = { - this.excludedWalletsIds = init.excludedWalletIds - this.recommendedWalletsIds = init.recommendedWalletsIds - _sessionParams = init.sessionParams - runCatching { - wcKoinApp.modules(walletConnectModalModule()) - setDelegate(WalletConnectModalDelegate) - }.onFailure { error -> onError(Modal.Model.Error(error)) } - onSuccess() - }, + onSuccess = { onInitializedClient(init, onSuccess, onError) }, onError = { error -> - onError(Modal.Model.Error(error.throwable)) - return@initialize + if (error.throwable is SignClientAlreadyInitializedException) { + onInitializedClient(init, onSuccess, onError) + } else { + onError(Modal.Model.Error(error.throwable)) + return@initialize + } } ) } - @Throws(IllegalStateException::class) - fun setDelegate(delegate: ModalDelegate) { - val signDelegate = object : SignClient.DappDelegate { - override fun onSessionApproved(approvedSession: Sign.Model.ApprovedSession) { - delegate.onSessionApproved(approvedSession.toModal()) - } - - override fun onSessionRejected(rejectedSession: Sign.Model.RejectedSession) { - delegate.onSessionRejected(rejectedSession.toModal()) - } - - override fun onSessionUpdate(updatedSession: Sign.Model.UpdatedSession) { - delegate.onSessionUpdate(updatedSession.toModal()) - } - - override fun onSessionEvent(sessionEvent: Sign.Model.SessionEvent) { - delegate.onSessionEvent(sessionEvent.toModal()) - } - override fun onSessionExtend(session: Sign.Model.Session) { - delegate.onSessionExtend(session.toModal()) - } - - override fun onSessionDelete(deletedSession: Sign.Model.DeletedSession) { - delegate.onSessionDelete(deletedSession.toModal()) - } - - override fun onSessionRequestResponse(response: Sign.Model.SessionRequestResponse) { - delegate.onSessionRequestResponse(response.toModal()) - } - - override fun onConnectionStateChange(state: Sign.Model.ConnectionState) { - delegate.onConnectionStateChange(state.toModal()) - } + private fun onInitializedClient( + init: Modal.Params.Init, + onSuccess: () -> Unit = {}, + onError: (Modal.Model.Error) -> Unit + ) { + this.excludedWalletsIds = init.excludedWalletIds + this.recommendedWalletsIds = init.recommendedWalletsIds + _sessionParams = init.sessionParams + runCatching { + wcKoinApp.modules(walletConnectModalModule()) + setDelegate(WalletConnectModalDelegate) + }.onFailure { error -> onError(Modal.Model.Error(error)) } + onSuccess() + } - override fun onError(error: Sign.Model.Error) { - delegate.onError(error.toModal()) + @Throws(IllegalStateException::class) + fun setDelegate(delegate: ModalDelegate) { + WalletConnectModalDelegate.wcEventModels.onEach { event -> + when(event) { + is Modal.Model.ApprovedSession -> delegate.onSessionApproved(event) + is Modal.Model.ConnectionState -> delegate.onConnectionStateChange(event) + is Modal.Model.DeletedSession.Success -> delegate.onSessionDelete(event) + is Modal.Model.Error -> delegate.onError(event) + is Modal.Model.RejectedSession -> delegate.onSessionRejected(event) + is Modal.Model.Session -> delegate.onSessionExtend(event) + is Modal.Model.SessionEvent -> delegate.onSessionEvent(event) + is Modal.Model.SessionRequestResponse -> delegate.onSessionRequestResponse(event) + is Modal.Model.UpdatedSession -> delegate.onSessionUpdate(event) + else -> Unit } - } - SignClient.setDappDelegate(signDelegate) + }.launchIn(scope) } fun setSessionParams(sessionParams: Modal.Params.SessionParams) { diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt index b2c235f718..465b689442 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt @@ -4,6 +4,7 @@ import com.walletconnect.android.internal.common.scope import com.walletconnect.android.internal.common.wcKoinApp import com.walletconnect.sign.client.Sign import com.walletconnect.sign.client.SignClient +import com.walletconnect.sign.common.exceptions.SignClientAlreadyInitializedException import com.walletconnect.web3.modal.di.web3ModalModule import com.walletconnect.web3.modal.domain.delegate.Web3ModalDelegate import com.walletconnect.web3.modal.domain.model.InvalidSessionException @@ -12,6 +13,8 @@ import com.walletconnect.web3.modal.domain.usecase.DeleteSessionDataUseCase import com.walletconnect.web3.modal.domain.usecase.GetSelectedChainUseCase import com.walletconnect.web3.modal.domain.usecase.GetSessionTopicUseCase import com.walletconnect.web3.modal.utils.toChain +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine @@ -61,21 +64,33 @@ object Web3Modal { SignClient.initialize( init = Sign.Params.Init(init.core), onSuccess = { - this.excludedWalletsIds = init.excludedWalletIds - this.recommendedWalletsIds = init.recommendedWalletsIds - runCatching { - wcKoinApp.modules(web3ModalModule()) - setDelegate(Web3ModalDelegate) - }.onFailure { error -> onError(Modal.Model.Error(error)) } - onSuccess() + onInitializedClient(init, onSuccess, onError) }, onError = { error -> - onError(Modal.Model.Error(error.throwable)) - return@initialize + if (error.throwable is SignClientAlreadyInitializedException) { + onInitializedClient(init, onSuccess, onError) + } else { + onError(Modal.Model.Error(error.throwable)) + return@initialize + } } ) } + private fun onInitializedClient( + init: Modal.Params.Init, + onSuccess: () -> Unit = {}, + onError: (Modal.Model.Error) -> Unit + ) { + this.excludedWalletsIds = init.excludedWalletIds + this.recommendedWalletsIds = init.recommendedWalletsIds + runCatching { + wcKoinApp.modules(web3ModalModule()) + setDelegate(Web3ModalDelegate) + }.onFailure { error -> onError(Modal.Model.Error(error)) } + onSuccess() + } + fun setChains(chains: List) { this.chains = chains } @@ -90,44 +105,20 @@ object Web3Modal { @Throws(IllegalStateException::class) fun setDelegate(delegate: ModalDelegate) { - val signDelegate = object : SignClient.DappDelegate { - override fun onSessionApproved(approvedSession: Sign.Model.ApprovedSession) { - delegate.onSessionApproved(approvedSession.toModal()) - } - - override fun onSessionRejected(rejectedSession: Sign.Model.RejectedSession) { - delegate.onSessionRejected(rejectedSession.toModal()) - } - - override fun onSessionUpdate(updatedSession: Sign.Model.UpdatedSession) { - delegate.onSessionUpdate(updatedSession.toModal()) - } - - override fun onSessionEvent(sessionEvent: Sign.Model.SessionEvent) { - delegate.onSessionEvent(sessionEvent.toModal()) + Web3ModalDelegate.wcEventModels.onEach { event -> + when(event) { + is Modal.Model.ApprovedSession -> delegate.onSessionApproved(event) + is Modal.Model.ConnectionState -> delegate.onConnectionStateChange(event) + is Modal.Model.DeletedSession.Success -> delegate.onSessionDelete(event) + is Modal.Model.Error -> delegate.onError(event) + is Modal.Model.RejectedSession -> delegate.onSessionRejected(event) + is Modal.Model.Session -> delegate.onSessionExtend(event) + is Modal.Model.SessionEvent -> delegate.onSessionEvent(event) + is Modal.Model.SessionRequestResponse -> delegate.onSessionRequestResponse(event) + is Modal.Model.UpdatedSession -> delegate.onSessionUpdate(event) + else -> Unit } - - override fun onSessionExtend(session: Sign.Model.Session) { - delegate.onSessionExtend(session.toModal()) - } - - override fun onSessionDelete(deletedSession: Sign.Model.DeletedSession) { - delegate.onSessionDelete(deletedSession.toModal()) - } - - override fun onSessionRequestResponse(response: Sign.Model.SessionRequestResponse) { - delegate.onSessionRequestResponse(response.toModal()) - } - - override fun onConnectionStateChange(state: Sign.Model.ConnectionState) { - delegate.onConnectionStateChange(state.toModal()) - } - - override fun onError(error: Sign.Model.Error) { - delegate.onError(error.toModal()) - } - } - SignClient.setDappDelegate(signDelegate) + }.launchIn(scope) } internal fun connect( diff --git a/product/web3wallet/src/main/kotlin/com/walletconnect/web3/wallet/client/Web3Wallet.kt b/product/web3wallet/src/main/kotlin/com/walletconnect/web3/wallet/client/Web3Wallet.kt index 7a62cc99bf..6cc052108a 100644 --- a/product/web3wallet/src/main/kotlin/com/walletconnect/web3/wallet/client/Web3Wallet.kt +++ b/product/web3wallet/src/main/kotlin/com/walletconnect/web3/wallet/client/Web3Wallet.kt @@ -5,8 +5,10 @@ import com.walletconnect.android.CoreInterface import com.walletconnect.android.internal.common.scope import com.walletconnect.auth.client.Auth import com.walletconnect.auth.client.AuthClient +import com.walletconnect.auth.common.exceptions.AuthClientAlreadyInitializedException import com.walletconnect.sign.client.Sign import com.walletconnect.sign.client.SignClient +import com.walletconnect.sign.common.exceptions.SignClientAlreadyInitializedException import kotlinx.coroutines.* import java.util.* @@ -88,8 +90,21 @@ object Web3Wallet { fun initialize(params: Wallet.Params.Init, onSuccess: () -> Unit = {}, onError: (Wallet.Model.Error) -> Unit) { coreClient = params.core var clientInitCounter = 0 - SignClient.initialize(Sign.Params.Init(params.core), onSuccess = { clientInitCounter++ }) { error -> onError(Wallet.Model.Error(error.throwable)) } - AuthClient.initialize(Auth.Params.Init(params.core), onSuccess = { clientInitCounter++ }) { error -> onError(Wallet.Model.Error(error.throwable)) } + val onSuccessfulInitialization: () -> Unit = { clientInitCounter++ } + SignClient.initialize(Sign.Params.Init(params.core), onSuccess = onSuccessfulInitialization) { error -> + if (error.throwable is SignClientAlreadyInitializedException) { + onSuccessfulInitialization() + } else { + onError(Wallet.Model.Error(error.throwable)) + } + } + AuthClient.initialize(Auth.Params.Init(params.core), onSuccess = onSuccessfulInitialization) { error -> + if (error.throwable is AuthClientAlreadyInitializedException) { + onSuccessfulInitialization() + } else { + onError(Wallet.Model.Error(error.throwable)) + } + } validateInitializationCount(clientInitCounter, onSuccess, onError) } diff --git a/protocol/auth/src/main/kotlin/com/walletconnect/auth/common/exceptions/Exceptions.kt b/protocol/auth/src/main/kotlin/com/walletconnect/auth/common/exceptions/Exceptions.kt index ddb18e47bc..d6315ff5e1 100644 --- a/protocol/auth/src/main/kotlin/com/walletconnect/auth/common/exceptions/Exceptions.kt +++ b/protocol/auth/src/main/kotlin/com/walletconnect/auth/common/exceptions/Exceptions.kt @@ -7,3 +7,5 @@ import com.walletconnect.android.internal.common.exception.WalletConnectExceptio internal object MissingAuthRequestException : WalletConnectException(MISSING_AUTH_REQUEST_MESSAGE) internal object InvalidCacaoException : WalletConnectException(CACAO_IS_NOT_VALID_MESSAGE) internal class InvalidParamsException(override val message: String) : WalletConnectException(message) + +class AuthClientAlreadyInitializedException : WalletConnectException(CLIENT_ALREADY_INITIALIZED) diff --git a/protocol/auth/src/main/kotlin/com/walletconnect/auth/common/exceptions/Messages.kt b/protocol/auth/src/main/kotlin/com/walletconnect/auth/common/exceptions/Messages.kt index a4b5ca00ff..86a762c1ea 100644 --- a/protocol/auth/src/main/kotlin/com/walletconnect/auth/common/exceptions/Messages.kt +++ b/protocol/auth/src/main/kotlin/com/walletconnect/auth/common/exceptions/Messages.kt @@ -3,4 +3,6 @@ package com.walletconnect.auth.common.exceptions internal const val MISSING_AUTH_REQUEST_MESSAGE: String = "Missing Auth Request" -internal const val CACAO_IS_NOT_VALID_MESSAGE: String = "Cacao is not valid" \ No newline at end of file +internal const val CACAO_IS_NOT_VALID_MESSAGE: String = "Cacao is not valid" + +internal const val CLIENT_ALREADY_INITIALIZED: String = "AuthClient already initialized" diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/client/SignProtocol.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/client/SignProtocol.kt index 23e4b9bb4e..a7b93931ae 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/client/SignProtocol.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/client/SignProtocol.kt @@ -10,6 +10,7 @@ import com.walletconnect.android.internal.common.wcKoinApp import com.walletconnect.android.pairing.model.mapper.toPairing import com.walletconnect.foundation.common.model.Topic import com.walletconnect.sign.client.mapper.* +import com.walletconnect.sign.common.exceptions.SignClientAlreadyInitializedException import com.walletconnect.sign.di.engineModule import com.walletconnect.sign.di.signJsonRpcModule import com.walletconnect.sign.di.storageModule @@ -45,7 +46,7 @@ class SignProtocol(private val koinApp: KoinApplication = wcKoinApp) : SignInter onError(Sign.Model.Error(e)) } } else { - onError(Sign.Model.Error(IllegalStateException("SignClient already initialized"))) + onError(Sign.Model.Error(SignClientAlreadyInitializedException())) } } diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/common/exceptions/Messages.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/common/exceptions/Messages.kt index 524ca882ed..5a91282f7b 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/common/exceptions/Messages.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/common/exceptions/Messages.kt @@ -27,4 +27,6 @@ internal const val UNAUTHORIZED_EVENT_MESSAGE: String = "Unauthorized event is n internal const val INVALID_EVENT_MESSAGE: String = "Event name and data fields cannot be empty. ChainId must be CAIP-2 compliant" internal const val INVALID_REQUEST_MESSAGE: String = "Request topic, method and params fields cannot be empty. ChainId must be CAIP-2 compliant" internal const val INVALID_EXTEND_TIME: String = "Extend time is out of range" -internal const val INVALID_SESSION_PROPERTIES: String = "Invalid Session Properties requested" \ No newline at end of file +internal const val INVALID_SESSION_PROPERTIES: String = "Invalid Session Properties requested" + +internal const val CLIENT_ALREADY_INITIALIZED: String = "SignClient already initialized" diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/common/exceptions/SignExceptions.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/common/exceptions/SignExceptions.kt index c533ebe3a0..8b1303a36c 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/common/exceptions/SignExceptions.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/common/exceptions/SignExceptions.kt @@ -11,4 +11,6 @@ class InvalidPropertiesException(override val message: String?) : WalletConnectE class InvalidEventException(override val message: String?) : WalletConnectException(message) class InvalidRequestException(override val message: String?) : WalletConnectException(message) -class NotSettledSessionException(override val message: String?) : WalletConnectException(message) \ No newline at end of file +class NotSettledSessionException(override val message: String?) : WalletConnectException(message) + +class SignClientAlreadyInitializedException : WalletConnectException(CLIENT_ALREADY_INITIALIZED) From 7df58c89c5c4876cf834bf150ccf4bceb21590bd Mon Sep 17 00:00:00 2001 From: Kacper Date: Tue, 7 Nov 2023 13:22:36 +0100 Subject: [PATCH 16/44] Create landscape screens and improvements --- .../ui/components/internal/Orientation.kt | 31 ++++ .../web3/modal/ui/previews/Previews.kt | 4 + .../ui/routes/account/account/AccountRoute.kt | 15 +- .../connect/redirect/RedirectWalletScreen.kt | 168 ++++++++++++++++-- .../routes/connect/scan_code/ScanCodeRoute.kt | 63 ++++++- .../connect/what_is_wallet/WhatIsWallet.kt | 6 +- .../sample/modal/MainActivity.kt | 74 ++++---- 7 files changed, 292 insertions(+), 69 deletions(-) create mode 100644 product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Orientation.kt diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Orientation.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Orientation.kt new file mode 100644 index 0000000000..5495b6f89d --- /dev/null +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Orientation.kt @@ -0,0 +1,31 @@ +package com.walletconnect.web3.modal.ui.components.internal + +import android.content.res.Configuration +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.runtime.snapshotFlow +import androidx.compose.ui.platform.LocalConfiguration + +@Composable +internal fun OrientationBox( + portrait: @Composable () -> Unit, + landscape: @Composable () -> Unit +) { + val configuration = LocalConfiguration.current + var orientation by remember { mutableIntStateOf(Configuration.ORIENTATION_PORTRAIT) } + + LaunchedEffect(configuration) { + snapshotFlow { configuration.orientation } + .collect { orientation = it } + } + + // TODO migrate to WindowSize when will you migrate to material3 + when (configuration.orientation) { + Configuration.ORIENTATION_LANDSCAPE -> landscape() + else -> portrait() + } +} \ No newline at end of file diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/previews/Previews.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/previews/Previews.kt index eeb7b78eba..6769107ab4 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/previews/Previews.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/previews/Previews.kt @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.runtime.Composable import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Devices import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.navigation.compose.rememberNavController @@ -82,3 +83,6 @@ internal annotation class LightTheme @Preview(uiMode = UI_MODE_NIGHT_YES) internal annotation class DarkTheme + +@Preview(device = Devices.AUTOMOTIVE_1024p, widthDp = 720, heightDp = 360, uiMode = UI_MODE_NIGHT_YES) +internal annotation class Landscape diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/account/AccountRoute.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/account/AccountRoute.kt index e55b003220..1af4c2f23e 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/account/AccountRoute.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/account/AccountRoute.kt @@ -4,6 +4,8 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState @@ -50,12 +52,6 @@ internal fun AccountRoute( val balance by accountState.balanceState.collectAsState() Box(modifier = Modifier.fillMaxWidth()) { - CloseIcon( - modifier = Modifier - .align(Alignment.TopEnd) - .padding(18.dp), - onClick = { accountState.closeModal() } - ) UiStateBuilder(uiStateFlow = accountState.accountState) { data -> AccountScreen( accountData = data, @@ -66,6 +62,12 @@ internal fun AccountRoute( onDisconnectClick = { accountState.disconnect() } ) } + CloseIcon( + modifier = Modifier + .align(Alignment.TopEnd) + .padding(18.dp), + onClick = { accountState.closeModal() } + ) } } @@ -81,6 +83,7 @@ private fun AccountScreen( Column( modifier = Modifier .fillMaxWidth() + .verticalScroll(rememberScrollState()) .padding( top = 32.dp, bottom = 16.dp, start = 12.dp, end = 12.dp ), diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt index 8f40ce0194..83a157964c 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt @@ -3,13 +3,17 @@ package com.walletconnect.web3.modal.ui.routes.connect.redirect import androidx.compose.animation.AnimatedContent import androidx.compose.foundation.background import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.verticalScroll import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -24,6 +28,7 @@ import androidx.compose.ui.platform.ClipboardManager import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.text.AnnotatedString +import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import com.walletconnect.android.internal.common.modal.data.model.Wallet @@ -32,6 +37,7 @@ import com.walletconnect.modal.utils.openMobileLink import com.walletconnect.modal.utils.openPlayStore import com.walletconnect.web3.modal.client.Modal import com.walletconnect.web3.modal.domain.delegate.Web3ModalDelegate +import com.walletconnect.web3.modal.ui.components.internal.OrientationBox import com.walletconnect.web3.modal.ui.components.internal.commons.DeclinedIcon import com.walletconnect.web3.modal.ui.components.internal.commons.ExternalIcon import com.walletconnect.web3.modal.ui.components.internal.commons.entry.CopyActionEntry @@ -48,6 +54,7 @@ import com.walletconnect.web3.modal.ui.components.internal.commons.switch.Platfo import com.walletconnect.web3.modal.ui.components.internal.commons.switch.PlatformTabRow import com.walletconnect.web3.modal.ui.components.internal.commons.switch.rememberWalletPlatformTabs import com.walletconnect.web3.modal.ui.components.internal.snackbar.LocalSnackBarHandler +import com.walletconnect.web3.modal.ui.previews.Landscape import com.walletconnect.web3.modal.ui.previews.UiModePreview import com.walletconnect.web3.modal.ui.previews.Web3ModalPreview import com.walletconnect.web3.modal.ui.previews.testWallets @@ -122,6 +129,23 @@ private fun RedirectWalletScreen( onMobileRetry: () -> Unit, onOpenPlayStore: () -> Unit, onOpenWebApp: () -> Unit +) { + OrientationBox( + portrait = { PortraitRedirectWalletContent(redirectState, platformTab, onPlatformTabSelect, wallet, onCopyLinkClick, onMobileRetry, onOpenPlayStore, onOpenWebApp) }, + landscape = { LandscapeRedirectContent(redirectState, platformTab, onPlatformTabSelect, wallet, onCopyLinkClick, onMobileRetry, onOpenPlayStore, onOpenWebApp) } + ) +} + +@Composable +private fun PortraitRedirectWalletContent( + redirectState: RedirectState, + platformTab: PlatformTab, + onPlatformTabSelect: (PlatformTab) -> Unit, + wallet: Wallet, + onCopyLinkClick: () -> Unit, + onMobileRetry: () -> Unit, + onOpenPlayStore: () -> Unit, + onOpenWebApp: () -> Unit ) { Column( modifier = Modifier @@ -158,6 +182,115 @@ private fun RedirectWalletScreen( } } +@Composable +private fun LandscapeRedirectContent( + redirectState: RedirectState, + platformTab: PlatformTab, + onPlatformTabSelect: (PlatformTab) -> Unit, + wallet: Wallet, + onCopyLinkClick: () -> Unit, + onMobileRetry: () -> Unit, + onOpenPlayStore: () -> Unit, + onOpenWebApp: () -> Unit +) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 20.dp, vertical = 16.dp), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically + ) { + Column( + modifier = Modifier + .weight(1f) + .verticalScroll(rememberScrollState()), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + if (wallet.hasMobileWallet && wallet.hasWebApp) { + PlatformTabRow(platformTab, onPlatformTabSelect) + } + VerticalSpacer(height = 16.dp) + when { + platformTab == PlatformTab.WEB || redirectState == RedirectState.Loading -> WalletImageWithLoader(url = wallet.imageUrl) + redirectState == RedirectState.NotDetected || redirectState == RedirectState.Reject -> RejectWalletImage(wallet.imageUrl) + } + if (redirectState == RedirectState.NotDetected) { + VerticalSpacer(height = 16.dp) + StoreEntry(text = "Don't have ${wallet.name}?", onClick = onOpenPlayStore) + } + VerticalSpacer(height = 16.dp) + } + Column( + modifier = Modifier.weight(1f), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + PlatformBox( + platformTab = platformTab, + mobileWalletContent = { + Column( + modifier = Modifier.fillMaxWidth(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + RedirectLabel(state = redirectState, wallet = wallet) + if (redirectState == RedirectState.NotDetected || redirectState == RedirectState.Reject) { + VerticalSpacer(height = 20.dp) + TryAgainButton(onClick = onMobileRetry) + } + } + }, + webWalletContent = { + RedirectWebWalletScreen( + onCopyLinkClick = onCopyLinkClick, + onOpenWebApp = onOpenWebApp + ) + } + ) + } + } +} + +@Composable +private fun RedirectLabel(state: RedirectState, wallet: Wallet) { + val header: String + val description: String + val headerStyle: TextStyle + val descriptionStyle: TextStyle + when (state) { + RedirectState.Loading -> { + header = "Continue in ${wallet.name}" + headerStyle = Web3ModalTheme.typo.paragraph500 + description = "Accept connection request in your wallet app" + descriptionStyle = Web3ModalTheme.typo.small400.copy(color = Web3ModalTheme.colors.foreground.color200) + } + + RedirectState.Reject -> { + header = "Connection declined" + description = "Connection can be declined if a previous request is still active" + headerStyle = Web3ModalTheme.typo.paragraph400.copy(Web3ModalTheme.colors.error) + descriptionStyle = Web3ModalTheme.typo.small400.copy(color = Web3ModalTheme.colors.foreground.color200) + } + + RedirectState.NotDetected -> { + header = "Download ${wallet.name}" + description = "Install ${wallet.name} app to continue" + headerStyle = Web3ModalTheme.typo.paragraph400 + descriptionStyle = Web3ModalTheme.typo.small400.copy(color = Web3ModalTheme.colors.foreground.color200) + } + } + Text(text = header, style = headerStyle) + VerticalSpacer(height = 8.dp) + Text( + text = description, + style = descriptionStyle, + modifier = Modifier.padding(horizontal = 30.dp), + textAlign = TextAlign.Center + ) + +} + @Composable private fun PlatformBox( platformTab: PlatformTab, @@ -189,9 +322,9 @@ private fun RedirectMobileWalletScreen( horizontalAlignment = Alignment.CenterHorizontally ) { when (redirectState) { - RedirectState.Loading -> LoadingState(wallet, onRetry, onCopyLinkClick) - RedirectState.Reject -> RejectedState(onRetry) - RedirectState.NotDetected -> NotDetectedWalletState(wallet, onRetry, onOpenPlayStore) + RedirectState.Loading -> LoadingState(state, wallet, onRetry, onCopyLinkClick) + RedirectState.Reject -> RejectedState(state, wallet, onRetry) + RedirectState.NotDetected -> NotDetectedWalletState(state, wallet, onRetry, onOpenPlayStore) } } } @@ -227,13 +360,12 @@ private fun Wallet.toPlatform(): PlatformTab = when { @Composable private fun LoadingState( + redirectState: RedirectState, wallet: Wallet, onRetry: () -> Unit, onCopyLinkClick: () -> Unit ) { - Text(text = "Continue in ${wallet.name}", style = Web3ModalTheme.typo.paragraph500) - VerticalSpacer(height = 8.dp) - Text(text = "Accept connection request in your wallet app", style = Web3ModalTheme.typo.small400.copy(color = Web3ModalTheme.colors.foreground.color200)) + RedirectLabel(state = redirectState, wallet = wallet) VerticalSpacer(height = 20.dp) TryAgainButton(onClick = onRetry) VerticalSpacer(height = 20.dp) @@ -254,28 +386,24 @@ private fun WalletImageWithLoader(url: String) { } @Composable -private fun RejectedState(onRetry: () -> Unit) { - Text(text = "Connection declined", style = Web3ModalTheme.typo.paragraph400.copy(Web3ModalTheme.colors.error)) - VerticalSpacer(height = 8.dp) - Text( - text = "Connection can be declined if a previous request is still active", - style = Web3ModalTheme.typo.small400.copy(color = Web3ModalTheme.colors.foreground.color200), - modifier = Modifier.padding(horizontal = 30.dp), - textAlign = TextAlign.Center - ) +private fun RejectedState( + state: RedirectState, + wallet: Wallet, + onRetry: () -> Unit +) { + RedirectLabel(state = state, wallet = wallet) VerticalSpacer(height = 20.dp) TryAgainButton(onClick = onRetry) } @Composable private fun NotDetectedWalletState( + state: RedirectState, wallet: Wallet, onRetry: () -> Unit, onOpenPlayStore: () -> Unit ) { - Text(text = "Download ${wallet.name}", style = Web3ModalTheme.typo.paragraph400) - VerticalSpacer(height = 8.dp) - Text(text = "Install ${wallet.name} app to continue", style = Web3ModalTheme.typo.small400.copy(color = Web3ModalTheme.colors.foreground.color200)) + RedirectLabel(state = state, wallet = wallet) VerticalSpacer(height = 20.dp) TryAgainButton(onClick = onRetry) VerticalSpacer(height = 16.dp) @@ -305,6 +433,7 @@ private fun RejectWalletImage(url: String) { } @UiModePreview +@Landscape @Composable private fun PreviewRedirectWalletScreenWithLoadingState() { val wallet = testWallets.first() @@ -314,6 +443,7 @@ private fun PreviewRedirectWalletScreenWithLoadingState() { } @UiModePreview +@Landscape @Composable private fun PreviewRedirectWalletScreenWithRejectedState() { val wallet = testWallets.first() @@ -323,6 +453,7 @@ private fun PreviewRedirectWalletScreenWithRejectedState() { } @UiModePreview +@Landscape @Composable private fun PreviewRedirectWalletScreenWithNotDetectedState() { val wallet = testWallets.first() @@ -332,6 +463,7 @@ private fun PreviewRedirectWalletScreenWithNotDetectedState() { } @UiModePreview +@Landscape @Composable private fun PreviewRedirectWebWalletScreen() { val wallet = testWallets.first() diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/scan_code/ScanCodeRoute.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/scan_code/ScanCodeRoute.kt index e6876c5e23..061b75b498 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/scan_code/ScanCodeRoute.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/scan_code/ScanCodeRoute.kt @@ -2,9 +2,12 @@ package com.walletconnect.web3.modal.ui.routes.connect.scan_code import androidx.compose.foundation.background import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding @@ -27,8 +30,10 @@ import com.walletconnect.modal.ui.components.qr.QrCodeType import com.walletconnect.modal.ui.components.qr.WalletConnectQRCode import com.walletconnect.web3.modal.client.Modal import com.walletconnect.web3.modal.domain.delegate.Web3ModalDelegate +import com.walletconnect.web3.modal.ui.components.internal.OrientationBox import com.walletconnect.web3.modal.ui.components.internal.commons.entry.CopyActionEntry import com.walletconnect.web3.modal.ui.components.internal.snackbar.LocalSnackBarHandler +import com.walletconnect.web3.modal.ui.previews.Landscape import com.walletconnect.web3.modal.ui.previews.UiModePreview import com.walletconnect.web3.modal.ui.previews.Web3ModalPreview import com.walletconnect.web3.modal.ui.routes.connect.ConnectState @@ -62,6 +67,48 @@ internal fun ScanQRCodeRoute(connectState: ConnectState) { @Composable private fun ScanQRCodeContent( + uri: String, onCopyLinkClick: () -> Unit +) { + OrientationBox( + portrait = { PortraitContent(uri, onCopyLinkClick) }, + landscape = { LandscapeContent(uri, onCopyLinkClick) } + ) + +} + +@Composable +private fun LandscapeContent( + uri: String, + onCopyLinkClick: () -> Unit +) { + Row( + modifier = Modifier + .fillMaxSize() + .padding(vertical = 5.dp, horizontal = 10.dp), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically + ) { + Box( + modifier = Modifier + .weight(1f) + .padding(vertical = 5.dp), + contentAlignment = Alignment.Center + ) { + QRCode(uri = uri) + } + Column( + modifier = Modifier.weight(1f), + horizontalAlignment = Alignment.CenterHorizontally + ) { + ScanQrCodeLabel() + Spacer(modifier = Modifier.height(12.dp)) + CopyActionEntry(onClick = onCopyLinkClick) + } + } +} + +@Composable +private fun PortraitContent( uri: String, onCopyLinkClick: () -> Unit ) { @@ -73,17 +120,20 @@ private fun ScanQRCodeContent( ) { QRCode(uri = uri) Spacer(modifier = Modifier.height(20.dp)) - Text( - text = "Scan this QR code with your phone", - modifier = Modifier.fillMaxWidth(), - style = Web3ModalTheme.typo.paragraph400, - textAlign = TextAlign.Center - ) + ScanQrCodeLabel() Spacer(modifier = Modifier.height(12.dp)) CopyActionEntry(onClick = onCopyLinkClick) } } +@Composable +private fun ScanQrCodeLabel() { + Text( + text = "Scan this QR code with your phone", + modifier = Modifier.fillMaxWidth(), style = Web3ModalTheme.typo.paragraph400, textAlign = TextAlign.Center + ) +} + @Composable private fun QRCode(uri: String) { if (isSystemInDarkTheme()) { @@ -110,6 +160,7 @@ private fun QRCode(uri: String) { } @UiModePreview +@Landscape @Composable private fun ScanQRCodePreview() { Web3ModalPreview("Mobile Wallets") { diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/what_is_wallet/WhatIsWallet.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/what_is_wallet/WhatIsWallet.kt index f932bd2716..a5b1344f6e 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/what_is_wallet/WhatIsWallet.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/what_is_wallet/WhatIsWallet.kt @@ -1,6 +1,8 @@ package com.walletconnect.web3.modal.ui.routes.connect.what_is_wallet import androidx.compose.foundation.layout.* +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -66,7 +68,9 @@ private fun WhatIsWallet( optionButton: @Composable () -> Unit ) { Column( - modifier = Modifier.padding(horizontal = 20.dp), + modifier = Modifier + .padding(horizontal = 20.dp) + .verticalScroll(rememberScrollState()), horizontalAlignment = Alignment.CenterHorizontally ) { Spacer(modifier = Modifier.height(20.dp)) diff --git a/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/MainActivity.kt b/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/MainActivity.kt index 9486828882..7d133b00e8 100644 --- a/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/MainActivity.kt +++ b/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/MainActivity.kt @@ -93,47 +93,46 @@ class MainActivity : ComponentActivity() { var isDark by remember { mutableStateOf(isDarkTheme) } var darkColors by remember { mutableStateOf(Web3ModalTheme.provideDarkWeb3ModalColor()) } var lightColors by remember { mutableStateOf(Web3ModalTheme.provideLightWeb3ModalColors()) } - - Scaffold( - scaffoldState = scaffoldState, - topBar = { - Column { - TopAppBar( - title = { - Text( - text = "Web3Modal Lab", - modifier = Modifier.fillMaxWidth(), - textAlign = TextAlign.Center + Web3ModalTheme( + mode = if (isDark) Web3ModalTheme.Mode.DARK else Web3ModalTheme.Mode.LIGHT, + lightColors = lightColors, + darkColors = darkColors + ) { + ModalBottomSheetLayout( + sheetShape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp), + bottomSheetNavigator = bottomSheetNavigator, + ) { + Scaffold( + scaffoldState = scaffoldState, + topBar = { + Column { + TopAppBar( + title = { + Text( + text = "Web3Modal Lab", + modifier = Modifier.fillMaxWidth(), + textAlign = TextAlign.Center + ) + }, + navigationIcon = {}, + actions = { + ThemeModeIcon(isDark) { isDark = it } + } + ) + PredefineThemes( + onClick = { light, dark -> + lightColors = light + darkColors = dark + } ) - }, - navigationIcon = {}, - actions = { - ThemeModeIcon(isDark) { isDark = it } - } - ) - PredefineThemes( - onClick = { light, dark -> - lightColors = light - darkColors = dark } - ) - } - }, - drawerContent = { DrawerContent() } - ) { paddingValues -> - Web3ModalTheme( - mode = if (isDark) Web3ModalTheme.Mode.DARK else Web3ModalTheme.Mode.LIGHT, - lightColors = lightColors, - darkColors = darkColors - ) { - ModalBottomSheetLayout( - sheetShape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp), - bottomSheetNavigator = bottomSheetNavigator, - modifier = Modifier.padding(paddingValues) - ) { + }, + drawerContent = { DrawerContent() } + ) { paddingValues -> NavHost( navController = navController, - startDestination = Route.Lab.path + startDestination = Route.Lab.path, + modifier = Modifier.padding(paddingValues) ) { composable(Route.Lab.path) { LabScreen(navController = navController) @@ -175,7 +174,6 @@ private fun PredefineThemes( } - @Composable private fun ThemeItem( color: Color, From a72657b57b8d1a8bc559cacb2a329e6170e38d85 Mon Sep 17 00:00:00 2001 From: szymon Date: Tue, 7 Nov 2023 15:36:40 +0100 Subject: [PATCH 17/44] feat: Update statement --- .../notify/engine/domain/RegisterIdentityUseCase.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol/notify/src/main/kotlin/com/walletconnect/notify/engine/domain/RegisterIdentityUseCase.kt b/protocol/notify/src/main/kotlin/com/walletconnect/notify/engine/domain/RegisterIdentityUseCase.kt index ec67b80474..16edd4f5fe 100644 --- a/protocol/notify/src/main/kotlin/com/walletconnect/notify/engine/domain/RegisterIdentityUseCase.kt +++ b/protocol/notify/src/main/kotlin/com/walletconnect/notify/engine/domain/RegisterIdentityUseCase.kt @@ -22,8 +22,8 @@ internal class RegisterIdentityUseCase( companion object { private const val LIMITED_STATEMENT = - "I further authorize this app to send and receive messages on my behalf for THIS domain using my WalletConnect identity. Read more at https://walletconnect.com/identity" + "I further authorize this app to send and receive messages on my behalf for THIS domain using my WalletConnect account. Read more at https://walletconnect.com/account" private const val UNLIMITED_STATEMENT = - "I further authorize this app to send and receive messages on my behalf for ALL domains using my WalletConnect identity. Read more at https://walletconnect.com/identity" + "I further authorize this app to send and receive messages on my behalf for ALL domains using my WalletConnect account. Read more at https://walletconnect.com/account" } } From f17cb576c205f702293444fb0407b7e68045664a Mon Sep 17 00:00:00 2001 From: Kacper Date: Tue, 7 Nov 2023 22:35:56 +0100 Subject: [PATCH 18/44] Change shapes and loader around images --- .../ui/components/internal/commons/Loading.kt | 61 +++++++++--------- .../commons/network/ChainNetworkIcons.kt | 62 ++++++++++++++----- .../chain_redirect/ChainSwitchRedirect.kt | 3 +- 3 files changed, 79 insertions(+), 47 deletions(-) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Loading.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Loading.kt index 6e28ed1843..a01570a91f 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Loading.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Loading.kt @@ -15,18 +15,23 @@ import androidx.compose.material.CircularProgressIndicator import androidx.compose.material.Surface import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableFloatStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.composed import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.drawWithCache -import androidx.compose.ui.graphics.BlendMode -import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Outline +import androidx.compose.ui.graphics.Path +import androidx.compose.ui.graphics.PathEffect +import androidx.compose.ui.graphics.PathMeasure import androidx.compose.ui.graphics.Shape -import androidx.compose.ui.graphics.drawOutline +import androidx.compose.ui.graphics.StrokeCap +import androidx.compose.ui.graphics.StrokeJoin +import androidx.compose.ui.graphics.addOutline import androidx.compose.ui.graphics.drawscope.Stroke -import androidx.compose.ui.graphics.drawscope.rotate import androidx.compose.ui.graphics.nativeCanvas import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp @@ -54,7 +59,7 @@ internal fun LoadingHexagonBorder( ) { Box( modifier = Modifier - .drawAnimatedBorder(strokeWidth = 4.dp, shape = HexagonShape, durationMillis = 1700) + .drawAnimatedBorder(strokeWidth = 4.dp, progress = .25f, shape = HexagonShape, durationMillis = 1000) ) { Surface( color = Color.Transparent, @@ -72,7 +77,7 @@ internal fun LoadingBorder( ) { Box( modifier = Modifier - .drawAnimatedBorder(strokeWidth = 4.dp, shape = RoundedCornerShape(cornerRadius + (cornerRadius / 4)), durationMillis = 1700) + .drawAnimatedBorder(strokeWidth = 4.dp, progress = .25f, shape = RoundedCornerShape(cornerRadius + (cornerRadius / 4)), durationMillis = 1000) ) { Surface( color = Color.Transparent, @@ -82,34 +87,27 @@ internal fun LoadingBorder( } } } - private fun Modifier.drawAnimatedBorder( strokeWidth: Dp, + progress: Float, shape: Shape, durationMillis: Int ) = composed { + val loaderColor = Web3ModalTheme.colors.accent100 + var pathLenght by remember { mutableFloatStateOf(0f) } val infiniteTransition = rememberInfiniteTransition(label = "rotation") - val angle by infiniteTransition.animateFloat( + val loaderProgress by infiniteTransition.animateFloat( initialValue = 0f, - targetValue = 360f, + targetValue = pathLenght, animationSpec = infiniteRepeatable( animation = tween(durationMillis, easing = LinearEasing), repeatMode = RepeatMode.Restart ), label = "rotation" ) - val brush = Brush.horizontalGradient( - listOf( - Web3ModalTheme.colors.accent100, - Web3ModalTheme.colors.accent100, - Web3ModalTheme.colors.accent100, - Color.Transparent, Color.Transparent, Color.Transparent, - Color.Transparent, Color.Transparent, Color.Transparent, - Color.Transparent, Color.Transparent, Color.Transparent, - ) - ) Modifier .clip(shape) + .padding(strokeWidth) .drawWithCache { val strokeWidthPx = strokeWidth.toPx() val outline: Outline = shape.createOutline(size, layoutDirection, this) @@ -117,23 +115,24 @@ private fun Modifier.drawAnimatedBorder( drawContent() with(drawContext.canvas.nativeCanvas) { val checkPoint = saveLayer(null, null) - drawOutline( - outline = outline, - color = Color.Gray, - style = Stroke(strokeWidthPx * 2) - ) - rotate(angle) { - drawCircle( - brush = brush, - radius = size.width, - blendMode = BlendMode.SrcIn, + val path = Path().apply { addOutline(outline) } + val pathMeasure = PathMeasure().apply { setPath(path, false) } + pathLenght = pathMeasure.length + drawPath( + path = path, + color = loaderColor, + style = Stroke( + width = strokeWidthPx, + pathEffect = PathEffect.dashPathEffect(floatArrayOf(0f, (1f - progress) * pathMeasure.length, progress * pathMeasure.length, 0f), loaderProgress), + cap = StrokeCap.Round, + join = StrokeJoin.Round ) - } + ) restoreToCount(checkPoint) } } } - .padding(10.dp) + .padding(8.dp) } @UiModePreview diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/network/ChainNetworkIcons.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/network/ChainNetworkIcons.kt index 1291dfc74c..f0087afdab 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/network/ChainNetworkIcons.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/network/ChainNetworkIcons.kt @@ -9,11 +9,16 @@ import androidx.compose.foundation.shape.CircleShape import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.draw.drawWithContent import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.BlendMode import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Outline import androidx.compose.ui.graphics.Path import androidx.compose.ui.graphics.Shape +import androidx.compose.ui.graphics.StrokeCap +import androidx.compose.ui.graphics.StrokeJoin +import androidx.compose.ui.graphics.drawscope.Stroke import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.Density @@ -29,8 +34,8 @@ import com.walletconnect.web3.modal.ui.previews.UiModePreview import com.walletconnect.web3.modal.ui.theme.Web3ModalTheme import com.walletconnect.web3.modal.utils.grayColorFilter import com.walletconnect.web3.modal.utils.imageHeaders -import java.lang.Float.min -import kotlin.math.sqrt +import kotlin.math.cos +import kotlin.math.sin @Composable internal fun CircleNetworkImage( @@ -63,9 +68,11 @@ internal fun CircleNetworkImage( internal fun HexagonNetworkImage( data: Any?, isEnabled: Boolean, + size: Dp = 56.dp, borderColor: Color? = null, placeholder: Drawable? = null ) { + val overlayColor = Web3ModalTheme.colors.grayGlass10 AsyncImage( model = ImageRequest.Builder(LocalContext.current) .data(data) @@ -75,17 +82,29 @@ internal fun HexagonNetworkImage( .build(), contentDescription = null, modifier = Modifier - .size(56.dp) + .size(size) .graphicsLayer { shape = HexagonShape clip = true } - .border(1.dp, borderColor ?: Color.Transparent, shape = HexagonShape), + .drawWithContent { + drawContent() + drawPath( + path = drawCustomHexagonPath(this.size), + color = borderColor ?: overlayColor, + style = Stroke( + width = 2.dp.toPx(), + cap = StrokeCap.Round, + join = StrokeJoin.Round + ), + blendMode = BlendMode.SrcOver + ) + }, colorFilter = if (isEnabled) null else grayColorFilter ) } -internal val HexagonShape = object: Shape { +internal val HexagonShape = object : Shape { override fun createOutline( size: Size, @@ -100,23 +119,36 @@ internal val HexagonShape = object: Shape { internal fun drawCustomHexagonPath(size: Size): Path { return Path().apply { - val radius = min(size.width / 2f, size.height / 2f) - customHexagon(radius, size) + customHexagon(size) } } -internal fun Path.customHexagon(radius: Float, size: Size) { - val triangleHeight = (sqrt(3.0) * radius / 2) +internal fun Path.customHexagon(size: Size) { + + val centerX = size.width / 2 val centerY = size.height / 2 + val radius = size.minDimension / 2f + val cornerRadius = 5f + + moveTo(centerX, size.height - cornerRadius) + for (i in 1..6) { + val angle = i * 60.0 + val x = centerX + radius * cos(Math.toRadians(angle)).toFloat() + val y = centerY + radius * sin(Math.toRadians(angle)).toFloat() - moveTo(centerX, centerY + radius) - lineTo((centerX - triangleHeight).toFloat(), centerY + radius/2) - lineTo((centerX - triangleHeight).toFloat(), centerY - radius/2) - lineTo(centerX, centerY - radius) - lineTo((centerX + triangleHeight).toFloat(), centerY - radius/2) - lineTo((centerX + triangleHeight).toFloat(), centerY + radius/2) + val controlPointX = centerX + (radius - cornerRadius) * cos(Math.toRadians(angle)).toFloat() + val controlPointY = centerY + (radius - cornerRadius) * sin(Math.toRadians(angle)).toFloat() + val endPointX = centerX + radius * cos(Math.toRadians(angle - 60)).toFloat() + val endPointY = centerY + radius * sin(Math.toRadians(angle - 60)).toFloat() + + cubicTo( + endPointY, endPointX, + y, x, + controlPointY, controlPointX, + ) + } close() } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/chain_redirect/ChainSwitchRedirect.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/chain_redirect/ChainSwitchRedirect.kt index 1ab9ca22e6..0a3a6cfa3d 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/chain_redirect/ChainSwitchRedirect.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/chain_redirect/ChainSwitchRedirect.kt @@ -142,7 +142,8 @@ private fun ChainNetworkImage( ChainNetworkImageWrapper(redirectState) { HexagonNetworkImage( data = chain.getImageData(), - isEnabled = true + isEnabled = true, + size = 96.dp ) } } From 14e1d08b35c0b3ab4c168ea388799f6a90b1b83b Mon Sep 17 00:00:00 2001 From: Kacper Date: Tue, 7 Nov 2023 22:37:44 +0100 Subject: [PATCH 19/44] Clear --- .../commons/network/ChainNetworkIcons.kt | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/network/ChainNetworkIcons.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/network/ChainNetworkIcons.kt index f0087afdab..58612edfff 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/network/ChainNetworkIcons.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/network/ChainNetworkIcons.kt @@ -119,37 +119,31 @@ internal val HexagonShape = object : Shape { internal fun drawCustomHexagonPath(size: Size): Path { return Path().apply { - customHexagon(size) - } -} - -internal fun Path.customHexagon(size: Size) { + val centerX = size.width / 2 + val centerY = size.height / 2 + val radius = size.minDimension / 2f + val cornerRadius = 5f + moveTo(centerX, size.height - cornerRadius) + for (i in 1..6) { + val angle = i * 60.0 + val x = centerX + radius * cos(Math.toRadians(angle)).toFloat() + val y = centerY + radius * sin(Math.toRadians(angle)).toFloat() - val centerX = size.width / 2 - val centerY = size.height / 2 - val radius = size.minDimension / 2f - val cornerRadius = 5f - moveTo(centerX, size.height - cornerRadius) - for (i in 1..6) { - val angle = i * 60.0 - val x = centerX + radius * cos(Math.toRadians(angle)).toFloat() - val y = centerY + radius * sin(Math.toRadians(angle)).toFloat() + val controlPointX = centerX + (radius - cornerRadius) * cos(Math.toRadians(angle)).toFloat() + val controlPointY = centerY + (radius - cornerRadius) * sin(Math.toRadians(angle)).toFloat() + val endPointX = centerX + radius * cos(Math.toRadians(angle - 60)).toFloat() + val endPointY = centerY + radius * sin(Math.toRadians(angle - 60)).toFloat() - - val controlPointX = centerX + (radius - cornerRadius) * cos(Math.toRadians(angle)).toFloat() - val controlPointY = centerY + (radius - cornerRadius) * sin(Math.toRadians(angle)).toFloat() - val endPointX = centerX + radius * cos(Math.toRadians(angle - 60)).toFloat() - val endPointY = centerY + radius * sin(Math.toRadians(angle - 60)).toFloat() - - cubicTo( - endPointY, endPointX, - y, x, - controlPointY, controlPointX, - ) + cubicTo( + endPointY, endPointX, + y, x, + controlPointY, controlPointX, + ) + } + close() } - close() } @Composable From 8352e409285c2a835dbd643e87ba6b1fc0de812f Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Tue, 7 Nov 2023 22:51:24 -0600 Subject: [PATCH 20/44] finalized slack notification workflow --- .../scripts/hello_world_workflow.main.kts | 55 -------------- ...ck_release_notifications_workflow.main.kts | 72 +++++++++++++++++++ ...slack_release_notifications_workflow.yaml} | 23 +++--- 3 files changed, 84 insertions(+), 66 deletions(-) delete mode 100755 .github/workflows/scripts/hello_world_workflow.main.kts create mode 100755 .github/workflows/scripts/slack_release_notifications_workflow.main.kts rename .github/workflows/{hello_world_workflow.yaml => slack_release_notifications_workflow.yaml} (55%) diff --git a/.github/workflows/scripts/hello_world_workflow.main.kts b/.github/workflows/scripts/hello_world_workflow.main.kts deleted file mode 100755 index 922e56fd00..0000000000 --- a/.github/workflows/scripts/hello_world_workflow.main.kts +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env kotlin - -@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.4.0") - -import io.github.typesafegithub.workflows.actions.actions.CheckoutV4 -import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest -import io.github.typesafegithub.workflows.domain.actions.CustomAction -import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch -import io.github.typesafegithub.workflows.dsl.expressions.Contexts -import io.github.typesafegithub.workflows.dsl.expressions.expr -import io.github.typesafegithub.workflows.dsl.workflow -import io.github.typesafegithub.workflows.yaml.writeToFile -import org.intellij.lang.annotations.Language - -@Suppress("PrivatePropertyName") -private val SLACK_WEBHOOK_URL by Contexts.secrets - -@Language("JSON") -private val slackPayload = """ - { - "text":"Hello, World!" - } - """.trimIndent() - -workflow( - name = "Test workflow", - on = listOf(WorkflowDispatch()), - sourceFile = __FILE__.toPath(), -) { - job(id = "test_job", runsOn = UbuntuLatest) { - uses( - name = "Check out", - action = CheckoutV4(ref = "feature/meta/workflow_to_notify_of_new_release") - ) - run( - name = "Print greeting", - command = "echo 'Hello world!' ${expr { SLACK_WEBHOOK_URL }} after secret" - ) - uses( - name = "Notify Channel", - action = CustomAction( - actionOwner = "slackapi", - actionName = "slack-github-action", - actionVersion = "v1.24.0", - inputs = linkedMapOf( - "payload" to slackPayload - ) - ), - env = linkedMapOf( - "SLACK_WEBHOOK_URL" to expr { SLACK_WEBHOOK_URL }, - "SLACK_WEBHOOK_TYPE" to "INCOMING_WEBHOOK" - ) - ) - } -}.writeToFile(addConsistencyCheck = false) \ No newline at end of file diff --git a/.github/workflows/scripts/slack_release_notifications_workflow.main.kts b/.github/workflows/scripts/slack_release_notifications_workflow.main.kts new file mode 100755 index 0000000000..5f31baf273 --- /dev/null +++ b/.github/workflows/scripts/slack_release_notifications_workflow.main.kts @@ -0,0 +1,72 @@ +#!/usr/bin/env kotlin +@file:Suppress("PrivatePropertyName") +@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.4.0") + +import io.github.typesafegithub.workflows.actions.actions.CheckoutV4 +import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest +import io.github.typesafegithub.workflows.domain.actions.Action +import io.github.typesafegithub.workflows.domain.actions.RegularAction +import io.github.typesafegithub.workflows.domain.triggers.Release +import io.github.typesafegithub.workflows.dsl.expressions.Contexts +import io.github.typesafegithub.workflows.dsl.expressions.expr +import io.github.typesafegithub.workflows.dsl.workflow +import io.github.typesafegithub.workflows.yaml.writeToFile +import org.intellij.lang.annotations.Language + +private val SLACK_WEBHOOK_URL_KOTLIN by Contexts.secrets + +workflow( + name = "Slack Release Notifications", + on = listOf( + Release(_customArguments = mapOf("types" to listOf("published"))) + ), + sourceFile = __FILE__.toPath(), +) { + job( + id = "push-notifications", + runsOn = UbuntuLatest, + _customArguments = mapOf( + "strategy" to mapOf( + "matrix" to mapOf( + "conf" to listOf( + mapOf("webhook_url" to expr { SLACK_WEBHOOK_URL_KOTLIN }), + ) + ) + ) + ) + ) { + uses( + name = "Check out", + action = CheckoutV4() + ) + uses( + name = "Notify Channel", + action = SlackGithubAction(), + env = linkedMapOf( + "SLACK_WEBHOOK_URL" to expr { "matrix.conf.webhook_url" }, + "SLACK_WEBHOOK_TYPE" to "INCOMING_WEBHOOK" + ) + ) + } +}.writeToFile(addConsistencyCheck = false) + +private class SlackGithubAction : RegularAction( + actionOwner = "slackapi", + actionName = "slack-github-action", + actionVersion = "v1.24.0" +) { + @Language("JSON") + private val slackPayload = + """ + { + "text":"Kotlin Release ${expr { github.eventRelease.release.name }} was just released. Please update and let us know if you have any issues." + } + """.trimIndent() + + override fun buildOutputObject(stepId: String): Outputs = Outputs(stepId) + + override fun toYamlArguments(): LinkedHashMap = + linkedMapOf( + "payload" to slackPayload + ) +} \ No newline at end of file diff --git a/.github/workflows/hello_world_workflow.yaml b/.github/workflows/slack_release_notifications_workflow.yaml similarity index 55% rename from .github/workflows/hello_world_workflow.yaml rename to .github/workflows/slack_release_notifications_workflow.yaml index ea2b4e761f..ddf471a270 100644 --- a/.github/workflows/hello_world_workflow.yaml +++ b/.github/workflows/slack_release_notifications_workflow.yaml @@ -1,30 +1,31 @@ -# This file was generated using Kotlin DSL (.github/workflows/scripts/hello_world_workflow.main.kts). +# This file was generated using Kotlin DSL (.github/workflows/scripts/slack_release_notifications_workflow.main.kts). # If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file. # Generated with https://github.com/typesafegithub/github-workflows-kt -name: 'Test workflow' +name: 'Slack Release Notifications' on: - workflow_dispatch: {} + release: + types: + - 'published' jobs: - test_job: + push-notifications: runs-on: 'ubuntu-latest' + strategy: + matrix: + conf: + - webhook_url: '${{ secrets.SLACK_WEBHOOK_URL_KOTLIN }}' steps: - id: 'step-0' name: 'Check out' uses: 'actions/checkout@v4' - with: - ref: 'feature/meta/workflow_to_notify_of_new_release' - id: 'step-1' - name: 'Print greeting' - run: 'echo ''Hello world!'' ${{ secrets.SLACK_WEBHOOK_URL }} after secret' - - id: 'step-2' name: 'Notify Channel' uses: 'slackapi/slack-github-action@v1.24.0' with: payload: |- { - "text":"Hello, World!" + "text":"Kotlin Release ${{ github.event.release.name }} was just released. Please update and let us know if you have any issues." } env: - SLACK_WEBHOOK_URL: '${{ secrets.SLACK_WEBHOOK_URL }}' + SLACK_WEBHOOK_URL: '${{ matrix.conf.webhook_url }}' SLACK_WEBHOOK_TYPE: 'INCOMING_WEBHOOK' From c16c51f3ef64b970e840a5beaf51beb73b1fdded Mon Sep 17 00:00:00 2001 From: Kacper Date: Wed, 8 Nov 2023 16:25:30 +0100 Subject: [PATCH 21/44] Update product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Szymon RzÄ…d --- .../kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt index 465b689442..ec7a046eb3 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt @@ -70,8 +70,7 @@ object Web3Modal { if (error.throwable is SignClientAlreadyInitializedException) { onInitializedClient(init, onSuccess, onError) } else { - onError(Modal.Model.Error(error.throwable)) - return@initialize + return@initialize onError(Modal.Model.Error(error.throwable)) } } ) From 197bdd631fe67a5c8ca05bf8584d0a474ba2e31c Mon Sep 17 00:00:00 2001 From: Kacper Date: Wed, 8 Nov 2023 16:25:40 +0100 Subject: [PATCH 22/44] Update product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt Co-authored-by: Talha --- .../kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt index ec7a046eb3..2d13b62fa9 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt @@ -86,7 +86,7 @@ object Web3Modal { runCatching { wcKoinApp.modules(web3ModalModule()) setDelegate(Web3ModalDelegate) - }.onFailure { error -> onError(Modal.Model.Error(error)) } + }.onFailure { error -> return@onInitializedClient onError(Modal.Model.Error(error)) } onSuccess() } From 4401833cb9d86f4864d431287edd3f0daec925c9 Mon Sep 17 00:00:00 2001 From: Kacper Date: Wed, 8 Nov 2023 16:25:45 +0100 Subject: [PATCH 23/44] Update product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/client/WalletConnectModal.kt Co-authored-by: Talha --- .../com/walletconnect/wcmodal/client/WalletConnectModal.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/client/WalletConnectModal.kt b/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/client/WalletConnectModal.kt index e9962c3479..5a545c3239 100644 --- a/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/client/WalletConnectModal.kt +++ b/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/client/WalletConnectModal.kt @@ -65,7 +65,7 @@ object WalletConnectModal { runCatching { wcKoinApp.modules(walletConnectModalModule()) setDelegate(WalletConnectModalDelegate) - }.onFailure { error -> onError(Modal.Model.Error(error)) } + }.onFailure { error -> return@onInitializedClient onError(Modal.Model.Error(error)) } onSuccess() } From bb2dbadb2feed946af73a9f8c66d36916d758d28 Mon Sep 17 00:00:00 2001 From: szymon Date: Wed, 8 Nov 2023 16:27:12 +0100 Subject: [PATCH 24/44] fix: Wrong url used --- .../wallet/ui/routes/composable_routes/inbox/InboxViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/composable_routes/inbox/InboxViewModel.kt b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/composable_routes/inbox/InboxViewModel.kt index a5f2bfdc73..24d3a7f33c 100644 --- a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/composable_routes/inbox/InboxViewModel.kt +++ b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/composable_routes/inbox/InboxViewModel.kt @@ -162,7 +162,7 @@ class InboxViewModel(application: Application) : AndroidViewModel(application) { _discoverState.update { DiscoverState.Subscribing(explorerApp) } val beforeSubscription = _activeSubscriptions.value - Notify.Params.Subscribe(explorerApp.homepage.toUri(), with(EthAccountDelegate) { account.toEthAddress() }).let { subscribeParams -> + Notify.Params.Subscribe(explorerApp.dappUrl.toUri(), with(EthAccountDelegate) { account.toEthAddress() }).let { subscribeParams -> NotifyClient.subscribe( params = subscribeParams, onSuccess = { From 0d12cf8ba73df48e58493e35cec43f9745cb9ccc Mon Sep 17 00:00:00 2001 From: szymon Date: Wed, 8 Nov 2023 16:29:49 +0100 Subject: [PATCH 25/44] feat: Update statement --- .../notify/engine/domain/RegisterIdentityUseCase.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol/notify/src/main/kotlin/com/walletconnect/notify/engine/domain/RegisterIdentityUseCase.kt b/protocol/notify/src/main/kotlin/com/walletconnect/notify/engine/domain/RegisterIdentityUseCase.kt index 16edd4f5fe..30c514d00c 100644 --- a/protocol/notify/src/main/kotlin/com/walletconnect/notify/engine/domain/RegisterIdentityUseCase.kt +++ b/protocol/notify/src/main/kotlin/com/walletconnect/notify/engine/domain/RegisterIdentityUseCase.kt @@ -22,8 +22,8 @@ internal class RegisterIdentityUseCase( companion object { private const val LIMITED_STATEMENT = - "I further authorize this app to send and receive messages on my behalf for THIS domain using my WalletConnect account. Read more at https://walletconnect.com/account" + "I further authorize this app to send me notifications. Read more at https://walletconnect.com/notifications" private const val UNLIMITED_STATEMENT = - "I further authorize this app to send and receive messages on my behalf for ALL domains using my WalletConnect account. Read more at https://walletconnect.com/account" + "I further authorize this app to view and manage my notifications for ALL apps. Read more at https://walletconnect.com/notifications" } } From eed73eb2dcb126fba380786dbb0e671cf5141d04 Mon Sep 17 00:00:00 2001 From: Kacper Date: Wed, 8 Nov 2023 16:22:46 +0100 Subject: [PATCH 26/44] Ui screen improvements --- .../ui/components/button/ConnectButton.kt | 2 +- .../ui/components/internal/Web3ModalTopBar.kt | 2 +- .../ui/components/internal/commons/Help.kt | 6 +- .../ui/components/internal/commons/Icons.kt | 10 ++- .../components/internal/commons/ListSelect.kt | 3 +- .../ui/components/internal/commons/Wallets.kt | 7 +- .../internal/commons/button/Button.kt | 36 +++++++-- .../internal/commons/button/ChipButton.kt | 53 +++++++++--- .../internal/commons/entry/AccountEntry.kt | 1 + .../internal/commons/entry/StoreEntry.kt | 3 +- .../internal/commons/inputs/SearchInput.kt | 2 +- .../components/internal/root/Web3ModalRoot.kt | 2 +- .../internal/snackbar/ModalSnackBar.kt | 2 +- .../web3/modal/ui/navigation/Route.kt | 7 +- .../routes/account/AccountNavigationGraph.kt | 8 +- .../ui/routes/account/account/AccountRoute.kt | 11 ++- .../what_is_network/WhatIsNetworkRoute.kt | 80 +++++++++++++++++++ .../routes/connect/ConnectNavigationGraph.kt | 6 +- .../connect/all_wallets/AllWalletsRoute.kt | 12 +-- .../connect_wallet/ConnectWalletRoute.kt | 16 ++-- .../connect/redirect/RedirectWalletScreen.kt | 10 +-- .../routes/connect/scan_code/ScanCodeRoute.kt | 2 +- .../connect/what_is_wallet/WhatIsWallet.kt | 70 ++++++---------- .../src/main/res/drawable/ic_copy.xml | 12 +-- .../main/res/drawable/ic_forward_chevron.xml | 12 +-- .../src/main/res/drawable/ic_wallet.xml | 12 +-- .../sample/modal/MainActivity.kt | 2 +- 27 files changed, 253 insertions(+), 136 deletions(-) create mode 100644 product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/what_is_network/WhatIsNetworkRoute.kt diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/button/ConnectButton.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/button/ConnectButton.kt index 6d2208892d..7220021b95 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/button/ConnectButton.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/button/ConnectButton.kt @@ -55,7 +55,7 @@ internal fun ConnectButton( ) {} } else { val text = when (size) { - ConnectButtonSize.NORMAL -> "Connect Wallet" + ConnectButtonSize.NORMAL -> "Connect wallet" ConnectButtonSize.SMALL -> "Connect" } TextButton( diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalTopBar.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalTopBar.kt index a5844fee97..dec5a462a7 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalTopBar.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalTopBar.kt @@ -24,7 +24,7 @@ internal fun Web3ModalTopBar( ) { Row( modifier = Modifier - .height(60.dp) + .height(64.dp) .fillMaxWidth() .padding(horizontal = 20.dp), verticalAlignment = Alignment.CenterVertically diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Help.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Help.kt index ff6ceefc12..92aa025254 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Help.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Help.kt @@ -31,9 +31,7 @@ internal fun HelpSection( assets: List ) { Column( - modifier = Modifier - .fillMaxWidth() - .padding(vertical = 8.dp), + modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally ) { Row { @@ -90,7 +88,7 @@ internal fun WhatIsNetworkLink(onClick: () -> Unit) { verticalAlignment = Alignment.CenterVertically ) { QuestionMarkIcon(tint = Web3ModalTheme.colors.accent100, modifier = Modifier.size(12.dp)) - HorizontalSpacer(width = 6.dp) + HorizontalSpacer(width = 4.dp) Text( text = "What is a network", style = Web3ModalTheme.typo.small600.copy(color = Web3ModalTheme.colors.accent100) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Icons.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Icons.kt index 82dd869a1f..85ada44b25 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Icons.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Icons.kt @@ -97,7 +97,7 @@ internal fun WalletIcon( Icon( imageVector = ImageVector.vectorResource(id = R.drawable.ic_wallet), contentDescription = ContentDescription.WALLET.description, - modifier = Modifier.size(14.dp), + modifier = Modifier.size(12.dp), tint = tint ) } @@ -159,9 +159,10 @@ internal fun RecentTransactionIcon( imageVector = ImageVector.vectorResource(id = R.drawable.ic_swap), contentDescription = ContentDescription.SWAP.description, modifier = Modifier + .border(2.dp, Web3ModalTheme.colors.grayGlass02, shape = CircleShape) + .padding(2.dp) .size(32.dp) .background(Web3ModalTheme.colors.grayGlass10, shape = CircleShape) - .border(2.dp, Web3ModalTheme.colors.grayGlass02, shape = CircleShape) .padding(8.dp), tint = tint ) @@ -175,9 +176,10 @@ internal fun DisconnectIcon( imageVector = ImageVector.vectorResource(id = R.drawable.ic_disconnect), contentDescription = ContentDescription.DISCONNECT.description, modifier = Modifier + .border(2.dp, Web3ModalTheme.colors.grayGlass05, shape = CircleShape) + .padding(2.dp) .size(32.dp) .background(Web3ModalTheme.colors.grayGlass10, shape = CircleShape) - .border(2.dp, Web3ModalTheme.colors.grayGlass05, shape = CircleShape) .padding(8.dp), tint = tint ) @@ -283,7 +285,7 @@ internal fun ForwardIcon( tint: Color = Web3ModalTheme.colors.inverse100 ) { Icon( - imageVector = ImageVector.vectorResource(id = R.drawable.ic_forward_chevron), + imageVector = ImageVector.vectorResource(id = R.drawable.ic_chevron_right), contentDescription = ContentDescription.FORWARD_ARROW.description, tint = tint, modifier = Modifier.size(12.dp), diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/ListSelect.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/ListSelect.kt index d0a8521613..fb8bf425d9 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/ListSelect.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/ListSelect.kt @@ -74,6 +74,7 @@ internal fun ListSelectRow( private fun ListSelectRowPreview() { MultipleComponentsPreview( { ListSelectRow(startIcon = { WalletConnectLogo(it) }, text = "WalletConnect") {} }, - { ListSelectRow(startIcon = { WalletConnectLogo(it) }, text = "WalletConnect", isEnabled = false) {} } + { ListSelectRow(startIcon = { WalletConnectLogo(it) }, text = "WalletConnect", isEnabled = false) {} }, + { ListSelectRow(startIcon = { WalletConnectLogo(it) }, text = "WalletConnect", label = { InstalledLabel() }) {} }, ) } \ No newline at end of file diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Wallets.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Wallets.kt index b85eabcbc7..e7998cff25 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Wallets.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Wallets.kt @@ -18,6 +18,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow @@ -115,9 +116,9 @@ internal fun WalletGridItem( WalletImage( url = wallet.imageUrl, modifier = Modifier - .size(54.dp) - .clip(RoundedCornerShape(16.dp)) - .border(width = 1.dp, color = Web3ModalTheme.colors.grayGlass10, shape = RoundedCornerShape(16.dp)) + .size(56.dp) + .clip(RoundedCornerShape(12.dp)) + .border(width = 1.dp, color = Web3ModalTheme.colors.grayGlass10, shape = RoundedCornerShape(12.dp)) ) VerticalSpacer(height = 8.dp) Text( diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/Button.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/Button.kt index 0a25acfcc8..5af18a62dc 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/Button.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/Button.kt @@ -4,6 +4,7 @@ import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.fillMaxHeight @@ -22,9 +23,11 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.compose.ui.unit.dp import com.walletconnect.web3.modal.ui.components.internal.commons.HorizontalSpacer import com.walletconnect.web3.modal.ui.components.internal.commons.RetryIcon +import com.walletconnect.web3.modal.ui.components.internal.commons.WalletIcon import com.walletconnect.web3.modal.ui.previews.ComponentPreview import com.walletconnect.web3.modal.ui.previews.MultipleComponentsPreview import com.walletconnect.web3.modal.ui.previews.UiModePreview +import com.walletconnect.web3.modal.ui.theme.Web3ModalTheme @Composable internal fun TryAgainButton( @@ -37,6 +40,7 @@ internal fun TryAgainButton( image = { RetryIcon(it) }, style = style, size = size, + paddingValues = PaddingValues(start = 12.dp, top = 8.dp, bottom = 8.dp, end = 16.dp), onClick = onClick ) } @@ -47,13 +51,35 @@ internal fun ImageButton( image: @Composable (Color) -> Unit, style: ButtonStyle, size: ButtonSize, + paddingValues: PaddingValues? = null, isEnabled: Boolean = true, - onClick: () -> Unit, + onClick: (() -> Unit)? = null ) { - StyledButton(style = style, size = size, isEnabled = isEnabled, onClick = onClick) { - image(it.tint) - HorizontalSpacer(width = 4.dp) - Text(text = text, style = it.textStyle, modifier = Modifier.fillMaxHeight()) + val backgroundColor = style.getBackgroundColor(isEnabled) + val borderColor = style.getBorder(isEnabled) + val tint = style.getTextColor(isEnabled) + val textStyle = size.getTextStyle().copy(color = tint) + val isClickEnabled = isEnabled && style != ButtonStyle.LOADING + val height = size.getHeight() + + Surface( + color = Color.Transparent, + shape = RoundedCornerShape(100) + ) { + Row( + modifier = Modifier + .height(height) + .clickable(isClickEnabled) { onClick?.invoke() } + .border(width = 1.dp, color = borderColor, shape = RoundedCornerShape(100)) + .background(backgroundColor) + .padding(paddingValues ?: size.getContentPadding()), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically + ) { + image(tint) + HorizontalSpacer(width = 4.dp) + Text(text = text, style = textStyle) + } } } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/ChipButton.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/ChipButton.kt index f891e6638d..bc215aca6a 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/ChipButton.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/ChipButton.kt @@ -1,7 +1,21 @@ package com.walletconnect.web3.modal.ui.components.internal.commons.button +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.Surface import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider @@ -19,20 +33,37 @@ internal fun ChipButton( endIcon: @Composable (Color) -> Unit, style: ButtonStyle, size: ButtonSize, + paddingValues: PaddingValues? = null, isEnabled: Boolean = true, onClick: () -> Unit ) { - StyledButton( - style = style, - size = size, - isEnabled = isEnabled, - onClick = onClick - ) { buttonData -> - startIcon(buttonData.tint) - HorizontalSpacer(width = 4.dp) - Text(text = text, style = buttonData.textStyle) - HorizontalSpacer(width = 4.dp) - endIcon(buttonData.tint) + val backgroundColor = style.getBackgroundColor(isEnabled) + val borderColor = style.getBorder(isEnabled) + val tint = style.getTextColor(isEnabled) + val textStyle = size.getTextStyle().copy(color = tint) + val isClickEnabled = isEnabled && style != ButtonStyle.LOADING + val height = size.getHeight() + + Surface( + color = Color.Transparent, + shape = RoundedCornerShape(100) + ) { + Row( + modifier = Modifier + .height(height) + .clickable(isClickEnabled) { onClick() } + .border(width = 1.dp, color = borderColor, shape = RoundedCornerShape(100)) + .background(backgroundColor) + .padding(paddingValues ?: size.getContentPadding()), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically + ) { + startIcon(tint) + HorizontalSpacer(width = 4.dp) + Text(text = text, style = textStyle, modifier = Modifier.fillMaxHeight()) + HorizontalSpacer(width = 4.dp) + endIcon(tint) + } } } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/entry/AccountEntry.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/entry/AccountEntry.kt index 65c47f5cf8..7e558cd40e 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/entry/AccountEntry.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/entry/AccountEntry.kt @@ -54,6 +54,7 @@ internal fun AccountEntry( AccountEntryState.NEXT -> ChevronRightIcon(entryColors.secondaryColor) AccountEntryState.INFO -> {} } + HorizontalSpacer(width = 6.dp) } } } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/entry/StoreEntry.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/entry/StoreEntry.kt index 5ecdcbafbf..e8ddef096f 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/entry/StoreEntry.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/entry/StoreEntry.kt @@ -67,11 +67,12 @@ private fun GetButton(onClick: () -> Unit) { modifier = Modifier .border(width = 1.dp, color = Web3ModalTheme.colors.grayGlass10, shape = CircleShape) .clickable { onClick() } - .padding(horizontal = 12.dp, vertical = 6.dp), + .padding(start = 12.dp, end = 8.dp, top = 6.dp, bottom = 6.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center ) { Text(text = "Get", style = Web3ModalTheme.typo.small500.copy(color = Web3ModalTheme.colors.accent100)) + HorizontalSpacer(width = 4.dp) ForwardIcon(tint = Web3ModalTheme.colors.accent100) } } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/inputs/SearchInput.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/inputs/SearchInput.kt index eaeab27df7..6260b06005 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/inputs/SearchInput.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/inputs/SearchInput.kt @@ -95,7 +95,7 @@ internal fun SearchInput( when { searchState.isFocused -> { borderColor = Web3ModalTheme.colors.accent100 - backgroundColor = Web3ModalTheme.colors.grayGlass05 + backgroundColor = Web3ModalTheme.colors.grayGlass10 } isEnabled -> { borderColor = Web3ModalTheme.colors.grayGlass05 diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/root/Web3ModalRoot.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/root/Web3ModalRoot.kt index bf1864ae38..835c04e200 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/root/Web3ModalRoot.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/root/Web3ModalRoot.kt @@ -79,7 +79,7 @@ internal fun Web3ModalRoot( Column( modifier = Modifier .fillMaxWidth() - .background(Web3ModalTheme.colors.background.color100) + .background(Web3ModalTheme.colors.background.color125) ) { title?.let { title -> Web3ModalTopBar( diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackBar.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackBar.kt index 0804206f92..ce00b5f248 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackBar.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackBar.kt @@ -35,7 +35,7 @@ internal fun ModalSnackBar( modifier = Modifier .height(40.dp) .background( - color = Web3ModalTheme.colors.background.color125, + color = Web3ModalTheme.colors.grayGlass05, shape = shape ) .border( diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/navigation/Route.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/navigation/Route.kt index 0dfc527a03..9c14272222 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/navigation/Route.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/navigation/Route.kt @@ -6,12 +6,10 @@ enum class Route(val path: String, val title: String? = null) { //Common WEB3MODAL("web3_modal"), CHOOSE_NETWORK("choose_network", "Select network"), - WHAT_IS_NETWORK("what_is_network", "What is a network?"), - //Connect routes CONNECT_YOUR_WALLET("connect_your_wallet", "Connect wallet"), QR_CODE("qr_code", "WalletConnect"), - WHAT_IS_WALLET("what_is_wallet", "What is wallet?"), + WHAT_IS_WALLET("what_is_wallet", "What is a wallet?"), GET_A_WALLET("get_a_wallet", "Get a wallet"), ALL_WALLETS("all_wallets", "All wallets"), REDIRECT("redirect"), @@ -20,5 +18,6 @@ enum class Route(val path: String, val title: String? = null) { ACCOUNT("account"), CHANGE_NETWORK("change_network", "Select network"), CHAIN_SWITCH_REDIRECT("chain_switch_redirect"), - RECENT_TRANSACTION("recent_transaction") + RECENT_TRANSACTION("recent_transaction"), + WHAT_IS_NETWORK("what_is_network", "What is a network?") } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/AccountNavigationGraph.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/AccountNavigationGraph.kt index 7ca00b573a..e4facecfce 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/AccountNavigationGraph.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/AccountNavigationGraph.kt @@ -9,8 +9,7 @@ import com.walletconnect.web3.modal.ui.navigation.Route import com.walletconnect.web3.modal.ui.navigation.account.chainSwitchRoute import com.walletconnect.web3.modal.ui.routes.account.account.AccountRoute import com.walletconnect.web3.modal.ui.routes.account.change_network.ChangeNetworkRoute -import com.walletconnect.web3.modal.ui.routes.connect.what_is_wallet.WhatIsWallet -import com.walletconnect.web3.modal.ui.routes.connect.what_is_wallet.WhatIsWalletOption +import com.walletconnect.web3.modal.ui.routes.account.what_is_network.WhatIsNetworkRoute import com.walletconnect.web3.modal.ui.utils.AnimatedNavGraph @Composable @@ -41,10 +40,7 @@ internal fun AccountNavGraph( ChangeNetworkRoute(accountState = accountState) } composable(route = Route.WHAT_IS_WALLET.path) { - WhatIsWallet( - navController = navController, - option = WhatIsWalletOption.LEARN_MORE - ) + WhatIsNetworkRoute() } chainSwitchRoute(accountState = accountState) } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/account/AccountRoute.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/account/AccountRoute.kt index 1af4c2f23e..740d1f2b75 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/account/AccountRoute.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/account/AccountRoute.kt @@ -93,7 +93,7 @@ private fun AccountScreen( VerticalSpacer(height = 20.dp) AccountName(accountData) balance?.let { balance -> - VerticalSpacer(height = 8.dp) + VerticalSpacer(height = 4.dp) Text( text = balance.valueWithSymbol, style = Web3ModalTheme.typo.paragraph400.copy(Web3ModalTheme.colors.foreground.color200) @@ -135,3 +135,12 @@ private fun PreviewAccountScreen() { AccountScreen(accountDataPreview, ethereumChain,null, {}, {}, {}) } } + +@UiModePreview +@Composable +private fun PreviewAccountScreenWithBalance() { + Web3ModalPreview { + AccountScreen(accountDataPreview, ethereumChain, Balance(ethereumChain.token, "0000000"), {}, {}, {}) + } +} + diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/what_is_network/WhatIsNetworkRoute.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/what_is_network/WhatIsNetworkRoute.kt new file mode 100644 index 0000000000..d14da4199a --- /dev/null +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/what_is_network/WhatIsNetworkRoute.kt @@ -0,0 +1,80 @@ +package com.walletconnect.web3.modal.ui.routes.account.what_is_network + +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.Surface +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalUriHandler +import androidx.compose.ui.unit.dp +import com.walletconnect.web3.modal.R +import com.walletconnect.web3.modal.ui.components.internal.commons.ExternalIcon +import com.walletconnect.web3.modal.ui.components.internal.commons.HelpSection +import com.walletconnect.web3.modal.ui.components.internal.commons.HorizontalSpacer +import com.walletconnect.web3.modal.ui.components.internal.commons.VerticalSpacer +import com.walletconnect.web3.modal.ui.components.internal.commons.WalletIcon +import com.walletconnect.web3.modal.ui.components.internal.commons.button.ButtonSize +import com.walletconnect.web3.modal.ui.components.internal.commons.button.ButtonStyle +import com.walletconnect.web3.modal.ui.components.internal.commons.button.ImageButton +import com.walletconnect.web3.modal.ui.previews.UiModePreview +import com.walletconnect.web3.modal.ui.previews.Web3ModalPreview +import com.walletconnect.web3.modal.ui.theme.Web3ModalTheme + +@Composable +internal fun WhatIsNetworkRoute() { + val uriHandler = LocalUriHandler.current + + WhatIsNetwork { uriHandler.openUri("https://ethereum.org/en/developers/docs/networks/") } +} + +@Composable +private fun WhatIsNetwork( + onLearnMoreClick: () -> Unit +) { + Column( + modifier = Modifier.padding(horizontal = 20.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Spacer(modifier = Modifier.height(20.dp)) + HelpSection( + title = "The system's nuts and bolts", + body = "A network is what brings the blockchain to life, as this technical infrastructure allows apps to access the ledger and smart contract services.", + assets = listOf(R.drawable.network, R.drawable.layers, R.drawable.system) + ) + Spacer(modifier = Modifier.height(24.dp)) + HelpSection( + title = "Designed for different uses", + body = "Each network is designed differently, and may therefore suit certain apps and experiences.", + assets = listOf(R.drawable.noun, R.drawable.defi_alt, R.drawable.dao) + ) + VerticalSpacer(height = 20.dp) + ImageButton( + text = "Learn more", + image = { ExternalIcon(Web3ModalTheme.colors.inverse100) }, + style = ButtonStyle.MAIN, + size = ButtonSize.S, + paddingValues = PaddingValues(start = 8.dp, top = 6.dp, end = 12.dp, 6.dp), + onClick = { onLearnMoreClick() } + ) + Spacer(modifier = Modifier.height(30.dp)) + } +} + +@UiModePreview +@Composable +private fun WhatIsNetworkPreview() { + Web3ModalPreview { + WhatIsNetworkRoute() + } +} diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectNavigationGraph.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectNavigationGraph.kt index bf05091a4b..a66fec7e67 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectNavigationGraph.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectNavigationGraph.kt @@ -14,7 +14,6 @@ import com.walletconnect.web3.modal.ui.routes.connect.connect_wallet.ConnectWall import com.walletconnect.web3.modal.ui.routes.connect.get_wallet.GetAWalletRoute import com.walletconnect.web3.modal.ui.routes.connect.what_is_wallet.WhatIsWallet import com.walletconnect.web3.modal.ui.routes.connect.scan_code.ScanQRCodeRoute -import com.walletconnect.web3.modal.ui.routes.connect.what_is_wallet.WhatIsWalletOption import com.walletconnect.web3.modal.ui.utils.AnimatedNavGraph @Composable @@ -39,10 +38,7 @@ internal fun ConnectionNavGraph( ScanQRCodeRoute(connectState = connectState) } composable(route = Route.WHAT_IS_WALLET.path) { - WhatIsWallet( - navController = navController, - option = WhatIsWalletOption.GET_WALLET - ) + WhatIsWallet(navController = navController,) } composable(Route.GET_A_WALLET.path) { GetAWalletRoute(wallets = connectState.getNotInstalledWallets() ) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/all_wallets/AllWalletsRoute.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/all_wallets/AllWalletsRoute.kt index 9a0df861e7..77945967db 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/all_wallets/AllWalletsRoute.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/all_wallets/AllWalletsRoute.kt @@ -145,9 +145,9 @@ private fun WalletsGrid( Box { LazyVerticalGrid( state = gridState, - columns = GridCells.Adaptive(76.dp), + columns = GridCells.FixedSize(76.dp), modifier = Modifier - .padding(start = 12.dp, end = 12.dp) + .padding(horizontal = 10.dp) .graphicsLayer { alpha = 0.99f } .drawWithContent { val colors = listOf(Color.Transparent, color) @@ -156,7 +156,8 @@ private fun WalletsGrid( brush = Brush.verticalGradient(colors, startY = 0f, endY = 40f), blendMode = BlendMode.DstIn, ) - } + }, + horizontalArrangement = Arrangement.SpaceBetween, ) { walletsGridItems(walletsData.wallets, onWalletItemClick) if (walletsData.loadingState == LoadingState.APPEND) { @@ -213,10 +214,11 @@ private fun SearchInputRow( val focusBorderWidth: Dp = 4.dp val focusedSpacing: Dp = defaultSpacing - focusBorderWidth val focusBorderColor = Web3ModalTheme.colors.accent20 + val state by searchState.state.collectAsState() val paddingValues: PaddingValues val spacerValue: Dp - if (searchState.isFocused) { + if (state.isFocused) { spacerValue = focusedSpacing paddingValues = PaddingValues(start = focusedSpacing, top = focusedSpacing, bottom = focusedSpacing, end = defaultSpacing) } else { @@ -229,7 +231,7 @@ private fun SearchInputRow( ) { Box(modifier = Modifier .weight(1f) - .conditionalModifier(searchState.isFocused) { + .conditionalModifier(state.isFocused) { border(width = focusBorderWidth, color = focusBorderColor, RoundedCornerShape(16.dp)).padding(focusBorderWidth) }) { SearchInput(searchState) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/connect_wallet/ConnectWalletRoute.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/connect_wallet/ConnectWalletRoute.kt index 2786522f0d..a92fb61af2 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/connect_wallet/ConnectWalletRoute.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/connect_wallet/ConnectWalletRoute.kt @@ -49,14 +49,12 @@ private fun ConnectWalletContent( onWalletItemClick: (Wallet) -> Unit, onViewAllClick: () -> Unit, ) { - Column { - WalletsList( - wallets = wallets, - walletsTotalCount = walletsTotalCount, - onWalletItemClick = onWalletItemClick, - onViewAllClick = onViewAllClick, - ) - } + WalletsList( + wallets = wallets, + walletsTotalCount = walletsTotalCount, + onWalletItemClick = onWalletItemClick, + onViewAllClick = onViewAllClick, + ) } @Composable @@ -79,7 +77,7 @@ private fun WalletsList( private fun walletSizeLabel(total: Int): String = with(total % 10) { if (this != 0) { - "${total-this}+" + "${total - this}+" } else { total.toString() } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt index 83a157964c..b8622455d2 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt @@ -406,9 +406,7 @@ private fun NotDetectedWalletState( RedirectLabel(state = state, wallet = wallet) VerticalSpacer(height = 20.dp) TryAgainButton(onClick = onRetry) - VerticalSpacer(height = 16.dp) - FullWidthDivider() - VerticalSpacer(height = 16.dp) + VerticalSpacer(height = 32.dp) StoreEntry(text = "Don't have ${wallet.name}?", onClick = onOpenPlayStore) } @@ -418,13 +416,13 @@ private fun RejectWalletImage(url: String) { WalletImage( url = url, modifier = Modifier .size(80.dp) - .border(width = 1.dp, color = Web3ModalTheme.colors.grayGlass10, shape = RoundedCornerShape(25.dp)) - .clip(RoundedCornerShape(25.dp)) + .border(width = 1.dp, color = Web3ModalTheme.colors.grayGlass10, shape = RoundedCornerShape(28.dp)) + .clip(RoundedCornerShape(28.dp)) ) Box( modifier = Modifier .align(Alignment.BottomEnd) - .background(Web3ModalTheme.colors.background.color100, shape = CircleShape) + .background(Web3ModalTheme.colors.background.color125, shape = CircleShape) .padding(2.dp) ) { DeclinedIcon() diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/scan_code/ScanCodeRoute.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/scan_code/ScanCodeRoute.kt index 061b75b498..16563f0c98 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/scan_code/ScanCodeRoute.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/scan_code/ScanCodeRoute.kt @@ -115,7 +115,7 @@ private fun PortraitContent( Column( modifier = Modifier .fillMaxWidth() - .padding(vertical = 20.dp, horizontal = 28.dp), + .padding(20.dp), horizontalAlignment = Alignment.CenterHorizontally ) { QRCode(uri = uri) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/what_is_wallet/WhatIsWallet.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/what_is_wallet/WhatIsWallet.kt index a5b1344f6e..1da101d2f7 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/what_is_wallet/WhatIsWallet.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/what_is_wallet/WhatIsWallet.kt @@ -1,71 +1,42 @@ package com.walletconnect.web3.modal.ui.routes.connect.what_is_wallet +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.unit.dp import androidx.navigation.NavController import com.walletconnect.web3.modal.ui.navigation.Route import com.walletconnect.web3.modal.R import com.walletconnect.web3.modal.ui.components.internal.commons.ExternalIcon import com.walletconnect.web3.modal.ui.components.internal.commons.HelpSection +import com.walletconnect.web3.modal.ui.components.internal.commons.HorizontalSpacer +import com.walletconnect.web3.modal.ui.components.internal.commons.VerticalSpacer import com.walletconnect.web3.modal.ui.components.internal.commons.WalletIcon import com.walletconnect.web3.modal.ui.components.internal.commons.button.ButtonSize import com.walletconnect.web3.modal.ui.components.internal.commons.button.ButtonStyle import com.walletconnect.web3.modal.ui.components.internal.commons.button.ImageButton import com.walletconnect.web3.modal.ui.previews.UiModePreview import com.walletconnect.web3.modal.ui.previews.Web3ModalPreview - -internal enum class WhatIsWalletOption { - GET_WALLET, LEARN_MORE -} +import com.walletconnect.web3.modal.ui.theme.Web3ModalTheme @Composable internal fun WhatIsWallet( - navController: NavController, - option: WhatIsWalletOption + navController: NavController ) { - val uriHandler = LocalUriHandler.current - - WhatIsWallet( - optionButton = { - ImageButton( - text = option.label(), - image = { option.Icon(it) }, - style = ButtonStyle.MAIN, - size = ButtonSize.S, - onClick = { - when (option) { - WhatIsWalletOption.GET_WALLET -> navController.navigate(Route.GET_A_WALLET.path) - WhatIsWalletOption.LEARN_MORE -> uriHandler.openUri("https://ethereum.org/en/developers/docs/networks/") - } - } - ) - } - ) -} - -private fun WhatIsWalletOption.label() = when (this) { - WhatIsWalletOption.GET_WALLET -> "Get a wallet" - WhatIsWalletOption.LEARN_MORE -> "Learn more" -} - -@Composable -private fun WhatIsWalletOption.Icon(tint: Color) { - when (this) { - WhatIsWalletOption.GET_WALLET -> WalletIcon(tint) - WhatIsWalletOption.LEARN_MORE -> ExternalIcon(tint) - } + WhatIsWallet { navController.navigate(Route.GET_A_WALLET.path) } } @Composable private fun WhatIsWallet( - optionButton: @Composable () -> Unit + onGetAWalletClick: () -> Unit ) { Column( modifier = Modifier @@ -73,27 +44,34 @@ private fun WhatIsWallet( .verticalScroll(rememberScrollState()), horizontalAlignment = Alignment.CenterHorizontally ) { - Spacer(modifier = Modifier.height(20.dp)) + VerticalSpacer(20.dp) HelpSection( title = "One login for all of web3", body = "Log in to any app by connecting your wallet. Say goodbye to countless passwords!", assets = listOf(R.drawable.login, R.drawable.profile, R.drawable.lock) ) - Spacer(modifier = Modifier.height(24.dp)) + VerticalSpacer(24.dp) HelpSection( title = "A home for your digital assets", body = "A wallet lets you store, send and receive digital assets like cryptocurrencies and NFTs.", assets = listOf(R.drawable.defi, R.drawable.nft, R.drawable.eth) ) - Spacer(modifier = Modifier.height(24.dp)) + VerticalSpacer(24.dp) HelpSection( title = "Your gateway to a new web", body = "With your wallet, you can explore and interact with DeFi, NFTs, DAOs, and much more.", assets = listOf(R.drawable.browser, R.drawable.noun, R.drawable.dao) ) - Spacer(modifier = Modifier.height(20.dp)) - optionButton() - Spacer(modifier = Modifier.height(30.dp)) + VerticalSpacer(20.dp) + ImageButton( + text = "Get a wallet", + image = { WalletIcon(Web3ModalTheme.colors.inverse100) }, + style = ButtonStyle.MAIN, + size = ButtonSize.S, + paddingValues = PaddingValues(start = 8.dp, top = 6.dp, end = 12.dp, 6.dp), + onClick = { onGetAWalletClick() } + ) + VerticalSpacer(30.dp) } } diff --git a/product/web3modal/src/main/res/drawable/ic_copy.xml b/product/web3modal/src/main/res/drawable/ic_copy.xml index 74193f7dbf..0a07c7e5b2 100644 --- a/product/web3modal/src/main/res/drawable/ic_copy.xml +++ b/product/web3modal/src/main/res/drawable/ic_copy.xml @@ -1,10 +1,10 @@ + android:width="14dp" + android:height="15dp" + android:viewportWidth="14" + android:viewportHeight="15"> diff --git a/product/web3modal/src/main/res/drawable/ic_forward_chevron.xml b/product/web3modal/src/main/res/drawable/ic_forward_chevron.xml index 73e54a7cd6..c27048251c 100644 --- a/product/web3modal/src/main/res/drawable/ic_forward_chevron.xml +++ b/product/web3modal/src/main/res/drawable/ic_forward_chevron.xml @@ -1,10 +1,10 @@ + android:width="14dp" + android:height="15dp" + android:viewportWidth="14" + android:viewportHeight="15"> diff --git a/product/web3modal/src/main/res/drawable/ic_wallet.xml b/product/web3modal/src/main/res/drawable/ic_wallet.xml index 8b2c31157e..000126ce3a 100644 --- a/product/web3modal/src/main/res/drawable/ic_wallet.xml +++ b/product/web3modal/src/main/res/drawable/ic_wallet.xml @@ -1,10 +1,10 @@ + android:width="14dp" + android:height="14dp" + android:viewportWidth="14" + android:viewportHeight="14"> diff --git a/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/MainActivity.kt b/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/MainActivity.kt index 7d133b00e8..4e3eadbecf 100644 --- a/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/MainActivity.kt +++ b/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/MainActivity.kt @@ -99,7 +99,7 @@ class MainActivity : ComponentActivity() { darkColors = darkColors ) { ModalBottomSheetLayout( - sheetShape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp), + sheetShape = RoundedCornerShape(topStart = 36.dp, topEnd = 36.dp), bottomSheetNavigator = bottomSheetNavigator, ) { Scaffold( From b63032b85a25884787248b0dc3c7edd6097e40d5 Mon Sep 17 00:00:00 2001 From: Kacper Date: Thu, 9 Nov 2023 10:47:10 +0100 Subject: [PATCH 27/44] add scroll to what is network --- .../what_is_network/WhatIsNetworkRoute.kt | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/what_is_network/WhatIsNetworkRoute.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/what_is_network/WhatIsNetworkRoute.kt index d14da4199a..2117856e00 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/what_is_network/WhatIsNetworkRoute.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/what_is_network/WhatIsNetworkRoute.kt @@ -1,29 +1,21 @@ package com.walletconnect.web3.modal.ui.routes.account.what_is_network -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Surface -import androidx.compose.material.Text +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.unit.dp import com.walletconnect.web3.modal.R import com.walletconnect.web3.modal.ui.components.internal.commons.ExternalIcon import com.walletconnect.web3.modal.ui.components.internal.commons.HelpSection -import com.walletconnect.web3.modal.ui.components.internal.commons.HorizontalSpacer import com.walletconnect.web3.modal.ui.components.internal.commons.VerticalSpacer -import com.walletconnect.web3.modal.ui.components.internal.commons.WalletIcon import com.walletconnect.web3.modal.ui.components.internal.commons.button.ButtonSize import com.walletconnect.web3.modal.ui.components.internal.commons.button.ButtonStyle import com.walletconnect.web3.modal.ui.components.internal.commons.button.ImageButton @@ -43,16 +35,18 @@ private fun WhatIsNetwork( onLearnMoreClick: () -> Unit ) { Column( - modifier = Modifier.padding(horizontal = 20.dp), + modifier = Modifier + .padding(horizontal = 20.dp) + .verticalScroll(rememberScrollState()), horizontalAlignment = Alignment.CenterHorizontally ) { - Spacer(modifier = Modifier.height(20.dp)) + VerticalSpacer(20.dp) HelpSection( title = "The system's nuts and bolts", body = "A network is what brings the blockchain to life, as this technical infrastructure allows apps to access the ledger and smart contract services.", assets = listOf(R.drawable.network, R.drawable.layers, R.drawable.system) ) - Spacer(modifier = Modifier.height(24.dp)) + VerticalSpacer(24.dp) HelpSection( title = "Designed for different uses", body = "Each network is designed differently, and may therefore suit certain apps and experiences.", From e539887a3655a3d25302b3ed23bcbd402035e0bf Mon Sep 17 00:00:00 2001 From: Kacper Date: Thu, 9 Nov 2023 12:22:57 +0100 Subject: [PATCH 28/44] Platform tab and redirect wallet screen size fixes --- .../components/internal/commons/Dividers.kt | 2 +- .../ui/components/internal/commons/Icons.kt | 2 +- .../internal/commons/switch/PlatformTabRow.kt | 47 +++++--- .../connect/redirect/RedirectWalletScreen.kt | 110 +++++++++++------- .../src/main/res/drawable/ic_browser.xml | 10 ++ 5 files changed, 113 insertions(+), 58 deletions(-) create mode 100644 product/web3modal/src/main/res/drawable/ic_browser.xml diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Dividers.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Dividers.kt index 9b313994e8..dd33922fed 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Dividers.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Dividers.kt @@ -7,5 +7,5 @@ import com.walletconnect.web3.modal.ui.theme.Web3ModalTheme @Composable internal fun FullWidthDivider(modifier: Modifier = Modifier) { - Divider(color = Web3ModalTheme.colors.background.color125, modifier = modifier) + Divider(color = Web3ModalTheme.colors.grayGlass05, modifier = modifier) } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Icons.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Icons.kt index 85ada44b25..8ee81ae222 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Icons.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Icons.kt @@ -273,7 +273,7 @@ internal fun WebIcon( tint: Color = Web3ModalTheme.colors.inverse100 ) { Icon( - imageVector = ImageVector.vectorResource(id = R.drawable.ic_web), + imageVector = ImageVector.vectorResource(id = R.drawable.ic_browser), contentDescription = ContentDescription.WEB.description, tint = tint, modifier = Modifier.size(12.dp), diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/switch/PlatformTabRow.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/switch/PlatformTabRow.kt index 24c095ab54..9fd46a210a 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/switch/PlatformTabRow.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/switch/PlatformTabRow.kt @@ -10,13 +10,17 @@ import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.Icon import androidx.compose.material.Tab import androidx.compose.material.TabPosition import androidx.compose.material.TabRow @@ -27,9 +31,15 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.res.vectorResource +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex +import com.walletconnect.web3.modal.R +import com.walletconnect.web3.modal.ui.components.internal.commons.ContentDescription import com.walletconnect.web3.modal.ui.components.internal.commons.HorizontalSpacer import com.walletconnect.web3.modal.ui.components.internal.commons.MobileIcon import com.walletconnect.web3.modal.ui.components.internal.commons.WebIcon @@ -38,10 +48,9 @@ import com.walletconnect.web3.modal.ui.previews.UiModePreview import com.walletconnect.web3.modal.ui.theme.Web3ModalTheme internal enum class PlatformTab( - val value: Int, - val label: String + val value: Int, val label: String ) { - MOBILE(0, "Mobile"), WEB(1, "WebApp") + MOBILE(0, "Mobile"), WEB(1, "Browser") } @Composable @@ -51,8 +60,7 @@ internal fun rememberWalletPlatformTabs(initValue: PlatformTab = PlatformTab.MOB @Composable internal fun PlatformTabRow( - platformTab: PlatformTab, - onPlatformTabSelect: (PlatformTab) -> Unit + platformTab: PlatformTab, onPlatformTabSelect: (PlatformTab) -> Unit ) { val indicator = @Composable { tabPositions: List -> CustomIndicatorWithAnimation(tabPositions, platformTab) @@ -66,9 +74,9 @@ internal fun PlatformTabRow( indicator = indicator, divider = {}, modifier = Modifier - .width(250.dp) - .height(40.dp) - .border(width = 3.dp, color = Web3ModalTheme.colors.grayGlass02, shape = RoundedCornerShape(80f)) + .width(210.dp) + .height(32.dp) + .background(color = Web3ModalTheme.colors.grayGlass02, shape = RoundedCornerShape(80f)) ) { PlatformTab.values().forEach { val isSelected = platformTab == it @@ -87,18 +95,25 @@ internal fun PlatformTabRow( @Composable private fun TabContent(platform: PlatformTab, isSelected: Boolean) { val color = if (isSelected) Web3ModalTheme.colors.foreground.color100 else Web3ModalTheme.colors.foreground.color200 - Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center) { + Row( + modifier = Modifier.fillMaxHeight(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Center + ) { PlatformTabIcon(platform = platform, tint = color) HorizontalSpacer(width = 4.dp) - Text(text = platform.label, style = Web3ModalTheme.typo.small400.copy(color = color)) + Text( + text = platform.label, + style = Web3ModalTheme.typo.small500.copy(color = color, textAlign = TextAlign.Center), + modifier = Modifier.wrapContentHeight() + ) } } @Composable private fun CustomIndicatorWithAnimation( - tabPositions: List, - platformState: PlatformTab + tabPositions: List, platformState: PlatformTab ) { val transition = updateTransition(platformState.value, label = "") val indicatorStart by transition.animateDp( @@ -108,8 +123,7 @@ private fun CustomIndicatorWithAnimation( } else { spring(dampingRatio = 1f, stiffness = 1000f) } - }, - label = "Indicator start animation" + }, label = "Indicator start animation" ) { tabPositions[it].left } @@ -121,8 +135,7 @@ private fun CustomIndicatorWithAnimation( } else { spring(dampingRatio = 1f, stiffness = 50f) } - }, - label = "Indicator end animation" + }, label = "Indicator end animation" ) { tabPositions[it].right } @@ -132,7 +145,7 @@ private fun CustomIndicatorWithAnimation( .offset(x = indicatorStart) .wrapContentSize(align = Alignment.BottomStart) .width(indicatorEnd - indicatorStart) - .padding(2.dp) + .padding(3.dp) .fillMaxSize() .background(color = Web3ModalTheme.colors.grayGlass02, RoundedCornerShape(50)) .border(BorderStroke(1.dp, Web3ModalTheme.colors.grayGlass02), RoundedCornerShape(50)) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt index b8622455d2..aae6df6a37 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.rememberScrollState @@ -20,6 +21,7 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -30,18 +32,19 @@ import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.walletconnect.android.internal.common.modal.data.model.Wallet import com.walletconnect.modal.utils.openWebAppLink import com.walletconnect.modal.utils.openMobileLink import com.walletconnect.modal.utils.openPlayStore +import com.walletconnect.util.Empty import com.walletconnect.web3.modal.client.Modal import com.walletconnect.web3.modal.domain.delegate.Web3ModalDelegate import com.walletconnect.web3.modal.ui.components.internal.OrientationBox import com.walletconnect.web3.modal.ui.components.internal.commons.DeclinedIcon import com.walletconnect.web3.modal.ui.components.internal.commons.ExternalIcon import com.walletconnect.web3.modal.ui.components.internal.commons.entry.CopyActionEntry -import com.walletconnect.web3.modal.ui.components.internal.commons.FullWidthDivider import com.walletconnect.web3.modal.ui.components.internal.commons.LoadingBorder import com.walletconnect.web3.modal.ui.components.internal.commons.VerticalSpacer import com.walletconnect.web3.modal.ui.components.internal.commons.WalletImage @@ -155,12 +158,12 @@ private fun PortraitRedirectWalletContent( if (wallet.hasMobileWallet && wallet.hasWebApp) { PlatformTabRow(platformTab, onPlatformTabSelect) } - VerticalSpacer(height = 28.dp) - when { - platformTab == PlatformTab.WEB || redirectState == RedirectState.Loading -> WalletImageWithLoader(url = wallet.imageUrl) - redirectState == RedirectState.NotDetected || redirectState == RedirectState.Reject -> RejectWalletImage(wallet.imageUrl) - } - VerticalSpacer(height = 20.dp) + WalletImageBox( + height = 140.dp, + platformTab = platformTab, + redirectState = redirectState, + wallet = wallet + ) PlatformBox( platformTab = platformTab, mobileWalletContent = { @@ -174,6 +177,7 @@ private fun PortraitRedirectWalletContent( }, webWalletContent = { RedirectWebWalletScreen( + wallet = wallet, onCopyLinkClick = onCopyLinkClick, onOpenWebApp = onOpenWebApp ) @@ -211,12 +215,14 @@ private fun LandscapeRedirectContent( PlatformTabRow(platformTab, onPlatformTabSelect) } VerticalSpacer(height = 16.dp) - when { - platformTab == PlatformTab.WEB || redirectState == RedirectState.Loading -> WalletImageWithLoader(url = wallet.imageUrl) - redirectState == RedirectState.NotDetected || redirectState == RedirectState.Reject -> RejectWalletImage(wallet.imageUrl) - } + WalletImageBox( + height = 120.dp, + platformTab = platformTab, + redirectState = redirectState, + wallet = wallet + ) if (redirectState == RedirectState.NotDetected) { - VerticalSpacer(height = 16.dp) + VerticalSpacer(height = 8.dp) StoreEntry(text = "Don't have ${wallet.name}?", onClick = onOpenPlayStore) } VerticalSpacer(height = 16.dp) @@ -243,6 +249,7 @@ private fun LandscapeRedirectContent( }, webWalletContent = { RedirectWebWalletScreen( + wallet = wallet, onCopyLinkClick = onCopyLinkClick, onOpenWebApp = onOpenWebApp ) @@ -252,6 +259,25 @@ private fun LandscapeRedirectContent( } } +@Composable +private fun WalletImageBox( + height: Dp, + platformTab: PlatformTab, + redirectState: RedirectState, + wallet: Wallet +) { + Box( + modifier = Modifier.height(height), + contentAlignment = Alignment.Center + ) { + when { + redirectState == RedirectState.NotDetected || platformTab == PlatformTab.WEB -> RoundedWalletImage(url = wallet.imageUrl) + redirectState == RedirectState.Loading -> WalletImageWithLoader(url = wallet.imageUrl) + redirectState == RedirectState.Reject -> RejectWalletImage(wallet.imageUrl) + } + } +} + @Composable private fun RedirectLabel(state: RedirectState, wallet: Wallet) { val header: String @@ -274,20 +300,22 @@ private fun RedirectLabel(state: RedirectState, wallet: Wallet) { } RedirectState.NotDetected -> { - header = "Download ${wallet.name}" - description = "Install ${wallet.name} app to continue" + header = "App not installed" + description = String.Empty headerStyle = Web3ModalTheme.typo.paragraph400 descriptionStyle = Web3ModalTheme.typo.small400.copy(color = Web3ModalTheme.colors.foreground.color200) } } Text(text = header, style = headerStyle) - VerticalSpacer(height = 8.dp) - Text( - text = description, - style = descriptionStyle, - modifier = Modifier.padding(horizontal = 30.dp), - textAlign = TextAlign.Center - ) + if (description.isNotEmpty()) { + VerticalSpacer(height = 8.dp) + Text( + text = description, + style = descriptionStyle, + modifier = Modifier.padding(horizontal = 30.dp), + textAlign = TextAlign.Center + ) + } } @@ -297,7 +325,6 @@ private fun PlatformBox( mobileWalletContent: @Composable () -> Unit, webWalletContent: @Composable () -> Unit ) { - AnimatedContent(targetState = platformTab, label = "Platform state") { state -> when (state) { PlatformTab.MOBILE -> mobileWalletContent() @@ -324,7 +351,7 @@ private fun RedirectMobileWalletScreen( when (redirectState) { RedirectState.Loading -> LoadingState(state, wallet, onRetry, onCopyLinkClick) RedirectState.Reject -> RejectedState(state, wallet, onRetry) - RedirectState.NotDetected -> NotDetectedWalletState(state, wallet, onRetry, onOpenPlayStore) + RedirectState.NotDetected -> NotDetectedWalletState(state, wallet, onOpenPlayStore) } } } @@ -332,13 +359,20 @@ private fun RedirectMobileWalletScreen( @Composable private fun RedirectWebWalletScreen( + wallet: Wallet, onCopyLinkClick: () -> Unit, onOpenWebApp: () -> Unit ) { Column( horizontalAlignment = Alignment.CenterHorizontally ) { - Text(text = "Open and continue in a browser", style = Web3ModalTheme.typo.paragraph400) + Text(text = "Continue in ${wallet.name}", style = Web3ModalTheme.typo.paragraph400) + VerticalSpacer(height = 8.dp) + Text( + text = "Accept connection request in the wallet", + style = Web3ModalTheme.typo.small400.copy(color = Web3ModalTheme.colors.foreground.color200), + textAlign = TextAlign.Center + ) VerticalSpacer(height = 20.dp) ImageButton( text = "Open", @@ -377,14 +411,20 @@ private fun WalletImageWithLoader(url: String) { LoadingBorder( cornerRadius = 25.dp ) { - WalletImage( - url = url, modifier = Modifier - .size(80.dp) - .border(width = 1.dp, color = Web3ModalTheme.colors.grayGlass10, shape = RoundedCornerShape(25.dp)) - ) + RoundedWalletImage(url = url) } } +@Composable +private fun RoundedWalletImage(url: String) { + WalletImage( + url = url, modifier = Modifier + .size(80.dp) + .border(width = 1.dp, color = Web3ModalTheme.colors.grayGlass10, shape = RoundedCornerShape(28.dp)) + .clip(RoundedCornerShape(28.dp)) + ) +} + @Composable private fun RejectedState( state: RedirectState, @@ -400,25 +440,17 @@ private fun RejectedState( private fun NotDetectedWalletState( state: RedirectState, wallet: Wallet, - onRetry: () -> Unit, onOpenPlayStore: () -> Unit ) { RedirectLabel(state = state, wallet = wallet) - VerticalSpacer(height = 20.dp) - TryAgainButton(onClick = onRetry) - VerticalSpacer(height = 32.dp) + VerticalSpacer(height = 28.dp) StoreEntry(text = "Don't have ${wallet.name}?", onClick = onOpenPlayStore) } @Composable private fun RejectWalletImage(url: String) { Box { - WalletImage( - url = url, modifier = Modifier - .size(80.dp) - .border(width = 1.dp, color = Web3ModalTheme.colors.grayGlass10, shape = RoundedCornerShape(28.dp)) - .clip(RoundedCornerShape(28.dp)) - ) + RoundedWalletImage(url = url) Box( modifier = Modifier .align(Alignment.BottomEnd) diff --git a/product/web3modal/src/main/res/drawable/ic_browser.xml b/product/web3modal/src/main/res/drawable/ic_browser.xml new file mode 100644 index 0000000000..545a609857 --- /dev/null +++ b/product/web3modal/src/main/res/drawable/ic_browser.xml @@ -0,0 +1,10 @@ + + + From 48cc2861bd03a1ce51abbf93da3a209e26438272 Mon Sep 17 00:00:00 2001 From: Kacper Date: Thu, 9 Nov 2023 12:26:59 +0100 Subject: [PATCH 29/44] fix grid item radius --- .../web3/modal/ui/components/internal/commons/Wallets.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Wallets.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Wallets.kt index e7998cff25..e28703a217 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Wallets.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Wallets.kt @@ -117,8 +117,8 @@ internal fun WalletGridItem( url = wallet.imageUrl, modifier = Modifier .size(56.dp) - .clip(RoundedCornerShape(12.dp)) - .border(width = 1.dp, color = Web3ModalTheme.colors.grayGlass10, shape = RoundedCornerShape(12.dp)) + .clip(RoundedCornerShape(16.dp)) + .border(width = 1.dp, color = Web3ModalTheme.colors.grayGlass10, shape = RoundedCornerShape(16.dp)) ) VerticalSpacer(height = 8.dp) Text( From b47b890744cac62fc33d80b820dbbe4113474930 Mon Sep 17 00:00:00 2001 From: Kacper Date: Thu, 9 Nov 2023 15:09:49 +0100 Subject: [PATCH 30/44] Improve grids adaptive sizes and --- .../ui/components/button/AccountButton.kt | 33 ++++++++----- .../ui/components/internal/commons/Icons.kt | 8 ++-- .../ui/components/internal/commons/Wallets.kt | 2 +- .../internal/commons/button/ButtonStyle.kt | 8 ++-- .../internal/commons/button/ChipButton.kt | 2 +- .../internal/commons/inputs/SearchInput.kt | 6 ++- .../commons/network/ChainNetworkItem.kt | 4 +- .../change_network/ChangeNetworkRoute.kt | 8 ++-- .../connect/all_wallets/AllWalletsRoute.kt | 3 +- .../choose_network/ChooseNetworkRoute.kt | 10 ++-- .../connect/get_wallet/GetAWalletRoute.kt | 6 +-- .../connect/redirect/RedirectWalletScreen.kt | 47 ++++++++++--------- 12 files changed, 78 insertions(+), 59 deletions(-) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/button/AccountButton.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/button/AccountButton.kt index 8e73304872..efd45b9acb 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/button/AccountButton.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/button/AccountButton.kt @@ -5,7 +5,9 @@ import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size @@ -117,30 +119,30 @@ private fun AccountButtonMixed( Box( modifier = Modifier .clickable(isEnabled) { onClick() } + .border(width = 1.dp, color = borderColor, shape = CircleShape) .height(40.dp) .background(backgroundColor) - .border(width = 1.dp, color = borderColor, shape = CircleShape) ) { Row( - modifier = Modifier - .padding(start = 8.dp, end = 4.dp, top = 4.dp, bottom = 4.dp), + modifier = Modifier.padding(start = 8.dp, end = 4.dp).fillMaxHeight(), horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically ) { CircleNetworkImage(data = chainImage.getImageData(), size = 24.dp, isEnabled = isEnabled) - HorizontalSpacer(width = 6.dp) + HorizontalSpacer(width = 4.dp) Text(text = chainData, style = Web3ModalTheme.typo.paragraph600.copy(color = textColor)) HorizontalSpacer(width = 8.dp) ImageButton( text = address.toVisibleAddress(), image = { Box( modifier = Modifier - .size(20.dp) - .border(width = 1.dp, color = Web3ModalTheme.colors.grayGlass05, shape = CircleShape) - .padding(1.dp) + .size(22.dp) + .border(width = 2.dp, color = Web3ModalTheme.colors.grayGlass05, shape = CircleShape) + .padding(2.dp) .background(brush = Brush.linearGradient(generateAvatarColors(address)), shape = CircleShape) ) }, + paddingValues = PaddingValues(start = 4.dp, end = 8.dp), isEnabled = isEnabled, style = ButtonStyle.ACCOUNT, size = ButtonSize.ACCOUNT_S, @@ -154,19 +156,26 @@ private fun AccountButtonMixed( @Composable private fun AccountButtonNormal( - address: String, onClick: () -> Unit, isEnabled: Boolean = true + address: String, + onClick: () -> Unit, + isEnabled: Boolean = true ) { ProvideWeb3ModalThemeComposition { ImageButton( text = address.toVisibleAddress(), image = { Box( modifier = Modifier - .size(20.dp) - .border(width = 1.dp, color = Web3ModalTheme.colors.grayGlass05, shape = CircleShape) - .padding(1.dp) + .size(22.dp) + .border(width = 2.dp, color = Web3ModalTheme.colors.grayGlass05, shape = CircleShape) + .padding(2.dp) .background(brush = Brush.linearGradient(generateAvatarColors(address)), shape = CircleShape) ) - }, isEnabled = isEnabled, style = ButtonStyle.ACCOUNT, size = ButtonSize.ACCOUNT_M, onClick = onClick + }, + paddingValues = PaddingValues(start = 6.dp, end = 12.dp, top = 4.dp, bottom = 4.dp), + isEnabled = isEnabled, + style = ButtonStyle.ACCOUNT, + size = ButtonSize.ACCOUNT_S, + onClick = onClick ) } } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Icons.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Icons.kt index 8ee81ae222..7f1d9e662e 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Icons.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Icons.kt @@ -12,6 +12,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.vectorResource +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.walletconnect.modal.ui.components.common.roundedClickable import com.walletconnect.web3.modal.R @@ -73,7 +74,7 @@ internal fun RetryIcon( imageVector = ImageVector.vectorResource(id = R.drawable.ic_retry), contentDescription = ContentDescription.RETRY.description, tint = tint, - modifier = Modifier.size(12.dp), + modifier = Modifier.size(14.dp), ) } @@ -104,12 +105,13 @@ internal fun WalletIcon( @Composable internal fun ExternalIcon( - tint: Color = Web3ModalTheme.colors.foreground.color200 + tint: Color = Web3ModalTheme.colors.foreground.color200, + size: Dp = 12.dp, ) { Icon( imageVector = ImageVector.vectorResource(id = R.drawable.ic_external_link), contentDescription = ContentDescription.EXTERNAL_LINK.description, - modifier = Modifier.size(12.dp), + modifier = Modifier.size(size), tint = tint ) } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Wallets.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Wallets.kt index e28703a217..bd18404a5e 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Wallets.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/Wallets.kt @@ -101,7 +101,7 @@ internal fun WalletGridItem( onWalletItemClick: (Wallet) -> Unit ) { TransparentSurface( - modifier = Modifier.padding(4.dp), + modifier = Modifier.padding(2.dp), shape = RoundedCornerShape(16.dp) ) { Column( diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/ButtonStyle.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/ButtonStyle.kt index 5837376bb0..8e64cb11d7 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/ButtonStyle.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/ButtonStyle.kt @@ -27,10 +27,10 @@ internal fun ButtonSize.getTextStyle() = when (this) { @Composable internal fun ButtonSize.getContentPadding() = when (this) { - ButtonSize.M -> PaddingValues(horizontal = 16.dp, vertical = 8.dp) - ButtonSize.S -> PaddingValues(horizontal = 12.dp, vertical = 6.dp) - ButtonSize.ACCOUNT_M -> PaddingValues(start = 8.dp, end = 12.dp, top = 8.dp, bottom = 8.dp) - ButtonSize.ACCOUNT_S -> PaddingValues(start = 6.dp, end = 12.dp, top = 5.dp, bottom = 5.dp) + ButtonSize.M -> PaddingValues(horizontal = 16.dp) + ButtonSize.S -> PaddingValues(horizontal = 12.dp) + ButtonSize.ACCOUNT_M -> PaddingValues(start = 8.dp, end = 12.dp) + ButtonSize.ACCOUNT_S -> PaddingValues(start = 6.dp, end = 12.dp) } @Composable diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/ChipButton.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/ChipButton.kt index bc215aca6a..ae20a5cbc6 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/ChipButton.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/button/ChipButton.kt @@ -60,7 +60,7 @@ internal fun ChipButton( ) { startIcon(tint) HorizontalSpacer(width = 4.dp) - Text(text = text, style = textStyle, modifier = Modifier.fillMaxHeight()) + Text(text = text, style = textStyle) HorizontalSpacer(width = 4.dp) endIcon(tint) } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/inputs/SearchInput.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/inputs/SearchInput.kt index 6260b06005..9ea1861150 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/inputs/SearchInput.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/inputs/SearchInput.kt @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.KeyboardActions @@ -129,13 +130,14 @@ internal fun SearchInput( modifier = Modifier.padding(4.dp), verticalAlignment = Alignment.CenterVertically ) { - HorizontalSpacer(width = 6.dp) + HorizontalSpacer(width = 10.dp) Icon( tint = Web3ModalTheme.colors.foreground.color275, + modifier = Modifier.size(14.dp), imageVector = ImageVector.vectorResource(id = R.drawable.ic_search), contentDescription = ContentDescription.SEARCH.description, ) - HorizontalSpacer(width = 8.dp) + HorizontalSpacer(width = 6.dp) Box(modifier = Modifier.weight(1f)) { if (state.searchValue.isBlank()) { Text(text = "Search wallets", style = Web3ModalTheme.typo.paragraph400.copy(color = Web3ModalTheme.colors.foreground.color275)) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/network/ChainNetworkItem.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/network/ChainNetworkItem.kt index a65267164f..125383ebc3 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/network/ChainNetworkItem.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/commons/network/ChainNetworkItem.kt @@ -59,8 +59,8 @@ internal fun ChainNetworkItem( } } TransparentSurface( - modifier = Modifier.padding(4.dp), - shape = RoundedCornerShape(16.dp) + shape = RoundedCornerShape(16.dp), + modifier = Modifier.padding(2.dp) ) { Column( modifier = Modifier diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/change_network/ChangeNetworkRoute.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/change_network/ChangeNetworkRoute.kt index b52c31c5fb..1674ea7c66 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/change_network/ChangeNetworkRoute.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/change_network/ChangeNetworkRoute.kt @@ -1,7 +1,7 @@ package com.walletconnect.web3.modal.ui.routes.account.change_network +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.grid.GridCells @@ -72,8 +72,10 @@ private fun ChainNetworkGrid( onItemClick: (Modal.Model.Chain) -> Unit ) { LazyVerticalGrid( - contentPadding = PaddingValues(horizontal = 10.dp), - columns = GridCells.Adaptive(76.dp), + columns = GridCells.FixedSize(82.dp), + modifier = Modifier.padding(horizontal = 10.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalArrangement = Arrangement.Center, content = { itemsIndexed(chains) { _, item -> ChainNetworkItem( diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/all_wallets/AllWalletsRoute.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/all_wallets/AllWalletsRoute.kt index 77945967db..34385ea5c7 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/all_wallets/AllWalletsRoute.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/all_wallets/AllWalletsRoute.kt @@ -145,7 +145,7 @@ private fun WalletsGrid( Box { LazyVerticalGrid( state = gridState, - columns = GridCells.FixedSize(76.dp), + columns = GridCells.FixedSize(82.dp), modifier = Modifier .padding(horizontal = 10.dp) .graphicsLayer { alpha = 0.99f } @@ -157,6 +157,7 @@ private fun WalletsGrid( blendMode = BlendMode.DstIn, ) }, + verticalArrangement = Arrangement.Center, horizontalArrangement = Arrangement.SpaceBetween, ) { walletsGridItems(walletsData.wallets, onWalletItemClick) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/choose_network/ChooseNetworkRoute.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/choose_network/ChooseNetworkRoute.kt index 752230c811..6dddb5c605 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/choose_network/ChooseNetworkRoute.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/choose_network/ChooseNetworkRoute.kt @@ -1,7 +1,7 @@ package com.walletconnect.web3.modal.ui.routes.connect.choose_network +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.grid.GridCells @@ -16,7 +16,6 @@ import androidx.compose.ui.unit.dp import com.walletconnect.web3.modal.client.Modal import com.walletconnect.web3.modal.client.Web3Modal import com.walletconnect.web3.modal.ui.components.internal.commons.NetworkBottomSection -import com.walletconnect.web3.modal.ui.components.internal.commons.VerticalSpacer import com.walletconnect.web3.modal.ui.components.internal.commons.network.ChainNetworkItem import com.walletconnect.web3.modal.ui.routes.connect.ConnectState import com.walletconnect.web3.modal.utils.getChainNetworkImageUrl @@ -49,7 +48,6 @@ private fun ChainNetworkSelector( .padding(vertical = 12.dp), horizontalAlignment = Alignment.CenterHorizontally ) { - VerticalSpacer(height = 12.dp) ChainNetworkGrid( chains = chains, selectedChain = selectedChain, @@ -66,8 +64,10 @@ private fun ChainNetworkGrid( onItemClick: (Modal.Model.Chain) -> Unit ) { LazyVerticalGrid( - contentPadding = PaddingValues(horizontal = 10.dp), - columns = GridCells.Adaptive(76.dp), + columns = GridCells.FixedSize(82.dp), + modifier = Modifier.padding(horizontal = 10.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalArrangement = Arrangement.Center, content = { itemsIndexed(chains) { _, item -> ChainNetworkItem( diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/get_wallet/GetAWalletRoute.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/get_wallet/GetAWalletRoute.kt index d802d3f164..5ac4e4261d 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/get_wallet/GetAWalletRoute.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/get_wallet/GetAWalletRoute.kt @@ -14,9 +14,9 @@ import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.unit.dp import com.walletconnect.android.internal.common.modal.data.model.Wallet import com.walletconnect.modal.utils.openPlayStore +import com.walletconnect.web3.modal.ui.components.internal.commons.AllWalletsIcon import com.walletconnect.web3.modal.ui.components.internal.commons.ExternalIcon import com.walletconnect.web3.modal.ui.components.internal.commons.ListSelectRow -import com.walletconnect.web3.modal.ui.components.internal.commons.MultipleWalletIcon import com.walletconnect.web3.modal.ui.components.internal.commons.WalletImage import com.walletconnect.web3.modal.ui.previews.UiModePreview import com.walletconnect.web3.modal.ui.previews.Web3ModalPreview @@ -57,8 +57,8 @@ private fun GetAWalletContent( } item { ListSelectRow( - startIcon = { MultipleWalletIcon(wallets = wallets.take(4)) }, - text = "Explore All", + startIcon = { AllWalletsIcon() }, + text = "Explore all", contentPadding = PaddingValues(vertical = 4.dp), label = { ExternalIcon() }, onClick = { uriHandler.openUri("https://explorer.walletconnect.com/?type=wallet") } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt index aae6df6a37..0550e62b96 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/redirect/RedirectWalletScreen.kt @@ -6,6 +6,7 @@ import androidx.compose.foundation.border import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height @@ -21,7 +22,6 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -32,26 +32,25 @@ import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.walletconnect.android.internal.common.modal.data.model.Wallet -import com.walletconnect.modal.utils.openWebAppLink import com.walletconnect.modal.utils.openMobileLink import com.walletconnect.modal.utils.openPlayStore +import com.walletconnect.modal.utils.openWebAppLink import com.walletconnect.util.Empty import com.walletconnect.web3.modal.client.Modal import com.walletconnect.web3.modal.domain.delegate.Web3ModalDelegate import com.walletconnect.web3.modal.ui.components.internal.OrientationBox import com.walletconnect.web3.modal.ui.components.internal.commons.DeclinedIcon import com.walletconnect.web3.modal.ui.components.internal.commons.ExternalIcon -import com.walletconnect.web3.modal.ui.components.internal.commons.entry.CopyActionEntry import com.walletconnect.web3.modal.ui.components.internal.commons.LoadingBorder import com.walletconnect.web3.modal.ui.components.internal.commons.VerticalSpacer import com.walletconnect.web3.modal.ui.components.internal.commons.WalletImage import com.walletconnect.web3.modal.ui.components.internal.commons.button.ButtonSize import com.walletconnect.web3.modal.ui.components.internal.commons.button.ButtonStyle -import com.walletconnect.web3.modal.ui.components.internal.commons.button.ImageButton +import com.walletconnect.web3.modal.ui.components.internal.commons.button.ChipButton import com.walletconnect.web3.modal.ui.components.internal.commons.button.TryAgainButton +import com.walletconnect.web3.modal.ui.components.internal.commons.entry.CopyActionEntry import com.walletconnect.web3.modal.ui.components.internal.commons.entry.StoreEntry import com.walletconnect.web3.modal.ui.components.internal.commons.switch.PlatformTab import com.walletconnect.web3.modal.ui.components.internal.commons.switch.PlatformTabRow @@ -159,11 +158,11 @@ private fun PortraitRedirectWalletContent( PlatformTabRow(platformTab, onPlatformTabSelect) } WalletImageBox( - height = 140.dp, platformTab = platformTab, redirectState = redirectState, wallet = wallet ) + VerticalSpacer(height = 8.dp) PlatformBox( platformTab = platformTab, mobileWalletContent = { @@ -216,7 +215,6 @@ private fun LandscapeRedirectContent( } VerticalSpacer(height = 16.dp) WalletImageBox( - height = 120.dp, platformTab = platformTab, redirectState = redirectState, wallet = wallet @@ -261,13 +259,12 @@ private fun LandscapeRedirectContent( @Composable private fun WalletImageBox( - height: Dp, platformTab: PlatformTab, redirectState: RedirectState, wallet: Wallet ) { Box( - modifier = Modifier.height(height), + modifier = Modifier.height(130.dp), contentAlignment = Alignment.Center ) { when { @@ -306,17 +303,21 @@ private fun RedirectLabel(state: RedirectState, wallet: Wallet) { descriptionStyle = Web3ModalTheme.typo.small400.copy(color = Web3ModalTheme.colors.foreground.color200) } } - Text(text = header, style = headerStyle) - if (description.isNotEmpty()) { - VerticalSpacer(height = 8.dp) - Text( - text = description, - style = descriptionStyle, - modifier = Modifier.padding(horizontal = 30.dp), - textAlign = TextAlign.Center - ) + Column( + modifier = Modifier.padding(horizontal = 30.dp), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text(text = header, style = headerStyle) + if (description.isNotEmpty()) { + VerticalSpacer(height = 8.dp) + Text( + text = description, + style = descriptionStyle, + textAlign = TextAlign.Center + ) + } } - } @Composable @@ -374,11 +375,13 @@ private fun RedirectWebWalletScreen( textAlign = TextAlign.Center ) VerticalSpacer(height = 20.dp) - ImageButton( + ChipButton( text = "Open", - image = { ExternalIcon(it) }, + startIcon = {}, + endIcon = { ExternalIcon(size = 14.dp, tint = it) }, style = ButtonStyle.ACCENT, size = ButtonSize.M, + paddingValues = PaddingValues(horizontal = 12.dp), onClick = onOpenWebApp ) VerticalSpacer(height = 20.dp) @@ -409,7 +412,7 @@ private fun LoadingState( @Composable private fun WalletImageWithLoader(url: String) { LoadingBorder( - cornerRadius = 25.dp + cornerRadius = 28.dp ) { RoundedWalletImage(url = url) } From 49dd7a0e7b93457575331692d4943498733d6011 Mon Sep 17 00:00:00 2001 From: Kacper Date: Thu, 9 Nov 2023 15:50:03 +0100 Subject: [PATCH 31/44] Fix delegate changes --- .../wcmodal/client/WalletConnectModal.kt | 44 ++++++++++++++++++- .../domain/WalletConnectModalDelegate.kt | 8 +++- .../web3/modal/client/Web3Modal.kt | 44 ++++++++++++++++++- .../domain/delegate/Web3ModalDelegate.kt | 8 +++- .../web3/modal/ui/Web3ModalViewModel.kt | 10 ++++- .../components/internal/Web3ModalComponent.kt | 2 +- 6 files changed, 107 insertions(+), 9 deletions(-) diff --git a/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/client/WalletConnectModal.kt b/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/client/WalletConnectModal.kt index 5a545c3239..ea498b738a 100644 --- a/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/client/WalletConnectModal.kt +++ b/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/client/WalletConnectModal.kt @@ -64,7 +64,7 @@ object WalletConnectModal { _sessionParams = init.sessionParams runCatching { wcKoinApp.modules(walletConnectModalModule()) - setDelegate(WalletConnectModalDelegate) + setInternalDelegate(WalletConnectModalDelegate) }.onFailure { error -> return@onInitializedClient onError(Modal.Model.Error(error)) } onSuccess() } @@ -87,6 +87,48 @@ object WalletConnectModal { }.launchIn(scope) } + @Throws(IllegalStateException::class) + private fun setInternalDelegate(delegate: ModalDelegate) { + val signDelegate = object : SignClient.DappDelegate { + override fun onSessionApproved(approvedSession: Sign.Model.ApprovedSession) { + delegate.onSessionApproved(approvedSession.toModal()) + } + + override fun onSessionRejected(rejectedSession: Sign.Model.RejectedSession) { + delegate.onSessionRejected(rejectedSession.toModal()) + } + + override fun onSessionUpdate(updatedSession: Sign.Model.UpdatedSession) { + delegate.onSessionUpdate(updatedSession.toModal()) + } + + override fun onSessionEvent(sessionEvent: Sign.Model.SessionEvent) { + delegate.onSessionEvent(sessionEvent.toModal()) + } + + override fun onSessionExtend(session: Sign.Model.Session) { + delegate.onSessionExtend(session.toModal()) + } + + override fun onSessionDelete(deletedSession: Sign.Model.DeletedSession) { + delegate.onSessionDelete(deletedSession.toModal()) + } + + override fun onSessionRequestResponse(response: Sign.Model.SessionRequestResponse) { + delegate.onSessionRequestResponse(response.toModal()) + } + + override fun onConnectionStateChange(state: Sign.Model.ConnectionState) { + delegate.onConnectionStateChange(state.toModal()) + } + + override fun onError(error: Sign.Model.Error) { + delegate.onError(error.toModal()) + } + } + SignClient.setDappDelegate(signDelegate) + } + fun setSessionParams(sessionParams: Modal.Params.SessionParams) { _sessionParams = sessionParams } diff --git a/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/domain/WalletConnectModalDelegate.kt b/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/domain/WalletConnectModalDelegate.kt index f4cda80172..f3fe78b319 100644 --- a/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/domain/WalletConnectModalDelegate.kt +++ b/product/walletconnectmodal/src/main/kotlin/com/walletconnect/wcmodal/domain/WalletConnectModalDelegate.kt @@ -59,10 +59,14 @@ internal object WalletConnectModalDelegate : WalletConnectModal.ModalDelegate { } override fun onConnectionStateChange(state: Modal.Model.ConnectionState) { - + scope.launch { + _wcEventModels.emit(state) + } } override fun onError(error: Modal.Model.Error) { - Timber.e(error.throwable) + scope.launch { + _wcEventModels.emit(error) + } } } \ No newline at end of file diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt index 2d13b62fa9..8ceaa0cd99 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt @@ -85,7 +85,7 @@ object Web3Modal { this.recommendedWalletsIds = init.recommendedWalletsIds runCatching { wcKoinApp.modules(web3ModalModule()) - setDelegate(Web3ModalDelegate) + setInternalDelegate(Web3ModalDelegate) }.onFailure { error -> return@onInitializedClient onError(Modal.Model.Error(error)) } onSuccess() } @@ -120,6 +120,48 @@ object Web3Modal { }.launchIn(scope) } + @Throws(IllegalStateException::class) + private fun setInternalDelegate(delegate: ModalDelegate) { + val signDelegate = object : SignClient.DappDelegate { + override fun onSessionApproved(approvedSession: Sign.Model.ApprovedSession) { + delegate.onSessionApproved(approvedSession.toModal()) + } + + override fun onSessionRejected(rejectedSession: Sign.Model.RejectedSession) { + delegate.onSessionRejected(rejectedSession.toModal()) + } + + override fun onSessionUpdate(updatedSession: Sign.Model.UpdatedSession) { + delegate.onSessionUpdate(updatedSession.toModal()) + } + + override fun onSessionEvent(sessionEvent: Sign.Model.SessionEvent) { + delegate.onSessionEvent(sessionEvent.toModal()) + } + + override fun onSessionExtend(session: Sign.Model.Session) { + delegate.onSessionExtend(session.toModal()) + } + + override fun onSessionDelete(deletedSession: Sign.Model.DeletedSession) { + delegate.onSessionDelete(deletedSession.toModal()) + } + + override fun onSessionRequestResponse(response: Sign.Model.SessionRequestResponse) { + delegate.onSessionRequestResponse(response.toModal()) + } + + override fun onConnectionStateChange(state: Sign.Model.ConnectionState) { + delegate.onConnectionStateChange(state.toModal()) + } + + override fun onError(error: Sign.Model.Error) { + delegate.onError(error.toModal()) + } + } + SignClient.setDappDelegate(signDelegate) + } + internal fun connect( connect: Modal.Params.Connect, onSuccess: () -> Unit, diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/domain/delegate/Web3ModalDelegate.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/domain/delegate/Web3ModalDelegate.kt index c3b75d84b4..e915b7a5c3 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/domain/delegate/Web3ModalDelegate.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/domain/delegate/Web3ModalDelegate.kt @@ -58,10 +58,14 @@ internal object Web3ModalDelegate : Web3Modal.ModalDelegate { } override fun onConnectionStateChange(state: Modal.Model.ConnectionState) { - + scope.launch { + _wcEventModels.emit(state) + } } override fun onError(error: Modal.Model.Error) { - + scope.launch { + _wcEventModels.emit(error) + } } } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/Web3ModalViewModel.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/Web3ModalViewModel.kt index d0d1db0c5c..5a780efe2d 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/Web3ModalViewModel.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/Web3ModalViewModel.kt @@ -7,8 +7,11 @@ import com.walletconnect.android.internal.common.wcKoinApp import com.walletconnect.foundation.util.Logger import com.walletconnect.web3.modal.client.Modal import com.walletconnect.web3.modal.client.Web3Modal +import com.walletconnect.web3.modal.domain.usecase.GetSelectedChainUseCase import com.walletconnect.web3.modal.domain.usecase.GetSessionTopicUseCase +import com.walletconnect.web3.modal.domain.usecase.SaveChainSelectionUseCase import com.walletconnect.web3.modal.domain.usecase.SaveSessionTopicUseCase +import com.walletconnect.web3.modal.utils.getSelectedChain import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow @@ -19,7 +22,9 @@ internal class Web3ModalViewModel: ViewModel() { private val logger: Logger = wcKoinApp.koin.get() private val saveSessionTopicUseCase: SaveSessionTopicUseCase = wcKoinApp.koin.get() + private val saveChainSelectionUseCase: SaveChainSelectionUseCase = wcKoinApp.koin.get() private val getSessionTopicUseCase: GetSessionTopicUseCase = wcKoinApp.koin.get() + private val getSelectedChainUseCase: GetSelectedChainUseCase = wcKoinApp.koin.get() private val _modalState: MutableStateFlow = MutableStateFlow(Web3ModalState.Loading) @@ -51,7 +56,8 @@ internal class Web3ModalViewModel: ViewModel() { private fun createConnectModalState() { _modalState.value = Web3ModalState.Connect } - internal fun saveSessionTopic(topic: String) = viewModelScope.launch { - saveSessionTopicUseCase(topic) + internal fun saveSession(event: Modal.Model.ApprovedSession) = viewModelScope.launch { + saveSessionTopicUseCase(event.topic) + saveChainSelectionUseCase(Web3Modal.chains.getSelectedChain(getSelectedChainUseCase()).id) } } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt index 558984001f..2136128542 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt @@ -44,7 +44,7 @@ fun Web3ModalComponent( .wcEventModels .filterIsInstance() .onEach { event -> - web3ModalViewModel.saveSessionTopic(event.topic) + web3ModalViewModel.saveSession(event) closeModal() } .collect() From c34dad2cd6d9c117db1f448d74897b35ce5430f0 Mon Sep 17 00:00:00 2001 From: szymon Date: Mon, 13 Nov 2023 14:41:39 +0100 Subject: [PATCH 32/44] feat: Add mixpanel to FCM events --- .../wallet/WalletFirebaseMessagingService.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/WalletFirebaseMessagingService.kt b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/WalletFirebaseMessagingService.kt index 1cab2c3348..e77a23a9b5 100644 --- a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/WalletFirebaseMessagingService.kt +++ b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/WalletFirebaseMessagingService.kt @@ -1,36 +1,39 @@ package com.walletconnect.sample.wallet import android.annotation.SuppressLint -import android.util.Log import com.google.firebase.messaging.RemoteMessage +import com.walletconnect.android.internal.common.di.AndroidCommonDITags +import com.walletconnect.android.internal.common.wcKoinApp +import com.walletconnect.foundation.util.Logger import com.walletconnect.notify.client.Notify import com.walletconnect.notify.client.NotifyMessageService import com.walletconnect.sample.wallet.domain.NotificationHandler import kotlinx.coroutines.runBlocking +import org.koin.core.qualifier.named @SuppressLint("MissingFirebaseInstanceTokenRefresh") class WalletFirebaseMessagingService : NotifyMessageService() { - private val TAG = this::class.simpleName + private val logger: Logger by lazy { wcKoinApp.koin.get(named(AndroidCommonDITags.LOGGER)) } override fun newToken(token: String) { - Log.d(TAG, "Registering New Token Success:\t$token") + logger.log("Registering New Token Success:\t$token") } override fun registeringFailed(token: String, throwable: Throwable) { - Log.d(TAG, "Registering New Token Failed:\t$token") + logger.log("Registering New Token Failed:\t$token") } override fun onMessage(message: Notify.Model.Message, originalMessage: RemoteMessage) { - Log.d(TAG, "Message:\t$message") + logger.log("Message:\t$message") runBlocking { NotificationHandler.addNotification(message) } } override fun onDefaultBehavior(message: RemoteMessage) { - Log.d(TAG, "onDefaultBehavior: ${message.to}") + logger.log("onDefaultBehavior: ${message.to}") } override fun onError(throwable: Throwable, defaultMessage: RemoteMessage) { - Log.e(TAG, "onError Message To: ${defaultMessage.to}", throwable) + logger.error("onError Message To: ${defaultMessage.to}, throwable: $throwable") } } \ No newline at end of file From 8cccb1b9e2b29b7c4dbb04bc6e820fe75857096d Mon Sep 17 00:00:00 2001 From: Kacper Date: Mon, 13 Nov 2023 17:59:49 +0100 Subject: [PATCH 33/44] Small fixes and adjustments --- .../web3/modal/ui/Web3ModalSheet.kt | 19 +++++++++++++------ .../chain_redirect/ChainSwitchRedirect.kt | 9 ++++++--- .../modal/ui/routes/connect/ConnectState.kt | 2 +- .../ui/routes/connect/WalletDataSource.kt | 3 +++ .../web3modal/src/main/res/values/theme.xml | 12 ++++++++++++ 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/Web3ModalSheet.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/Web3ModalSheet.kt index 3376c4319b..3785f85e84 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/Web3ModalSheet.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/Web3ModalSheet.kt @@ -7,10 +7,13 @@ import android.view.View import android.view.ViewGroup import androidx.activity.ComponentDialog import androidx.activity.OnBackPressedCallback +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.Surface import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy +import androidx.compose.ui.unit.dp import androidx.core.content.res.use import androidx.core.content.res.getColorOrThrow import androidx.navigation.NavHostController @@ -24,7 +27,7 @@ import com.walletconnect.web3.modal.ui.theme.ColorPalette class Web3ModalSheet : BottomSheetDialogFragment() { override fun onCreate(savedInstanceState: Bundle?) { - requireContext().setTheme(R.style.Web3ModalTheme) + requireContext().setTheme(R.style.Web3ModalTheme_DialogTheme) super.onCreate(savedInstanceState) } @@ -61,11 +64,15 @@ class Web3ModalSheet : BottomSheetDialogFragment() { this@Web3ModalSheet, onBackPressedCallback(navController) ) - Web3ModalComponent( - navController = navController, - shouldOpenChooseNetwork = shouldOpenChooseNetwork, - closeModal = { this@Web3ModalSheet.dismiss() } - ) + Surface( + shape = RoundedCornerShape(topStart = 36.dp, topEnd = 36.dp) + ) { + Web3ModalComponent( + navController = navController, + shouldOpenChooseNetwork = shouldOpenChooseNetwork, + closeModal = { this@Web3ModalSheet.dismiss() } + ) + } } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/chain_redirect/ChainSwitchRedirect.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/chain_redirect/ChainSwitchRedirect.kt index 0a3a6cfa3d..f3ca32cf1a 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/chain_redirect/ChainSwitchRedirect.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/chain_redirect/ChainSwitchRedirect.kt @@ -47,17 +47,20 @@ internal fun ChainSwitchRedirectRoute( val onError: (String?) -> Unit = { accountState.showError(it ?: "Something went wrong") } + var chainSwitchState by remember { mutableStateOf(ChainRedirectState.Loading) } val switchChain = suspend { accountState.switchChain( to = chain, - openConnectedWallet = { uri -> uriHandler.openUri(uri) { onError(it.message) } }, + openConnectedWallet = { uri -> + uriHandler.openUri(uri) { + chainSwitchState = ChainRedirectState.Declined + } + }, onError = onError ) } - var chainSwitchState by remember { mutableStateOf(ChainRedirectState.Loading) } - LaunchedEffect(Unit) { switchChain() } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectState.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectState.kt index aaec4c5063..32a30b87de 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectState.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectState.kt @@ -143,7 +143,7 @@ internal class ConnectState( fun getWallet(walletId: String?) = walletsDataStore.getWallet(walletId) - fun getNotInstalledWallets() = walletsState.value.wallets.filterNot { it.isWalletInstalled } + fun getNotInstalledWallets() = walletsDataStore.wallets.filterNot { it.isWalletInstalled } fun getWalletsTotalCount() = walletsDataStore.totalWalletsCount diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/WalletDataSource.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/WalletDataSource.kt index aa2b903d79..0963e5c1d6 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/WalletDataSource.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/WalletDataSource.kt @@ -41,6 +41,9 @@ internal class WalletDataSource( val totalWalletsCount: Int get() = walletsListingData.totalCount + installedWalletsIds.size + val wallets: List + get() = walletsListingData.wallets + private fun getPriorityWallets() = (getRecentWalletUseCase()?.let { listOf(it) } ?: listOf()) + installedWalletsIds + Web3Modal.recommendedWalletsIds private val searchState: MutableStateFlow = MutableStateFlow(WalletsData.empty()) val walletState: MutableStateFlow = MutableStateFlow(WalletsData.empty()) diff --git a/product/web3modal/src/main/res/values/theme.xml b/product/web3modal/src/main/res/values/theme.xml index fd3a08286f..a6e370eea6 100644 --- a/product/web3modal/src/main/res/values/theme.xml +++ b/product/web3modal/src/main/res/values/theme.xml @@ -4,4 +4,16 @@ + + + + + + \ No newline at end of file From 7347642e8c974288fccbb7f14154ea0a95ddbd2a Mon Sep 17 00:00:00 2001 From: Kacper Date: Mon, 13 Nov 2023 18:01:36 +0100 Subject: [PATCH 34/44] rename themes --- product/web3modal/src/main/res/values/theme.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/product/web3modal/src/main/res/values/theme.xml b/product/web3modal/src/main/res/values/theme.xml index a6e370eea6..9f37071d09 100644 --- a/product/web3modal/src/main/res/values/theme.xml +++ b/product/web3modal/src/main/res/values/theme.xml @@ -6,14 +6,14 @@ - - \ No newline at end of file From 666029c4a2f03980ad93baee6b47238d9fc9228f Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 13 Nov 2023 23:01:22 -0600 Subject: [PATCH 35/44] update sessionRequestEventsQueue to be a ConcurrentLinkedQueue instead of just a LinkedList --- .../com/walletconnect/sign/engine/SessionRequestQueue.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/SessionRequestQueue.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/SessionRequestQueue.kt index 56a0d971fe..2743823eac 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/SessionRequestQueue.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/SessionRequestQueue.kt @@ -1,6 +1,6 @@ package com.walletconnect.sign.engine import com.walletconnect.sign.engine.model.EngineDO -import java.util.LinkedList +import java.util.concurrent.ConcurrentLinkedQueue -internal val sessionRequestEventsQueue: LinkedList = LinkedList() \ No newline at end of file +internal val sessionRequestEventsQueue = ConcurrentLinkedQueue() \ No newline at end of file From b98818b0a59666f9a23dccba5710a7e9d14ce4bf Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 13 Nov 2023 23:02:17 -0600 Subject: [PATCH 36/44] updated the OnSessionRequestUseCase to use the ConcurrentLinkedQueue api --- .../sign/engine/use_case/requests/OnSessionRequestUseCase.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/requests/OnSessionRequestUseCase.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/requests/OnSessionRequestUseCase.kt index 9722b4338f..bc04277be9 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/requests/OnSessionRequestUseCase.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/use_case/requests/OnSessionRequestUseCase.kt @@ -85,7 +85,7 @@ internal class OnSessionRequestUseCase( sessionRequestEventsQueue.find { event -> CoreValidator.isExpiryWithinBounds(event.request.expiry) } ?: sessionRequestEvent } - sessionRequestEventsQueue.addLast(sessionRequestEvent) + sessionRequestEventsQueue.add(sessionRequestEvent) scope.launch { _events.emit(event) } } } catch (e: Exception) { From 493814d6a9f67a4241940b2de30b631d53293e7d Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 13 Nov 2023 23:02:30 -0600 Subject: [PATCH 37/44] updated the SignEngine to use the ConcurrentLinkedQueue api --- .../kotlin/com/walletconnect/sign/engine/domain/SignEngine.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/domain/SignEngine.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/domain/SignEngine.kt index b17bdc5b1b..5bf9ec0bbd 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/domain/SignEngine.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/engine/domain/SignEngine.kt @@ -282,7 +282,7 @@ internal class SignEngine( val verifyContext = verifyContextStorageRepository.get(sessionRequest.request.id) ?: VerifyContext(sessionRequest.request.id, String.Empty, Validation.UNKNOWN, String.Empty, null) val sessionRequestEvent = EngineDO.SessionRequestEvent(sessionRequest, verifyContext.toEngineDO()) - sessionRequestEventsQueue.addLast(sessionRequestEvent) + sessionRequestEventsQueue.add(sessionRequestEvent) } } } From c85aa53abcacb98755ac8906571e42cb7dd28a60 Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Mon, 13 Nov 2023 23:03:17 -0600 Subject: [PATCH 38/44] Created a test to show the difference between a non-thread safe LinkedList vs a thread safe ConcurrentLinkedQueue --- .../sign/engine/SessionRequestQueueTest.kt | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 protocol/sign/src/test/kotlin/com/walletconnect/sign/engine/SessionRequestQueueTest.kt diff --git a/protocol/sign/src/test/kotlin/com/walletconnect/sign/engine/SessionRequestQueueTest.kt b/protocol/sign/src/test/kotlin/com/walletconnect/sign/engine/SessionRequestQueueTest.kt new file mode 100644 index 0000000000..e2530f4e9a --- /dev/null +++ b/protocol/sign/src/test/kotlin/com/walletconnect/sign/engine/SessionRequestQueueTest.kt @@ -0,0 +1,78 @@ +package com.walletconnect.sign.engine + +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlinx.coroutines.test.runTest +import org.junit.Assert.assertFalse +import org.junit.Assert.assertThrows +import org.junit.Test +import java.util.LinkedList +import java.util.concurrent.ConcurrentLinkedQueue + +class SessionRequestQueueTest { + + @Test + fun testLinkedListAccessFromMultipleCoroutines() { + assertThrows(ConcurrentModificationException::class.java) { + runTest { + val linkedList = LinkedList() + + // Add initial elements to the list + repeat(100) { linkedList.add(it) } + + // Launch coroutines for concurrent modification and iteration + launch { + repeat(100) { + linkedList.add(it) + delay(10) // Adding a small delay + } + } + + launch { + linkedList.forEach { + println(it) + delay(5) // Adding a small delay + } + } + + // Wait for coroutines to finish + delay(1000) + } + } + } + + @Test + fun testConcurrentAccess() = runTest { + val concurrentQueue = ConcurrentLinkedQueue() + + // Add initial elements to the queue + repeat(100) { concurrentQueue.add(it) } + + var exceptionThrown = false + + try { + // Launch coroutines for concurrent modification and iteration + launch { + repeat(100) { + concurrentQueue.add(it) + delay(10) // Adding a small delay + } + } + + launch { + concurrentQueue.forEach { + println(it) // mimics some processing + delay(5) // Adding a small delay + } + } + + // Wait for coroutines to finish + delay(1000) + } catch (e: ConcurrentModificationException) { + exceptionThrown = true + } + + // Check if no exception was thrown + assertFalse("ConcurrentModificationException was thrown unexpectedly", exceptionThrown) + } +} \ No newline at end of file From eb55b85633757b58984e65a4dfa003d984146b06 Mon Sep 17 00:00:00 2001 From: Kacper Date: Wed, 15 Nov 2023 17:18:54 +0100 Subject: [PATCH 39/44] Disconnect improvements and fixes --- .../com/walletconnect/web3/modal/client/Web3Modal.kt | 4 ++-- .../ui/components/internal/Web3ModalComponent.kt | 11 ++++++++--- .../ui/components/internal/snackbar/ModalSnackBar.kt | 4 ++++ .../components/internal/snackbar/ModalSnackbarHost.kt | 1 + .../web3/modal/ui/routes/account/AccountState.kt | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt index 8ceaa0cd99..8a7fff87ef 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt @@ -144,6 +144,7 @@ object Web3Modal { } override fun onSessionDelete(deletedSession: Sign.Model.DeletedSession) { + scope.launch { deleteSessionDataUseCase() } delegate.onSessionDelete(deletedSession.toModal()) } @@ -210,11 +211,10 @@ object Web3Modal { onError(InvalidSessionException.toModalError()) return } - + scope.launch { deleteSessionDataUseCase() } SignClient.disconnect( Sign.Params.Disconnect(sessionTopic), { - scope.launch { deleteSessionDataUseCase() } onSuccess(it.toModal()) }, { onError(it.toModal()) } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt index 2136128542..47da117742 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt @@ -42,10 +42,15 @@ fun Web3ModalComponent( LaunchedEffect(Unit) { Web3ModalDelegate .wcEventModels - .filterIsInstance() .onEach { event -> - web3ModalViewModel.saveSession(event) - closeModal() + when(event) { + is Modal.Model.ApprovedSession -> { + web3ModalViewModel.saveSession(event) + closeModal() + } + is Modal.Model.DeletedSession.Success -> { closeModal() } + else -> Unit + } } .collect() } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackBar.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackBar.kt index ce00b5f248..ef62b91da0 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackBar.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackBar.kt @@ -34,6 +34,10 @@ internal fun ModalSnackBar( Row( modifier = Modifier .height(40.dp) + .background( + color = Web3ModalTheme.colors.background.color125, + shape = shape + ) .background( color = Web3ModalTheme.colors.grayGlass05, shape = shape diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackbarHost.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackbarHost.kt index 0ef7024636..297017f32d 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackbarHost.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackbarHost.kt @@ -39,6 +39,7 @@ internal fun ModalSnackBarHost( visible = isVisibleSnackBar, modifier = Modifier .padding(top = 10.dp) + .padding(horizontal = 60.dp) .align(Alignment.TopCenter), enter = fadeIn() + scaleIn(), exit = fadeOut() + scaleOut() diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/AccountState.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/AccountState.kt index 61e9f7f16c..b924154de5 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/AccountState.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/AccountState.kt @@ -113,12 +113,12 @@ internal class AccountState( fun disconnect() { Web3Modal.disconnect( onSuccess = { - coroutineScope.launch { deleteSessionDataUseCase() } coroutineScope.launch(Dispatchers.Main) { closeModal() } }, onError = { showError(it.throwable.localizedMessage) logger.error(it.throwable) + coroutineScope.launch(Dispatchers.Main) { closeModal() } } ) } From 2eedb5a0551a1e656e838990afec4362ecf1cde1 Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Wed, 15 Nov 2023 17:07:59 -0600 Subject: [PATCH 40/44] bumped versions --- buildSrc/src/main/kotlin/Versions.kt | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 0059c6e942..cdcfd59074 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -5,17 +5,17 @@ const val KEY_PUBLISH_ARTIFACT_ID = "PUBLISH_ARTIFACT_ID" const val KEY_SDK_NAME = "SDK_NAME" //Latest versions -const val BOM_VERSION = "1.19.1" +const val BOM_VERSION = "1.20.0" const val FOUNDATION_VERSION = "1.12.0" -const val CORE_VERSION = "1.24.0" -const val SIGN_VERSION = "2.22.0" -const val AUTH_VERSION = "1.22.0" -const val CHAT_VERSION = "1.0.0-beta21" -const val NOTIFY_VERSION = "1.0.0-beta02" -const val WEB_3_WALLET = "1.17.0" -const val WEB_3_MODAL = "1.0.0-beta02" -const val WC_MODAL_VERSION = "1.0.0-beta01" -const val MODAL_CORE_VERSION = "1.0.0-beta01" +const val CORE_VERSION = "1.25.0" +const val SIGN_VERSION = "2.23.0" +const val AUTH_VERSION = "1.23.0" +const val CHAT_VERSION = "1.0.0-beta22" +const val NOTIFY_VERSION = "1.0.0-beta03" +const val WEB_3_WALLET = "1.18.0" +const val WEB_3_MODAL = "1.0.0" +const val WC_MODAL_VERSION = "1.0.0-beta02" +const val MODAL_CORE_VERSION = "1.0.0-beta02" val jvmVersion = JavaVersion.VERSION_11 const val MIN_SDK: Int = 23 From bfd4091fdc4bb8737dfe2994a596de43665d9def Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Wed, 15 Nov 2023 17:08:01 -0600 Subject: [PATCH 41/44] bumped versions --- ReadMe.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ReadMe.md b/ReadMe.md index b92455b955..e2e78720c2 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -10,6 +10,7 @@ WalletConnect v2 protocols for Android applications. | BOM | [Core SDK](core/android) | [Sign SDK](protocol/sign) | [Auth SDK](protocol/auth) | [Chat SDK](protocol/chat) | [Notify SDK](protocol/notify) | [web3wallet](product/web3wallet) | [web3modal](product/web3modal) | [WalletConnectModal](product/walletconnectmodal) | |-----------------------------------------------------------------------------------------|--------------------------|---------------------------|---------------------------|---------------------------|:------------------------------|----------------------------------|--------------------------------|--------------------------------------------------| +| 1.20.0 | 1.25.0 | 2.23.0 | 1.23.0 | 1.0.0.beta22 | 1.0.0-beta03 | 1.18.0 | 1.0.0 | 1.0.0-beta02 | | 1.19.1 | 1.24.0 | 2.22.0 | 1.22.0 | 1.0.0.beta21 | 1.0.0-beta02 | 1.17.0 | 1.0.0-beta02 | 1.0.0-beta01 | | 1.19.0 | 1.24.0 | 2.22.0 | 1.22.0 | 1.0.0.beta21 | 1.0.0-beta02 | 1.17.0 | 1.0.0-beta01 | 1.0.0-beta01 | | 1.18.0 | 1.23.0 | 2.21.0 | 1.21.0 | 1.0.0.beta20 | 1.0.0-beta01 | 1.16.0 | 1.0.0-alpha11 | 1.0.0-alpha07 | From 1f7fa5143f37201c077d7fcefe8f5da2ee8f8761 Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Wed, 15 Nov 2023 18:38:22 -0600 Subject: [PATCH 42/44] set jvm toolchain --- buildSrc/build.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index df871e432d..a982b1b448 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -9,6 +9,8 @@ repositories { gradlePluginPortal() } +kotlin.jvmToolchain(11) + dependencies { implementation("com.android.tools.build:gradle:8.0.2") // when changing, remember to change version in Versions.kt in buildSrc module implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21") // when changing, remember to change version in Versions.kt in buildSrc module From dd78afc3faeb596ddccce22b5ca9c1a263dd6be7 Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Wed, 15 Nov 2023 18:41:40 -0600 Subject: [PATCH 43/44] use JavaVersion instead of hardcoded value --- buildSrc/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index a982b1b448..7fbc44ad4d 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -9,7 +9,7 @@ repositories { gradlePluginPortal() } -kotlin.jvmToolchain(11) +kotlin.jvmToolchain(JavaVersion.VERSION_11.majorVersion.toInt()) dependencies { implementation("com.android.tools.build:gradle:8.0.2") // when changing, remember to change version in Versions.kt in buildSrc module From 40f59afbca7e86160b6740d2a0a73a3afe0193a0 Mon Sep 17 00:00:00 2001 From: Talha Ali <> Date: Thu, 16 Nov 2023 09:20:08 -0600 Subject: [PATCH 44/44] commented out jvmToolchain as it is causing integration tests to fail --- buildSrc/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 7fbc44ad4d..3b36ca6ea6 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -9,7 +9,7 @@ repositories { gradlePluginPortal() } -kotlin.jvmToolchain(JavaVersion.VERSION_11.majorVersion.toInt()) +//kotlin.jvmToolchain(JavaVersion.VERSION_11.majorVersion.toInt()) dependencies { implementation("com.android.tools.build:gradle:8.0.2") // when changing, remember to change version in Versions.kt in buildSrc module