@instadapp/avocado-base 0.0.0-dev.a1a59bd → 0.0.0-dev.a43ff53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/app.vue +7 -0
  2. package/assets/images/icons/change-threshold.svg +4 -0
  3. package/assets/images/icons/cross-transfer.svg +7 -0
  4. package/assets/images/icons/dapp.svg +4 -0
  5. package/assets/images/icons/deploy.svg +12 -0
  6. package/assets/images/icons/gas.svg +12 -5
  7. package/assets/images/icons/instadapp-pro.svg +4 -0
  8. package/assets/images/icons/multi-send.svg +7 -0
  9. package/assets/images/icons/permit-sign.svg +11 -0
  10. package/assets/images/icons/plus-circle.svg +6 -0
  11. package/assets/images/icons/refresh.svg +4 -4
  12. package/assets/images/icons/reject-proposal.svg +6 -0
  13. package/assets/images/icons/transfer.svg +5 -0
  14. package/assets/images/icons/trash-2.svg +8 -0
  15. package/assets/images/icons/upgrade.svg +4 -0
  16. package/components/ActionLogo.vue +38 -0
  17. package/components/ActionMetadata.vue +23 -4
  18. package/components/AuthorityAvatar.vue +26 -0
  19. package/components/ChainLogo.vue +98 -441
  20. package/components/CopyClipboard.vue +64 -0
  21. package/components/metadata/Bridge.vue +25 -5
  22. package/components/metadata/CrossTransfer.vue +5 -1
  23. package/components/metadata/GasTopup.vue +7 -1
  24. package/components/metadata/Permit2.vue +6 -1
  25. package/components/metadata/Signers.vue +45 -0
  26. package/components/metadata/Swap.vue +9 -2
  27. package/components/metadata/Transfer.vue +6 -2
  28. package/package.json +5 -3
  29. package/utils/formatter.ts +1 -1
  30. package/utils/helper.ts +19 -0
  31. package/utils/metadata.ts +183 -127
  32. package/utils/network.ts +36 -1
  33. package/utils/services.ts +8 -1
  34. package/utils/utils.d.ts +128 -127
@@ -0,0 +1,64 @@
1
+ <script setup lang="ts">
2
+ import CopySVG from '~/assets/images/icons/copy.svg'
3
+ import CheckCircle from '~/assets/images/icons/check-circle.svg'
4
+
5
+ defineProps<{
6
+ text: string
7
+ iconOnly?: boolean
8
+ successText?: string
9
+ }>()
10
+ const { copy, copied } = useClipboard()
11
+ const slots = useSlots()
12
+ </script>
13
+
14
+ <template>
15
+ <button
16
+ class="text-slate-400 font-semibold inline-flex items-center gap-2.5"
17
+ @click.stop="copy(text)"
18
+ >
19
+ <Transition mode="out-in" name="slide-left">
20
+ <span v-if="copied && !iconOnly"> {{ successText || 'Copied' }} </span>
21
+ <span v-else-if="slots.content">
22
+ <slot name="content" />
23
+ </span>
24
+ </Transition>
25
+
26
+ <Transition mode="out-in" name="slide">
27
+ <CheckCircle
28
+ v-if="copied"
29
+ class="w-4 h-4 shrink-0 dark:text-slate-900 text-white svg-circle"
30
+ />
31
+ <slot v-else-if="slots.copy" name="copy" />
32
+ <slot v-else name="copy-icon">
33
+ <CopySVG />
34
+ </slot>
35
+ </Transition>
36
+ </button>
37
+ </template>
38
+
39
+ <style scoped>
40
+ .slide-left-enter-active,
41
+ .slide-left-leave-active {
42
+ transition: all 0.1s ease-out;
43
+ }
44
+
45
+ .slide-left-enter-from {
46
+ opacity: 0;
47
+ transform: translateX(30px);
48
+ }
49
+
50
+ .slide-left-leave-to {
51
+ opacity: 0;
52
+ transform: translateX(-30px);
53
+ }
54
+
55
+ .slide-enter-active,
56
+ .slide-leave-active {
57
+ transition: opacity 0.1s ease;
58
+ }
59
+
60
+ .slide-enter-from,
61
+ .slide-leave-to {
62
+ opacity: 0;
63
+ }
64
+ </style>
@@ -6,11 +6,26 @@ const props = defineProps<{
6
6
  }>();
7
7
 
8
8
  const compact = inject('compact');
9
+ const tokens = inject<ITokenPrice[]>('tokens');
9
10
 
10
11
  const toToken = asyncComputed(() =>
11
- fetchTokenByAddress(props.metadata?.toToken, props.metadata?.toChainId)
12
+ {
13
+ if (Array.isArray(tokens) && !tokens.length) return null;
14
+ return fetchTokenByAddress(props.metadata?.toToken, props.metadata?.toChainId, tokens)
15
+ }
12
16
  );
13
17
 
18
+ const fromToken = asyncComputed(() =>
19
+ {
20
+ if (Array.isArray(tokens) && !tokens.length) return null;
21
+ return fetchTokenByAddress(props.metadata?.fromToken, props.chain_id, tokens)
22
+ }
23
+ );
24
+
25
+ const isTokensSame = computed(() => {
26
+ return toToken.value?.symbol === fromToken.value?.symbol
27
+ })
28
+
14
29
  const bridgeAmountFormatted = computed(() =>
15
30
  formatDecimal(
16
31
  fromWei(props.metadata?.amount, toToken?.value?.decimals).toFixed()
@@ -19,18 +34,23 @@ const bridgeAmountFormatted = computed(() =>
19
34
  </script>
20
35
 
21
36
  <template>
22
- <div v-if="!toToken" class="rounded-5 w-24 h-4 loading-box" />
37
+ <div v-if="!toToken || !fromToken" class="rounded-5 w-24 h-4 loading-box" />
23
38
  <div
24
39
  class="flex gap-5 items-center"
25
- v-if="metadata.type === 'bridge' && toToken"
40
+ v-if="toToken && fromToken"
26
41
  >
27
42
  <span v-if="!compact" class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
28
43
  <span class="inline-flex gap-2.5 items-center">
29
- <img width="20" height="20" class="w-5 h-5" :src="toToken.logo_url" />
44
+ <img width="20" height="20" class="w-5 h-5" :src="fromToken.logo_url" />
30
45
  {{ bridgeAmountFormatted }}
31
- <span class="uppercase">{{ toToken?.symbol }}</span>
46
+ <span class="uppercase">{{ fromToken?.symbol }}</span>
32
47
  <SvgoBridge class="text-slate-400 w-4 h-4" />
48
+ <template v-if="!isTokensSame">
49
+ <img width="20" height="20" class="w-5 h-5" :src="toToken.logo_url" />
50
+ <span class="uppercase">{{ toToken?.symbol }}</span>
51
+ </template>
33
52
  <span class="flex items-center gap-2.5">
53
+ on
34
54
  <ChainLogo class="w-5" :chain="metadata.toChainId" />
35
55
  <span>{{ chainIdToName(metadata.toChainId) }}</span>
36
56
  </span>
@@ -6,13 +6,17 @@ const props = defineProps<{
6
6
  }>();
7
7
 
8
8
  const compact = inject('compact');
9
+ const tokens = inject<ITokenPrice[]>('tokens');
9
10
 
10
11
  const fromToken = asyncComputed(() => {
11
12
  if (!props?.chain_id) return null;
12
13
 
14
+ if (Array.isArray(tokens) && !tokens.length) return null;
15
+
13
16
  return fetchTokenByAddress(
14
17
  props.metadata?.fromToken,
15
- props?.chain_id
18
+ props?.chain_id,
19
+ tokens
16
20
  );
17
21
  });
18
22
 
@@ -5,8 +5,14 @@ const props = defineProps<{
5
5
  chain_id: number | string
6
6
  }>();
7
7
 
8
+ const tokens = inject<ITokenPrice[]>('tokens');
9
+
8
10
  const token = asyncComputed(() =>
9
- fetchTokenByAddress(props.metadata?.token, props?.chain_id)
11
+ {
12
+ if (Array.isArray(tokens) && !tokens.length) return null;
13
+
14
+ return fetchTokenByAddress(props.metadata?.token, props?.chain_id, tokens)
15
+ }
10
16
  );
11
17
 
12
18
  const compact = inject('compact');
@@ -5,8 +5,13 @@ const props = defineProps<{
5
5
  chain_id: number | string
6
6
  }>();
7
7
 
8
+ const tokens = inject<ITokenPrice[]>('tokens');
9
+
8
10
  const token = asyncComputed(() =>
9
- fetchTokenByAddress(props.metadata?.token, props?.chain_id)
11
+ {
12
+ if (Array.isArray(tokens) && !tokens.length) return null;
13
+ return fetchTokenByAddress(props.metadata?.token, props?.chain_id, tokens)
14
+ }
10
15
  );
11
16
 
12
17
  const calculateDate = (timestamp: number) => {
@@ -0,0 +1,45 @@
1
+ <script setup lang="ts">
2
+ import { Tippy } from 'vue-tippy'
3
+ const props = defineProps<{
4
+ metadata: {
5
+ type: MetadataTypes,
6
+ [key: string]: any
7
+ };
8
+ compact?: boolean;
9
+ }>();
10
+ </script>
11
+
12
+ <template>
13
+ <div>
14
+ <div v-if="!compact || metadata.addresses.length < 3" class="flex gap-[14px] flex-wrap">
15
+ <div v-for="address of metadata.addresses" :key="address" class="flex gap-[8px] rounded-full bg-slate-50 dark:bg-gray-850 justify-start items-center px-[8px] py-[6px]">
16
+ <AuthorityAvatar :address="address" class="w-[18px] h-[18px]" />
17
+ <p class="text-xs leading-5">
18
+ {{ shortenHash(address, compact ? 2 : 4) }}
19
+ </p>
20
+ </div>
21
+ </div>
22
+ <div v-else class="flex gap-2 flex-wrap items-center">
23
+ <div v-for="address of [metadata.addresses[0], metadata.addresses[1]]" :key="address" class="flex gap-[8px] rounded-full bg-slate-50 dark:bg-gray-850 justify-start items-center px-[8px] py-[6px]">
24
+ <AuthorityAvatar :address="address" class="w-[18px] h-[18px]" />
25
+ <p class="text-xs leading-5">
26
+ {{ shortenHash(address, 2) }}
27
+ </p>
28
+ </div>
29
+ ...
30
+ <Tippy max-width="none" interactive tag="button" content-tag="div" content-class="content-wrapper">
31
+ <template #default>
32
+ <SvgoInfo2 class="w-[16px] h-[16px] text-slate-500 rounded-full" />
33
+ </template>
34
+ <template #content>
35
+ <ul class="flex flex-col gap-2.5">
36
+ <li v-for="address in metadata.addresses" :key="address" class="flex text-xs items-center gap-2.5">
37
+ <AuthorityAvatar class="shrink-0 w-5 h-5" :address="address" />
38
+ {{ address }}
39
+ </li>
40
+ </ul>
41
+ </template>
42
+ </Tippy>
43
+ </div>
44
+ </div>
45
+ </template>
@@ -6,12 +6,19 @@ const props = defineProps<{
6
6
  }>();
7
7
 
8
8
  const compact = inject('compact');
9
+ const tokens = inject<ITokenPrice[]>('tokens');
9
10
 
10
11
  const buyToken = asyncComputed(() =>
11
- fetchTokenByAddress(props.metadata?.buyToken, props?.chain_id)
12
+ {
13
+ if (Array.isArray(tokens) && !tokens.length) return null;
14
+ return fetchTokenByAddress(props.metadata?.buyToken, props?.chain_id, tokens)
15
+ }
12
16
  );
13
17
  const sellToken = asyncComputed(() =>
14
- fetchTokenByAddress(props.metadata?.sellToken, props?.chain_id)
18
+ {
19
+ if (Array.isArray(tokens) && !tokens.length) return null;
20
+ return fetchTokenByAddress(props.metadata?.sellToken, props?.chain_id, tokens)
21
+ }
15
22
  );
16
23
 
17
24
  const sellAmountFormatted = computed(() =>
@@ -6,13 +6,17 @@ const props = defineProps<{
6
6
  }>();
7
7
 
8
8
  const compact = inject('compact');
9
+ const tokens = inject<ITokenPrice[]>('tokens');
9
10
 
10
11
  const token = asyncComputed(() => {
11
12
  if (!props?.chain_id) return null;
12
13
 
14
+ if (Array.isArray(tokens) && !tokens.length) return null;
15
+
13
16
  return fetchTokenByAddress(
14
17
  props.metadata?.token,
15
- props?.chain_id
18
+ props?.chain_id,
19
+ tokens
16
20
  );
17
21
  });
18
22
 
@@ -28,9 +32,9 @@ const formattedAmount = computed(() =>
28
32
  <div class="flex items-center gap-5" v-else>
29
33
  <span v-if="!compact" class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
30
34
  <span class="inline-flex gap-2.5 items-center">
31
- <img width="20" height="20" class="w-5 h-5" :src="token?.logo_url" />
32
35
  {{ formattedAmount }}
33
36
  <span class="uppercase">{{ token?.symbol }}</span>
37
+ <img width="20" height="20" class="w-5 h-5" :src="token?.logo_url" />
34
38
  <SvgoArrowRight class="w-4 h-4 text-slate-400 mx-2" />
35
39
  <NuxtLink
36
40
  class="text-primary"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/avocado-base",
3
- "version": "0.0.0-dev.a1a59bd",
3
+ "version": "0.0.0-dev.a43ff53",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "global.d.ts",
@@ -20,11 +20,13 @@
20
20
  "nuxt-svgo": "^3.1.0",
21
21
  "rimraf": "^3.0.2",
22
22
  "typechain": "^8.1.1",
23
- "unplugin-vue-components": "^0.25.1"
23
+ "unplugin-vue-components": "^0.25.1",
24
+ "vue-tippy": "^6.0.0"
24
25
  },
25
26
  "dependencies": {
26
27
  "@vueuse/nuxt": "^10.2.0",
27
28
  "bignumber.js": "^9.1.1",
28
- "ethers": "^5.7.2"
29
+ "ethers": "^5.7.2",
30
+ "spark-md5": "^3.0.2"
29
31
  }
30
32
  }
@@ -72,7 +72,7 @@ export function formatDecimal(value: string | number, fractionDigits?: number) {
72
72
  let decimals;
73
73
 
74
74
  if (num.lt(1)) {
75
- decimals = 8;
75
+ decimals = 4;
76
76
  } else if (num.lt(10)) {
77
77
  decimals = 6;
78
78
  } else if (num.lt(100)) {
package/utils/helper.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import SparkMD5 from 'spark-md5';
2
+
1
3
  export const indexSorter = (aIndex: number, bIndex: number) => {
2
4
  if (aIndex === -1 && bIndex === -1) {
3
5
  return 0; // fallback to other sorting criteria
@@ -52,3 +54,20 @@ export function onImageError(this: HTMLImageElement) {
52
54
  parentElement.classList.add("bg-gray-300");
53
55
  }
54
56
  }
57
+
58
+ export function formatMultipleAddresses(addresses: string[], shorten = true) {
59
+ const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' })
60
+ const formattedString = formatter.format(addresses.map(i => shorten ? shortenHash(i) || '' : i))
61
+
62
+ return formattedString
63
+ }
64
+
65
+ export function generateColor(address: string) {
66
+ const hash = parseInt(SparkMD5.hash(address), 16);
67
+
68
+ const hue = hash % 360;
69
+ const saturation = 80 + (hash % 30);
70
+ const lightness = 70 + (hash % 20);
71
+
72
+ return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
73
+ }